ipq806x: Add support for IPQ806x chip family
[openwrt/svn-archive/archive.git] / target / linux / ipq806x / patches / 0008-ARM-Introduce-CPU_METHOD_OF_DECLARE-for-cpu-hotplug-.patch
1 From 48f17325fef9cbebc5cb39aa78f4c1caff5d7b16 Mon Sep 17 00:00:00 2001
2 From: Stephen Boyd <sboyd@codeaurora.org>
3 Date: Wed, 30 Oct 2013 18:21:09 -0700
4 Subject: [PATCH 008/182] ARM: Introduce CPU_METHOD_OF_DECLARE() for cpu
5 hotplug/smp
6
7 The goal of multi-platform kernels is to remove the need for mach
8 directories and machine descriptors. To further that goal,
9 introduce CPU_METHOD_OF_DECLARE() to allow cpu hotplug/smp
10 support to be separated from the machine descriptors.
11 Implementers should specify an enable-method property in their
12 cpus node and then implement a matching set of smp_ops in their
13 hotplug/smp code, wiring it up with the CPU_METHOD_OF_DECLARE()
14 macro. When the kernel is compiled we'll collect all the
15 enable-method smp_ops into one section for use at boot.
16
17 At boot time we'll look for an enable-method in each cpu node and
18 try to match that against all known CPU enable methods in the
19 kernel. If there are no enable-methods in the cpu nodes we
20 fallback to the cpus node and try to use any enable-method found
21 there. If that doesn't work we fall back to the old way of using
22 the machine descriptor.
23
24 Acked-by: Mark Rutland <mark.rutland@arm.com>
25 Cc: Russell King <linux@arm.linux.org.uk>
26 Cc: <devicetree@vger.kernel.org>
27 Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
28 Signed-off-by: Kumar Gala <galak@codeaurora.org>
29 ---
30 arch/arm/include/asm/smp.h | 9 +++++++++
31 arch/arm/kernel/devtree.c | 40 +++++++++++++++++++++++++++++++++++++
32 include/asm-generic/vmlinux.lds.h | 10 ++++++++++
33 3 files changed, 59 insertions(+)
34
35 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
36 index 22a3b9b..772435b 100644
37 --- a/arch/arm/include/asm/smp.h
38 +++ b/arch/arm/include/asm/smp.h
39 @@ -114,6 +114,15 @@ struct smp_operations {
40 #endif
41 };
42
43 +struct of_cpu_method {
44 + const char *method;
45 + struct smp_operations *ops;
46 +};
47 +
48 +#define CPU_METHOD_OF_DECLARE(name, _method, _ops) \
49 + static const struct of_cpu_method __cpu_method_of_table_##name \
50 + __used __section(__cpu_method_of_table) \
51 + = { .method = _method, .ops = _ops }
52 /*
53 * set platform specific SMP operations
54 */
55 diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
56 index f751714..c7419a5 100644
57 --- a/arch/arm/kernel/devtree.c
58 +++ b/arch/arm/kernel/devtree.c
59 @@ -18,6 +18,7 @@
60 #include <linux/of_fdt.h>
61 #include <linux/of_irq.h>
62 #include <linux/of_platform.h>
63 +#include <linux/smp.h>
64
65 #include <asm/cputype.h>
66 #include <asm/setup.h>
67 @@ -63,6 +64,34 @@ void __init arm_dt_memblock_reserve(void)
68 }
69 }
70
71 +#ifdef CONFIG_SMP
72 +extern struct of_cpu_method __cpu_method_of_table_begin[];
73 +extern struct of_cpu_method __cpu_method_of_table_end[];
74 +
75 +static int __init set_smp_ops_by_method(struct device_node *node)
76 +{
77 + const char *method;
78 + struct of_cpu_method *m = __cpu_method_of_table_begin;
79 +
80 + if (of_property_read_string(node, "enable-method", &method))
81 + return 0;
82 +
83 + for (; m < __cpu_method_of_table_end; m++)
84 + if (!strcmp(m->method, method)) {
85 + smp_set_ops(m->ops);
86 + return 1;
87 + }
88 +
89 + return 0;
90 +}
91 +#else
92 +static inline int set_smp_ops_by_method(struct device_node *node)
93 +{
94 + return 1;
95 +}
96 +#endif
97 +
98 +
99 /*
100 * arm_dt_init_cpu_maps - Function retrieves cpu nodes from the device tree
101 * and builds the cpu logical map array containing MPIDR values related to
102 @@ -79,6 +108,7 @@ void __init arm_dt_init_cpu_maps(void)
103 * read as 0.
104 */
105 struct device_node *cpu, *cpus;
106 + int found_method = 0;
107 u32 i, j, cpuidx = 1;
108 u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
109
110 @@ -150,8 +180,18 @@ void __init arm_dt_init_cpu_maps(void)
111 }
112
113 tmp_map[i] = hwid;
114 +
115 + if (!found_method)
116 + found_method = set_smp_ops_by_method(cpu);
117 }
118
119 + /*
120 + * Fallback to an enable-method in the cpus node if nothing found in
121 + * a cpu node.
122 + */
123 + if (!found_method)
124 + set_smp_ops_by_method(cpus);
125 +
126 if (!bootcpu_valid) {
127 pr_warn("DT missing boot CPU MPIDR[23:0], fall back to default cpu_logical_map\n");
128 return;
129 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
130 index bc2121f..bd02ca7 100644
131 --- a/include/asm-generic/vmlinux.lds.h
132 +++ b/include/asm-generic/vmlinux.lds.h
133 @@ -167,6 +167,15 @@
134 #define CLK_OF_TABLES()
135 #endif
136
137 +#ifdef CONFIG_SMP
138 +#define CPU_METHOD_OF_TABLES() . = ALIGN(8); \
139 + VMLINUX_SYMBOL(__cpu_method_of_table_begin) = .; \
140 + *(__cpu_method_of_table) \
141 + VMLINUX_SYMBOL(__cpu_method_of_table_end) = .;
142 +#else
143 +#define CPU_METHOD_OF_TABLES()
144 +#endif
145 +
146 #define KERNEL_DTB() \
147 STRUCT_ALIGN(); \
148 VMLINUX_SYMBOL(__dtb_start) = .; \
149 @@ -491,6 +500,7 @@
150 MEM_DISCARD(init.rodata) \
151 CLK_OF_TABLES() \
152 CLKSRC_OF_TABLES() \
153 + CPU_METHOD_OF_TABLES() \
154 KERNEL_DTB() \
155 IRQCHIP_OF_MATCH_TABLE()
156
157 --
158 1.7.10.4
159