diff options
author | Huacai Chen <chenhc@lemote.com> | 2014-11-04 01:13:26 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2014-11-24 01:45:01 -0500 |
commit | ec0f8d3fbb7ea12cfd10083e340381b96e7c34f8 (patch) | |
tree | 9550596fd52cccb8b7026c7135553255ddb0313d /arch/mips | |
parent | f490682a6b21ffed5acd7a0d49d8371e5e625d7a (diff) |
MIPS: Loongson: Allow booting from any core
By offering Logical->Physical core id mapping, so as to reserve some
physical cores via mask. This allow booting from any core when core-0
has problems. Since the maximun cores supported by Loongson-3 is 16,
32-bit cpu_startup_core_id can be split to 16-bit cpu_startup_core_id
and 16-bit reserved_cores_mask for compatibility.
Signed-off-by: Huacai Chen <chenhc@lemote.com>
Cc: John Crispin <john@phrozen.org>
Cc: Steven J. Hill <Steven.Hill@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: Fuxin Zhang <zhangfx@lemote.com>
Cc: Zhangjin Wu <wuzhangjin@gmail.com>
Patchwork: https://patchwork.linux-mips.org/patch/8323/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/include/asm/mach-loongson/boot_param.h | 5 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-loongson/irq.h | 3 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-loongson/topology.h | 2 | ||||
-rw-r--r-- | arch/mips/loongson/common/env.c | 2 | ||||
-rw-r--r-- | arch/mips/loongson/loongson-3/irq.c | 14 | ||||
-rw-r--r-- | arch/mips/loongson/loongson-3/numa.c | 12 | ||||
-rw-r--r-- | arch/mips/loongson/loongson-3/smp.c | 65 |
7 files changed, 67 insertions, 36 deletions
diff --git a/arch/mips/include/asm/mach-loongson/boot_param.h b/arch/mips/include/asm/mach-loongson/boot_param.h index 3388fc53599e..11ebf4ca2b41 100644 --- a/arch/mips/include/asm/mach-loongson/boot_param.h +++ b/arch/mips/include/asm/mach-loongson/boot_param.h | |||
@@ -42,7 +42,8 @@ struct efi_cpuinfo_loongson { | |||
42 | u32 processor_id; /* PRID, e.g. 6305, 6306 */ | 42 | u32 processor_id; /* PRID, e.g. 6305, 6306 */ |
43 | u32 cputype; /* Loongson_3A/3B, etc. */ | 43 | u32 cputype; /* Loongson_3A/3B, etc. */ |
44 | u32 total_node; /* num of total numa nodes */ | 44 | u32 total_node; /* num of total numa nodes */ |
45 | u32 cpu_startup_core_id; /* Core id */ | 45 | u16 cpu_startup_core_id; /* Boot core id */ |
46 | u16 reserved_cores_mask; | ||
46 | u32 cpu_clock_freq; /* cpu_clock */ | 47 | u32 cpu_clock_freq; /* cpu_clock */ |
47 | u32 nr_cpus; | 48 | u32 nr_cpus; |
48 | } __packed; | 49 | } __packed; |
@@ -149,6 +150,8 @@ struct loongson_system_configuration { | |||
149 | u32 nr_nodes; | 150 | u32 nr_nodes; |
150 | int cores_per_node; | 151 | int cores_per_node; |
151 | int cores_per_package; | 152 | int cores_per_package; |
153 | u16 boot_cpu_id; | ||
154 | u16 reserved_cpus_mask; | ||
152 | enum loongson_cpu_type cputype; | 155 | enum loongson_cpu_type cputype; |
153 | u64 ht_control_base; | 156 | u64 ht_control_base; |
154 | u64 pci_mem_start_addr; | 157 | u64 pci_mem_start_addr; |
diff --git a/arch/mips/include/asm/mach-loongson/irq.h b/arch/mips/include/asm/mach-loongson/irq.h index 34560bda6626..a281cca5f2fb 100644 --- a/arch/mips/include/asm/mach-loongson/irq.h +++ b/arch/mips/include/asm/mach-loongson/irq.h | |||
@@ -32,8 +32,7 @@ | |||
32 | #define LOONGSON_INT_ROUTER_LPC LOONGSON_INT_ROUTER_ENTRY(0x0a) | 32 | #define LOONGSON_INT_ROUTER_LPC LOONGSON_INT_ROUTER_ENTRY(0x0a) |
33 | #define LOONGSON_INT_ROUTER_HT1(n) LOONGSON_INT_ROUTER_ENTRY(n + 0x18) | 33 | #define LOONGSON_INT_ROUTER_HT1(n) LOONGSON_INT_ROUTER_ENTRY(n + 0x18) |
34 | 34 | ||
35 | #define LOONGSON_INT_CORE0_INT0 0x11 /* route to int 0 of core 0 */ | 35 | #define LOONGSON_INT_COREx_INTy(x, y) (1<<(x) | 1<<(y+4)) /* route to int y of core x */ |
36 | #define LOONGSON_INT_CORE0_INT1 0x21 /* route to int 1 of core 0 */ | ||
37 | 36 | ||
38 | #endif | 37 | #endif |
39 | 38 | ||
diff --git a/arch/mips/include/asm/mach-loongson/topology.h b/arch/mips/include/asm/mach-loongson/topology.h index 5598ba77d2ef..0d8f3b55bdbc 100644 --- a/arch/mips/include/asm/mach-loongson/topology.h +++ b/arch/mips/include/asm/mach-loongson/topology.h | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | #ifdef CONFIG_NUMA | 4 | #ifdef CONFIG_NUMA |
5 | 5 | ||
6 | #define cpu_to_node(cpu) ((cpu) >> 2) | 6 | #define cpu_to_node(cpu) (cpu_logical_map(cpu) >> 2) |
7 | #define parent_node(node) (node) | 7 | #define parent_node(node) (node) |
8 | #define cpumask_of_node(node) (&__node_data[(node)]->cpumask) | 8 | #define cpumask_of_node(node) (&__node_data[(node)]->cpumask) |
9 | 9 | ||
diff --git a/arch/mips/loongson/common/env.c b/arch/mips/loongson/common/env.c index f15228550a22..d8be5398105c 100644 --- a/arch/mips/loongson/common/env.c +++ b/arch/mips/loongson/common/env.c | |||
@@ -119,6 +119,8 @@ void __init prom_init_env(void) | |||
119 | } | 119 | } |
120 | 120 | ||
121 | loongson_sysconf.nr_cpus = ecpu->nr_cpus; | 121 | loongson_sysconf.nr_cpus = ecpu->nr_cpus; |
122 | loongson_sysconf.boot_cpu_id = ecpu->cpu_startup_core_id; | ||
123 | loongson_sysconf.reserved_cpus_mask = ecpu->reserved_cores_mask; | ||
122 | if (ecpu->nr_cpus > NR_CPUS || ecpu->nr_cpus == 0) | 124 | if (ecpu->nr_cpus > NR_CPUS || ecpu->nr_cpus == 0) |
123 | loongson_sysconf.nr_cpus = NR_CPUS; | 125 | loongson_sysconf.nr_cpus = NR_CPUS; |
124 | loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus + | 126 | loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus + |
diff --git a/arch/mips/loongson/loongson-3/irq.c b/arch/mips/loongson/loongson-3/irq.c index ca1c62af5188..5813d941f9fc 100644 --- a/arch/mips/loongson/loongson-3/irq.c +++ b/arch/mips/loongson/loongson-3/irq.c | |||
@@ -55,8 +55,8 @@ static inline void mask_loongson_irq(struct irq_data *d) | |||
55 | /* Workaround: UART IRQ may deliver to any core */ | 55 | /* Workaround: UART IRQ may deliver to any core */ |
56 | if (d->irq == LOONGSON_UART_IRQ) { | 56 | if (d->irq == LOONGSON_UART_IRQ) { |
57 | int cpu = smp_processor_id(); | 57 | int cpu = smp_processor_id(); |
58 | int node_id = cpu / loongson_sysconf.cores_per_node; | 58 | int node_id = cpu_logical_map(cpu) / loongson_sysconf.cores_per_node; |
59 | int core_id = cpu % loongson_sysconf.cores_per_node; | 59 | int core_id = cpu_logical_map(cpu) % loongson_sysconf.cores_per_node; |
60 | u64 intenclr_addr = smp_group[node_id] | | 60 | u64 intenclr_addr = smp_group[node_id] | |
61 | (u64)(&LOONGSON_INT_ROUTER_INTENCLR); | 61 | (u64)(&LOONGSON_INT_ROUTER_INTENCLR); |
62 | u64 introuter_lpc_addr = smp_group[node_id] | | 62 | u64 introuter_lpc_addr = smp_group[node_id] | |
@@ -72,8 +72,8 @@ static inline void unmask_loongson_irq(struct irq_data *d) | |||
72 | /* Workaround: UART IRQ may deliver to any core */ | 72 | /* Workaround: UART IRQ may deliver to any core */ |
73 | if (d->irq == LOONGSON_UART_IRQ) { | 73 | if (d->irq == LOONGSON_UART_IRQ) { |
74 | int cpu = smp_processor_id(); | 74 | int cpu = smp_processor_id(); |
75 | int node_id = cpu / loongson_sysconf.cores_per_node; | 75 | int node_id = cpu_logical_map(cpu) / loongson_sysconf.cores_per_node; |
76 | int core_id = cpu % loongson_sysconf.cores_per_node; | 76 | int core_id = cpu_logical_map(cpu) % loongson_sysconf.cores_per_node; |
77 | u64 intenset_addr = smp_group[node_id] | | 77 | u64 intenset_addr = smp_group[node_id] | |
78 | (u64)(&LOONGSON_INT_ROUTER_INTENSET); | 78 | (u64)(&LOONGSON_INT_ROUTER_INTENSET); |
79 | u64 introuter_lpc_addr = smp_group[node_id] | | 79 | u64 introuter_lpc_addr = smp_group[node_id] | |
@@ -102,10 +102,12 @@ void irq_router_init(void) | |||
102 | int i; | 102 | int i; |
103 | 103 | ||
104 | /* route LPC int to cpu core0 int 0 */ | 104 | /* route LPC int to cpu core0 int 0 */ |
105 | LOONGSON_INT_ROUTER_LPC = LOONGSON_INT_CORE0_INT0; | 105 | LOONGSON_INT_ROUTER_LPC = |
106 | LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 0); | ||
106 | /* route HT1 int0 ~ int7 to cpu core0 INT1*/ | 107 | /* route HT1 int0 ~ int7 to cpu core0 INT1*/ |
107 | for (i = 0; i < 8; i++) | 108 | for (i = 0; i < 8; i++) |
108 | LOONGSON_INT_ROUTER_HT1(i) = LOONGSON_INT_CORE0_INT1; | 109 | LOONGSON_INT_ROUTER_HT1(i) = |
110 | LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 1); | ||
109 | /* enable HT1 interrupt */ | 111 | /* enable HT1 interrupt */ |
110 | LOONGSON_HT1_INTN_EN(0) = 0xffffffff; | 112 | LOONGSON_HT1_INTN_EN(0) = 0xffffffff; |
111 | /* enable router interrupt intenset */ | 113 | /* enable router interrupt intenset */ |
diff --git a/arch/mips/loongson/loongson-3/numa.c b/arch/mips/loongson/loongson-3/numa.c index 42323bcc5d28..6cae0e75de27 100644 --- a/arch/mips/loongson/loongson-3/numa.c +++ b/arch/mips/loongson/loongson-3/numa.c | |||
@@ -224,7 +224,7 @@ static void __init node_mem_init(unsigned int node) | |||
224 | 224 | ||
225 | static __init void prom_meminit(void) | 225 | static __init void prom_meminit(void) |
226 | { | 226 | { |
227 | unsigned int node, cpu; | 227 | unsigned int node, cpu, active_cpu = 0; |
228 | 228 | ||
229 | cpu_node_probe(); | 229 | cpu_node_probe(); |
230 | init_topology_matrix(); | 230 | init_topology_matrix(); |
@@ -240,8 +240,14 @@ static __init void prom_meminit(void) | |||
240 | node = cpu / loongson_sysconf.cores_per_node; | 240 | node = cpu / loongson_sysconf.cores_per_node; |
241 | if (node >= num_online_nodes()) | 241 | if (node >= num_online_nodes()) |
242 | node = 0; | 242 | node = 0; |
243 | pr_info("NUMA: set cpumask cpu %d on node %d\n", cpu, node); | 243 | |
244 | cpu_set(cpu, __node_data[(node)]->cpumask); | 244 | if (loongson_sysconf.reserved_cpus_mask & (1<<cpu)) |
245 | continue; | ||
246 | |||
247 | cpu_set(active_cpu, __node_data[(node)]->cpumask); | ||
248 | pr_info("NUMA: set cpumask cpu %d on node %d\n", active_cpu, node); | ||
249 | |||
250 | active_cpu++; | ||
245 | } | 251 | } |
246 | } | 252 | } |
247 | 253 | ||
diff --git a/arch/mips/loongson/loongson-3/smp.c b/arch/mips/loongson/loongson-3/smp.c index d8c63af6c7cc..94ed8a57353c 100644 --- a/arch/mips/loongson/loongson-3/smp.c +++ b/arch/mips/loongson/loongson-3/smp.c | |||
@@ -239,7 +239,7 @@ static void ipi_mailbox_buf_init(void) | |||
239 | */ | 239 | */ |
240 | static void loongson3_send_ipi_single(int cpu, unsigned int action) | 240 | static void loongson3_send_ipi_single(int cpu, unsigned int action) |
241 | { | 241 | { |
242 | loongson3_ipi_write32((u32)action, ipi_set0_regs[cpu]); | 242 | loongson3_ipi_write32((u32)action, ipi_set0_regs[cpu_logical_map(cpu)]); |
243 | } | 243 | } |
244 | 244 | ||
245 | static void | 245 | static void |
@@ -248,7 +248,7 @@ loongson3_send_ipi_mask(const struct cpumask *mask, unsigned int action) | |||
248 | unsigned int i; | 248 | unsigned int i; |
249 | 249 | ||
250 | for_each_cpu(i, mask) | 250 | for_each_cpu(i, mask) |
251 | loongson3_ipi_write32((u32)action, ipi_set0_regs[i]); | 251 | loongson3_ipi_write32((u32)action, ipi_set0_regs[cpu_logical_map(i)]); |
252 | } | 252 | } |
253 | 253 | ||
254 | void loongson3_ipi_interrupt(struct pt_regs *regs) | 254 | void loongson3_ipi_interrupt(struct pt_regs *regs) |
@@ -257,10 +257,10 @@ void loongson3_ipi_interrupt(struct pt_regs *regs) | |||
257 | unsigned int action, c0count; | 257 | unsigned int action, c0count; |
258 | 258 | ||
259 | /* Load the ipi register to figure out what we're supposed to do */ | 259 | /* Load the ipi register to figure out what we're supposed to do */ |
260 | action = loongson3_ipi_read32(ipi_status0_regs[cpu]); | 260 | action = loongson3_ipi_read32(ipi_status0_regs[cpu_logical_map(cpu)]); |
261 | 261 | ||
262 | /* Clear the ipi register to clear the interrupt */ | 262 | /* Clear the ipi register to clear the interrupt */ |
263 | loongson3_ipi_write32((u32)action, ipi_clear0_regs[cpu]); | 263 | loongson3_ipi_write32((u32)action, ipi_clear0_regs[cpu_logical_map(cpu)]); |
264 | 264 | ||
265 | if (action & SMP_RESCHEDULE_YOURSELF) | 265 | if (action & SMP_RESCHEDULE_YOURSELF) |
266 | scheduler_ipi(); | 266 | scheduler_ipi(); |
@@ -291,12 +291,14 @@ static void loongson3_init_secondary(void) | |||
291 | /* Set interrupt mask, but don't enable */ | 291 | /* Set interrupt mask, but don't enable */ |
292 | change_c0_status(ST0_IM, imask); | 292 | change_c0_status(ST0_IM, imask); |
293 | 293 | ||
294 | for (i = 0; i < loongson_sysconf.nr_cpus; i++) | 294 | for (i = 0; i < num_possible_cpus(); i++) |
295 | loongson3_ipi_write32(0xffffffff, ipi_en0_regs[i]); | 295 | loongson3_ipi_write32(0xffffffff, ipi_en0_regs[cpu_logical_map(i)]); |
296 | 296 | ||
297 | cpu_data[cpu].package = cpu / loongson_sysconf.cores_per_package; | ||
298 | cpu_data[cpu].core = cpu % loongson_sysconf.cores_per_package; | ||
299 | per_cpu(cpu_state, cpu) = CPU_ONLINE; | 297 | per_cpu(cpu_state, cpu) = CPU_ONLINE; |
298 | cpu_data[cpu].core = | ||
299 | cpu_logical_map(cpu) % loongson_sysconf.cores_per_package; | ||
300 | cpu_data[cpu].package = | ||
301 | cpu_logical_map(cpu) / loongson_sysconf.cores_per_package; | ||
300 | 302 | ||
301 | i = 0; | 303 | i = 0; |
302 | __this_cpu_write(core0_c0count, 0); | 304 | __this_cpu_write(core0_c0count, 0); |
@@ -314,37 +316,50 @@ static void loongson3_init_secondary(void) | |||
314 | 316 | ||
315 | static void loongson3_smp_finish(void) | 317 | static void loongson3_smp_finish(void) |
316 | { | 318 | { |
319 | int cpu = smp_processor_id(); | ||
320 | |||
317 | write_c0_compare(read_c0_count() + mips_hpt_frequency/HZ); | 321 | write_c0_compare(read_c0_count() + mips_hpt_frequency/HZ); |
318 | local_irq_enable(); | 322 | local_irq_enable(); |
319 | loongson3_ipi_write64(0, | 323 | loongson3_ipi_write64(0, |
320 | (void *)(ipi_mailbox_buf[smp_processor_id()]+0x0)); | 324 | (void *)(ipi_mailbox_buf[cpu_logical_map(cpu)]+0x0)); |
321 | pr_info("CPU#%d finished, CP0_ST=%x\n", | 325 | pr_info("CPU#%d finished, CP0_ST=%x\n", |
322 | smp_processor_id(), read_c0_status()); | 326 | smp_processor_id(), read_c0_status()); |
323 | } | 327 | } |
324 | 328 | ||
325 | static void __init loongson3_smp_setup(void) | 329 | static void __init loongson3_smp_setup(void) |
326 | { | 330 | { |
327 | int i, num; | 331 | int i = 0, num = 0; /* i: physical id, num: logical id */ |
328 | 332 | ||
329 | init_cpu_possible(cpu_none_mask); | 333 | init_cpu_possible(cpu_none_mask); |
330 | set_cpu_possible(0, true); | ||
331 | |||
332 | __cpu_number_map[0] = 0; | ||
333 | __cpu_logical_map[0] = 0; | ||
334 | 334 | ||
335 | /* For unified kernel, NR_CPUS is the maximum possible value, | 335 | /* For unified kernel, NR_CPUS is the maximum possible value, |
336 | * loongson_sysconf.nr_cpus is the really present value */ | 336 | * loongson_sysconf.nr_cpus is the really present value */ |
337 | for (i = 1, num = 0; i < loongson_sysconf.nr_cpus; i++) { | 337 | while (i < loongson_sysconf.nr_cpus) { |
338 | set_cpu_possible(i, true); | 338 | if (loongson_sysconf.reserved_cpus_mask & (1<<i)) { |
339 | __cpu_number_map[i] = ++num; | 339 | /* Reserved physical CPU cores */ |
340 | __cpu_logical_map[num] = i; | 340 | __cpu_number_map[i] = -1; |
341 | } else { | ||
342 | __cpu_number_map[i] = num; | ||
343 | __cpu_logical_map[num] = i; | ||
344 | set_cpu_possible(num, true); | ||
345 | num++; | ||
346 | } | ||
347 | i++; | ||
341 | } | 348 | } |
349 | pr_info("Detected %i available CPU(s)\n", num); | ||
350 | |||
351 | while (num < loongson_sysconf.nr_cpus) { | ||
352 | __cpu_logical_map[num] = -1; | ||
353 | num++; | ||
354 | } | ||
355 | |||
342 | ipi_set0_regs_init(); | 356 | ipi_set0_regs_init(); |
343 | ipi_clear0_regs_init(); | 357 | ipi_clear0_regs_init(); |
344 | ipi_status0_regs_init(); | 358 | ipi_status0_regs_init(); |
345 | ipi_en0_regs_init(); | 359 | ipi_en0_regs_init(); |
346 | ipi_mailbox_buf_init(); | 360 | ipi_mailbox_buf_init(); |
347 | pr_info("Detected %i available secondary CPU(s)\n", num); | 361 | cpu_data[0].core = cpu_logical_map(0) % loongson_sysconf.cores_per_package; |
362 | cpu_data[0].package = cpu_logical_map(0) / loongson_sysconf.cores_per_package; | ||
348 | } | 363 | } |
349 | 364 | ||
350 | static void __init loongson3_prepare_cpus(unsigned int max_cpus) | 365 | static void __init loongson3_prepare_cpus(unsigned int max_cpus) |
@@ -371,10 +386,14 @@ static void loongson3_boot_secondary(int cpu, struct task_struct *idle) | |||
371 | pr_debug("CPU#%d, func_pc=%lx, sp=%lx, gp=%lx\n", | 386 | pr_debug("CPU#%d, func_pc=%lx, sp=%lx, gp=%lx\n", |
372 | cpu, startargs[0], startargs[1], startargs[2]); | 387 | cpu, startargs[0], startargs[1], startargs[2]); |
373 | 388 | ||
374 | loongson3_ipi_write64(startargs[3], (void *)(ipi_mailbox_buf[cpu]+0x18)); | 389 | loongson3_ipi_write64(startargs[3], |
375 | loongson3_ipi_write64(startargs[2], (void *)(ipi_mailbox_buf[cpu]+0x10)); | 390 | (void *)(ipi_mailbox_buf[cpu_logical_map(cpu)]+0x18)); |
376 | loongson3_ipi_write64(startargs[1], (void *)(ipi_mailbox_buf[cpu]+0x8)); | 391 | loongson3_ipi_write64(startargs[2], |
377 | loongson3_ipi_write64(startargs[0], (void *)(ipi_mailbox_buf[cpu]+0x0)); | 392 | (void *)(ipi_mailbox_buf[cpu_logical_map(cpu)]+0x10)); |
393 | loongson3_ipi_write64(startargs[1], | ||
394 | (void *)(ipi_mailbox_buf[cpu_logical_map(cpu)]+0x8)); | ||
395 | loongson3_ipi_write64(startargs[0], | ||
396 | (void *)(ipi_mailbox_buf[cpu_logical_map(cpu)]+0x0)); | ||
378 | } | 397 | } |
379 | 398 | ||
380 | #ifdef CONFIG_HOTPLUG_CPU | 399 | #ifdef CONFIG_HOTPLUG_CPU |