aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2009-06-23 05:36:38 -0400
committerRalf Baechle <ralf@linux-mips.org>2009-06-24 13:34:40 -0400
commit773cb77d0e32f0a3c36edf5aaeb9642c18038cd2 (patch)
treef604b52d75aaeffe4c432437f339f13c9e099265 /arch
parent9801b321ecdb6708365b6825bf728c8e433fca00 (diff)
MIPS: Cavium: Add CPU hotplugging code.
Thanks to Cavium Inc. for the code contribution and help. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/Kconfig2
-rw-r--r--arch/mips/cavium-octeon/octeon-irq.c59
-rw-r--r--arch/mips/cavium-octeon/octeon_boot.h70
-rw-r--r--arch/mips/cavium-octeon/smp.c234
-rw-r--r--arch/mips/include/asm/smp.h2
5 files changed, 365 insertions, 2 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 3cce4ed5473d..8c4be1f301cf 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -601,6 +601,7 @@ config CAVIUM_OCTEON_SIMULATOR
601 select SYS_SUPPORTS_64BIT_KERNEL 601 select SYS_SUPPORTS_64BIT_KERNEL
602 select SYS_SUPPORTS_BIG_ENDIAN 602 select SYS_SUPPORTS_BIG_ENDIAN
603 select SYS_SUPPORTS_HIGHMEM 603 select SYS_SUPPORTS_HIGHMEM
604 select SYS_SUPPORTS_HOTPLUG_CPU
604 select SYS_HAS_CPU_CAVIUM_OCTEON 605 select SYS_HAS_CPU_CAVIUM_OCTEON
605 help 606 help
606 The Octeon simulator is software performance model of the Cavium 607 The Octeon simulator is software performance model of the Cavium
@@ -615,6 +616,7 @@ config CAVIUM_OCTEON_REFERENCE_BOARD
615 select SYS_SUPPORTS_64BIT_KERNEL 616 select SYS_SUPPORTS_64BIT_KERNEL
616 select SYS_SUPPORTS_BIG_ENDIAN 617 select SYS_SUPPORTS_BIG_ENDIAN
617 select SYS_SUPPORTS_HIGHMEM 618 select SYS_SUPPORTS_HIGHMEM
619 select SYS_SUPPORTS_HOTPLUG_CPU
618 select SYS_HAS_EARLY_PRINTK 620 select SYS_HAS_EARLY_PRINTK
619 select SYS_HAS_CPU_CAVIUM_OCTEON 621 select SYS_HAS_CPU_CAVIUM_OCTEON
620 select SWAP_IO_SPACE 622 select SWAP_IO_SPACE
diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
index 3090ee37e109..384f1842bfb1 100644
--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -501,3 +501,62 @@ asmlinkage void plat_irq_dispatch(void)
501 } 501 }
502 } 502 }
503} 503}
504
505#ifdef CONFIG_HOTPLUG_CPU
506static int is_irq_enabled_on_cpu(unsigned int irq, unsigned int cpu)
507{
508 unsigned int isset;
509#ifdef CONFIG_SMP
510 int coreid = cpu_logical_map(cpu);
511#else
512 int coreid = cvmx_get_core_num();
513#endif
514 int bit = (irq < OCTEON_IRQ_WDOG0) ?
515 irq - OCTEON_IRQ_WORKQ0 : irq - OCTEON_IRQ_WDOG0;
516 if (irq < 64) {
517 isset = (cvmx_read_csr(CVMX_CIU_INTX_EN0(coreid * 2)) &
518 (1ull << bit)) >> bit;
519 } else {
520 isset = (cvmx_read_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1)) &
521 (1ull << bit)) >> bit;
522 }
523 return isset;
524}
525
526void fixup_irqs(void)
527{
528 int irq;
529
530 for (irq = OCTEON_IRQ_SW0; irq <= OCTEON_IRQ_TIMER; irq++)
531 octeon_irq_core_disable_local(irq);
532
533 for (irq = OCTEON_IRQ_WORKQ0; irq <= OCTEON_IRQ_GPIO15; irq++) {
534 if (is_irq_enabled_on_cpu(irq, smp_processor_id())) {
535 /* ciu irq migrates to next cpu */
536 octeon_irq_chip_ciu0.disable(irq);
537 octeon_irq_ciu0_set_affinity(irq, &cpu_online_map);
538 }
539 }
540
541#if 0
542 for (irq = OCTEON_IRQ_MBOX0; irq <= OCTEON_IRQ_MBOX1; irq++)
543 octeon_irq_mailbox_mask(irq);
544#endif
545 for (irq = OCTEON_IRQ_UART0; irq <= OCTEON_IRQ_BOOTDMA; irq++) {
546 if (is_irq_enabled_on_cpu(irq, smp_processor_id())) {
547 /* ciu irq migrates to next cpu */
548 octeon_irq_chip_ciu0.disable(irq);
549 octeon_irq_ciu0_set_affinity(irq, &cpu_online_map);
550 }
551 }
552
553 for (irq = OCTEON_IRQ_UART2; irq <= OCTEON_IRQ_RESERVED135; irq++) {
554 if (is_irq_enabled_on_cpu(irq, smp_processor_id())) {
555 /* ciu irq migrates to next cpu */
556 octeon_irq_chip_ciu1.disable(irq);
557 octeon_irq_ciu1_set_affinity(irq, &cpu_online_map);
558 }
559 }
560}
561
562#endif /* CONFIG_HOTPLUG_CPU */
diff --git a/arch/mips/cavium-octeon/octeon_boot.h b/arch/mips/cavium-octeon/octeon_boot.h
new file mode 100644
index 000000000000..0f7f84accf9a
--- /dev/null
+++ b/arch/mips/cavium-octeon/octeon_boot.h
@@ -0,0 +1,70 @@
1/*
2 * (C) Copyright 2004, 2005 Cavium Networks
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17 * MA 02111-1307 USA
18 */
19
20#ifndef __OCTEON_BOOT_H__
21#define __OCTEON_BOOT_H__
22
23#include <linux/types.h>
24
25struct boot_init_vector {
26 uint32_t stack_addr;
27 uint32_t code_addr;
28 uint32_t app_start_func_addr;
29 uint32_t k0_val;
30 uint32_t flags;
31 uint32_t boot_info_addr;
32 uint32_t pad;
33 uint32_t pad2;
34};
35
36/* similar to bootloader's linux_app_boot_info but without global data */
37struct linux_app_boot_info {
38 uint32_t labi_signature;
39 uint32_t start_core0_addr;
40 uint32_t avail_coremask;
41 uint32_t pci_console_active;
42 uint32_t icache_prefetch_disable;
43 uint32_t InitTLBStart_addr;
44 uint32_t start_app_addr;
45 uint32_t cur_exception_base;
46 uint32_t no_mark_private_data;
47 uint32_t compact_flash_common_base_addr;
48 uint32_t compact_flash_attribute_base_addr;
49 uint32_t led_display_base_addr;
50};
51
52/* If not to copy a lot of bootloader's structures
53 here is only offset of requested member */
54#define AVAIL_COREMASK_OFFSET_IN_LINUX_APP_BOOT_BLOCK 0x765c
55
56/* hardcoded in bootloader */
57#define LABI_ADDR_IN_BOOTLOADER 0x700
58
59#define LINUX_APP_BOOT_BLOCK_NAME "linux-app-boot"
60
61#define LABI_SIGNATURE 0xAABBCCDD
62
63/* from uboot-headers/octeon_mem_map.h */
64#define EXCEPTION_BASE_INCR (4 * 1024)
65 /* Increment size for exception base addresses (4k minimum) */
66#define EXCEPTION_BASE_BASE 0
67#define BOOTLOADER_PRIV_DATA_BASE (EXCEPTION_BASE_BASE + 0x800)
68#define BOOTLOADER_BOOT_VECTOR (BOOTLOADER_PRIV_DATA_BASE)
69
70#endif /* __OCTEON_BOOT_H__ */
diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
index 24e0ad63980a..0b891a9c6253 100644
--- a/arch/mips/cavium-octeon/smp.c
+++ b/arch/mips/cavium-octeon/smp.c
@@ -5,6 +5,7 @@
5 * 5 *
6 * Copyright (C) 2004-2008 Cavium Networks 6 * Copyright (C) 2004-2008 Cavium Networks
7 */ 7 */
8#include <linux/cpu.h>
8#include <linux/init.h> 9#include <linux/init.h>
9#include <linux/delay.h> 10#include <linux/delay.h>
10#include <linux/smp.h> 11#include <linux/smp.h>
@@ -19,10 +20,16 @@
19 20
20#include <asm/octeon/octeon.h> 21#include <asm/octeon/octeon.h>
21 22
23#include "octeon_boot.h"
24
22volatile unsigned long octeon_processor_boot = 0xff; 25volatile unsigned long octeon_processor_boot = 0xff;
23volatile unsigned long octeon_processor_sp; 26volatile unsigned long octeon_processor_sp;
24volatile unsigned long octeon_processor_gp; 27volatile unsigned long octeon_processor_gp;
25 28
29#ifdef CONFIG_HOTPLUG_CPU
30static unsigned int InitTLBStart_addr;
31#endif
32
26static irqreturn_t mailbox_interrupt(int irq, void *dev_id) 33static irqreturn_t mailbox_interrupt(int irq, void *dev_id)
27{ 34{
28 const int coreid = cvmx_get_core_num(); 35 const int coreid = cvmx_get_core_num();
@@ -67,8 +74,28 @@ static inline void octeon_send_ipi_mask(cpumask_t mask, unsigned int action)
67} 74}
68 75
69/** 76/**
70 * Detect available CPUs, populate phys_cpu_present_map 77 * Detect available CPUs, populate cpu_possible_map
71 */ 78 */
79static void octeon_smp_hotplug_setup(void)
80{
81#ifdef CONFIG_HOTPLUG_CPU
82 uint32_t labi_signature;
83
84 labi_signature =
85 cvmx_read64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
86 LABI_ADDR_IN_BOOTLOADER +
87 offsetof(struct linux_app_boot_info,
88 labi_signature)));
89 if (labi_signature != LABI_SIGNATURE)
90 pr_err("The bootloader version on this board is incorrect\n");
91 InitTLBStart_addr =
92 cvmx_read64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
93 LABI_ADDR_IN_BOOTLOADER +
94 offsetof(struct linux_app_boot_info,
95 InitTLBStart_addr)));
96#endif
97}
98
72static void octeon_smp_setup(void) 99static void octeon_smp_setup(void)
73{ 100{
74 const int coreid = cvmx_get_core_num(); 101 const int coreid = cvmx_get_core_num();
@@ -91,6 +118,9 @@ static void octeon_smp_setup(void)
91 cpus++; 118 cpus++;
92 } 119 }
93 } 120 }
121 cpu_present_map = cpu_possible_map;
122
123 octeon_smp_hotplug_setup();
94} 124}
95 125
96/** 126/**
@@ -128,6 +158,17 @@ static void octeon_init_secondary(void)
128 const int coreid = cvmx_get_core_num(); 158 const int coreid = cvmx_get_core_num();
129 union cvmx_ciu_intx_sum0 interrupt_enable; 159 union cvmx_ciu_intx_sum0 interrupt_enable;
130 160
161#ifdef CONFIG_HOTPLUG_CPU
162 unsigned int cur_exception_base;
163
164 cur_exception_base = cvmx_read64_uint32(
165 CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
166 LABI_ADDR_IN_BOOTLOADER +
167 offsetof(struct linux_app_boot_info,
168 cur_exception_base)));
169 /* cur_exception_base is incremented in bootloader after setting */
170 write_c0_ebase((unsigned int)(cur_exception_base - EXCEPTION_BASE_INCR));
171#endif
131 octeon_check_cpu_bist(); 172 octeon_check_cpu_bist();
132 octeon_init_cvmcount(); 173 octeon_init_cvmcount();
133 /* 174 /*
@@ -199,6 +240,193 @@ static void octeon_cpus_done(void)
199#endif 240#endif
200} 241}
201 242
243#ifdef CONFIG_HOTPLUG_CPU
244
245/* State of each CPU. */
246DEFINE_PER_CPU(int, cpu_state);
247
248extern void fixup_irqs(void);
249
250static DEFINE_SPINLOCK(smp_reserve_lock);
251
252static int octeon_cpu_disable(void)
253{
254 unsigned int cpu = smp_processor_id();
255
256 if (cpu == 0)
257 return -EBUSY;
258
259 spin_lock(&smp_reserve_lock);
260
261 cpu_clear(cpu, cpu_online_map);
262 cpu_clear(cpu, cpu_callin_map);
263 local_irq_disable();
264 fixup_irqs();
265 local_irq_enable();
266
267 flush_cache_all();
268 local_flush_tlb_all();
269
270 spin_unlock(&smp_reserve_lock);
271
272 return 0;
273}
274
275static void octeon_cpu_die(unsigned int cpu)
276{
277 int coreid = cpu_logical_map(cpu);
278 uint32_t avail_coremask;
279 struct cvmx_bootmem_named_block_desc *block_desc;
280
281#ifdef CONFIG_CAVIUM_OCTEON_WATCHDOG
282 /* Disable the watchdog */
283 cvmx_ciu_wdogx_t ciu_wdog;
284 ciu_wdog.u64 = cvmx_read_csr(CVMX_CIU_WDOGX(cpu));
285 ciu_wdog.s.mode = 0;
286 cvmx_write_csr(CVMX_CIU_WDOGX(cpu), ciu_wdog.u64);
287#endif
288
289 while (per_cpu(cpu_state, cpu) != CPU_DEAD)
290 cpu_relax();
291
292 /*
293 * This is a bit complicated strategics of getting/settig available
294 * cores mask, copied from bootloader
295 */
296 /* LINUX_APP_BOOT_BLOCK is initialized in bootoct binary */
297 block_desc = cvmx_bootmem_find_named_block(LINUX_APP_BOOT_BLOCK_NAME);
298
299 if (!block_desc) {
300 avail_coremask =
301 cvmx_read64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
302 LABI_ADDR_IN_BOOTLOADER +
303 offsetof
304 (struct linux_app_boot_info,
305 avail_coremask)));
306 } else { /* alternative, already initialized */
307 avail_coremask =
308 cvmx_read64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
309 block_desc->base_addr +
310 AVAIL_COREMASK_OFFSET_IN_LINUX_APP_BOOT_BLOCK));
311 }
312
313 avail_coremask |= 1 << coreid;
314
315 /* Setting avail_coremask for bootoct binary */
316 if (!block_desc) {
317 cvmx_write64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
318 LABI_ADDR_IN_BOOTLOADER +
319 offsetof(struct linux_app_boot_info,
320 avail_coremask)),
321 avail_coremask);
322 } else {
323 cvmx_write64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
324 block_desc->base_addr +
325 AVAIL_COREMASK_OFFSET_IN_LINUX_APP_BOOT_BLOCK),
326 avail_coremask);
327 }
328
329 pr_info("Reset core %d. Available Coremask = %x \n", coreid,
330 avail_coremask);
331 cvmx_write_csr(CVMX_CIU_PP_RST, 1 << coreid);
332 cvmx_write_csr(CVMX_CIU_PP_RST, 0);
333}
334
335void play_dead(void)
336{
337 int coreid = cvmx_get_core_num();
338
339 idle_task_exit();
340 octeon_processor_boot = 0xff;
341 per_cpu(cpu_state, coreid) = CPU_DEAD;
342
343 while (1) /* core will be reset here */
344 ;
345}
346
347extern void kernel_entry(unsigned long arg1, ...);
348
349static void start_after_reset(void)
350{
351 kernel_entry(0, 0, 0); /* set a2 = 0 for secondary core */
352}
353
354int octeon_update_boot_vector(unsigned int cpu)
355{
356
357 int coreid = cpu_logical_map(cpu);
358 unsigned int avail_coremask;
359 struct cvmx_bootmem_named_block_desc *block_desc;
360 struct boot_init_vector *boot_vect =
361 (struct boot_init_vector *) cvmx_phys_to_ptr(0x0 +
362 BOOTLOADER_BOOT_VECTOR);
363
364 block_desc = cvmx_bootmem_find_named_block(LINUX_APP_BOOT_BLOCK_NAME);
365
366 if (!block_desc) {
367 avail_coremask =
368 cvmx_read64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
369 LABI_ADDR_IN_BOOTLOADER +
370 offsetof(struct linux_app_boot_info,
371 avail_coremask)));
372 } else { /* alternative, already initialized */
373 avail_coremask =
374 cvmx_read64_uint32(CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS,
375 block_desc->base_addr +
376 AVAIL_COREMASK_OFFSET_IN_LINUX_APP_BOOT_BLOCK));
377 }
378
379 if (!(avail_coremask & (1 << coreid))) {
380 /* core not available, assume, that catched by simple-executive */
381 cvmx_write_csr(CVMX_CIU_PP_RST, 1 << coreid);
382 cvmx_write_csr(CVMX_CIU_PP_RST, 0);
383 }
384
385 boot_vect[coreid].app_start_func_addr =
386 (uint32_t) (unsigned long) start_after_reset;
387 boot_vect[coreid].code_addr = InitTLBStart_addr;
388
389 CVMX_SYNC;
390
391 cvmx_write_csr(CVMX_CIU_NMI, (1 << coreid) & avail_coremask);
392
393 return 0;
394}
395
396static int __cpuinit octeon_cpu_callback(struct notifier_block *nfb,
397 unsigned long action, void *hcpu)
398{
399 unsigned int cpu = (unsigned long)hcpu;
400
401 switch (action) {
402 case CPU_UP_PREPARE:
403 octeon_update_boot_vector(cpu);
404 break;
405 case CPU_ONLINE:
406 pr_info("Cpu %d online\n", cpu);
407 break;
408 case CPU_DEAD:
409 break;
410 }
411
412 return NOTIFY_OK;
413}
414
415static struct notifier_block __cpuinitdata octeon_cpu_notifier = {
416 .notifier_call = octeon_cpu_callback,
417};
418
419static int __cpuinit register_cavium_notifier(void)
420{
421 register_hotcpu_notifier(&octeon_cpu_notifier);
422
423 return 0;
424}
425
426late_initcall(register_cavium_notifier);
427
428#endif /* CONFIG_HOTPLUG_CPU */
429
202struct plat_smp_ops octeon_smp_ops = { 430struct plat_smp_ops octeon_smp_ops = {
203 .send_ipi_single = octeon_send_ipi_single, 431 .send_ipi_single = octeon_send_ipi_single,
204 .send_ipi_mask = octeon_send_ipi_mask, 432 .send_ipi_mask = octeon_send_ipi_mask,
@@ -208,4 +436,8 @@ struct plat_smp_ops octeon_smp_ops = {
208 .boot_secondary = octeon_boot_secondary, 436 .boot_secondary = octeon_boot_secondary,
209 .smp_setup = octeon_smp_setup, 437 .smp_setup = octeon_smp_setup,
210 .prepare_cpus = octeon_prepare_cpus, 438 .prepare_cpus = octeon_prepare_cpus,
439#ifdef CONFIG_HOTPLUG_CPU
440 .cpu_disable = octeon_cpu_disable,
441 .cpu_die = octeon_cpu_die,
442#endif
211}; 443};
diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
index 01f813dc3888..aaa2d4ab26dc 100644
--- a/arch/mips/include/asm/smp.h
+++ b/arch/mips/include/asm/smp.h
@@ -41,7 +41,7 @@ extern int __cpu_logical_map[NR_CPUS];
41/* Octeon - Tell another core to flush its icache */ 41/* Octeon - Tell another core to flush its icache */
42#define SMP_ICACHE_FLUSH 0x4 42#define SMP_ICACHE_FLUSH 0x4
43 43
44extern cpumask_t cpu_callin_map; 44extern volatile cpumask_t cpu_callin_map;
45 45
46extern void asmlinkage smp_bootstrap(void); 46extern void asmlinkage smp_bootstrap(void);
47 47