kernel: update 3.14 to 3.14.18
[openwrt/openwrt.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 --- a/arch/arm/include/asm/smp.h
36 +++ b/arch/arm/include/asm/smp.h
37 @@ -114,6 +114,15 @@ struct smp_operations {
38 #endif
39 };
40
41 +struct of_cpu_method {
42 + const char *method;
43 + struct smp_operations *ops;
44 +};
45 +
46 +#define CPU_METHOD_OF_DECLARE(name, _method, _ops) \
47 + static const struct of_cpu_method __cpu_method_of_table_##name \
48 + __used __section(__cpu_method_of_table) \
49 + = { .method = _method, .ops = _ops }
50 /*
51 * set platform specific SMP operations
52 */
53 --- a/arch/arm/kernel/devtree.c
54 +++ b/arch/arm/kernel/devtree.c
55 @@ -18,6 +18,7 @@
56 #include <linux/of_fdt.h>
57 #include <linux/of_irq.h>
58 #include <linux/of_platform.h>
59 +#include <linux/smp.h>
60
61 #include <asm/cputype.h>
62 #include <asm/setup.h>
63 @@ -63,6 +64,34 @@ void __init arm_dt_memblock_reserve(void
64 }
65 }
66
67 +#ifdef CONFIG_SMP
68 +extern struct of_cpu_method __cpu_method_of_table_begin[];
69 +extern struct of_cpu_method __cpu_method_of_table_end[];
70 +
71 +static int __init set_smp_ops_by_method(struct device_node *node)
72 +{
73 + const char *method;
74 + struct of_cpu_method *m = __cpu_method_of_table_begin;
75 +
76 + if (of_property_read_string(node, "enable-method", &method))
77 + return 0;
78 +
79 + for (; m < __cpu_method_of_table_end; m++)
80 + if (!strcmp(m->method, method)) {
81 + smp_set_ops(m->ops);
82 + return 1;
83 + }
84 +
85 + return 0;
86 +}
87 +#else
88 +static inline int set_smp_ops_by_method(struct device_node *node)
89 +{
90 + return 1;
91 +}
92 +#endif
93 +
94 +
95 /*
96 * arm_dt_init_cpu_maps - Function retrieves cpu nodes from the device tree
97 * and builds the cpu logical map array containing MPIDR values related to
98 @@ -79,6 +108,7 @@ void __init arm_dt_init_cpu_maps(void)
99 * read as 0.
100 */
101 struct device_node *cpu, *cpus;
102 + int found_method = 0;
103 u32 i, j, cpuidx = 1;
104 u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
105
106 @@ -150,8 +180,18 @@ void __init arm_dt_init_cpu_maps(void)
107 }
108
109 tmp_map[i] = hwid;
110 +
111 + if (!found_method)
112 + found_method = set_smp_ops_by_method(cpu);
113 }
114
115 + /*
116 + * Fallback to an enable-method in the cpus node if nothing found in
117 + * a cpu node.
118 + */
119 + if (!found_method)
120 + set_smp_ops_by_method(cpus);
121 +
122 if (!bootcpu_valid) {
123 pr_warn("DT missing boot CPU MPIDR[23:0], fall back to default cpu_logical_map\n");
124 return;
125 --- a/include/asm-generic/vmlinux.lds.h
126 +++ b/include/asm-generic/vmlinux.lds.h
127 @@ -177,6 +177,15 @@
128 #define CLK_OF_TABLES()
129 #endif
130
131 +#ifdef CONFIG_SMP
132 +#define CPU_METHOD_OF_TABLES() . = ALIGN(8); \
133 + VMLINUX_SYMBOL(__cpu_method_of_table_begin) = .; \
134 + *(__cpu_method_of_table) \
135 + VMLINUX_SYMBOL(__cpu_method_of_table_end) = .;
136 +#else
137 +#define CPU_METHOD_OF_TABLES()
138 +#endif
139 +
140 #define KERNEL_DTB() \
141 STRUCT_ALIGN(); \
142 VMLINUX_SYMBOL(__dtb_start) = .; \
143 @@ -502,6 +511,7 @@
144 MEM_DISCARD(init.rodata) \
145 CLK_OF_TABLES() \
146 CLKSRC_OF_TABLES() \
147 + CPU_METHOD_OF_TABLES() \
148 KERNEL_DTB() \
149 IRQCHIP_OF_MATCH_TABLE()
150