diff options
author | Huacai Chen <chenhc@lemote.com> | 2014-03-21 06:44:08 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2014-03-31 12:17:12 -0400 |
commit | 300459d558725cdada5ddebbe52c24ef6e1853d3 (patch) | |
tree | fb93b1d6c2845af29cce7c06ae35a3b88b7f6431 | |
parent | 0e476d91244ec6a9f6be3eb1963627340d031f99 (diff) |
MIPS: Loongson 3: Add Loongson-3 SMP support
IPI registers of Loongson-3 include IPI_SET, IPI_CLEAR, IPI_STATUS,
IPI_EN and IPI_MAILBOX_BUF. Each bit of IPI_STATUS indicate a type of
IPI and IPI_EN indicate whether the IPI is enabled. The sender write 1
to IPI_SET bits generate IPIs in IPI_STATUS, and receiver write 1 to
bits of IPI_CLEAR to clear IPIs. IPI_MAILBOX_BUF are used to deliver
more information about IPIs.
Why we change code in arch/mips/loongson/common/setup.c?
If without this change, when SMP configured, system cannot boot since
it hang at printk() in cgroup_init_early(). The root cause is:
console_trylock()
\-->down_trylock(&console_sem)
\-->raw_spin_unlock_irqrestore(&sem->lock, flags)
\-->_raw_spin_unlock_irqrestore()(SMP/UP have different versions)
\-->__raw_spin_unlock_irqrestore() (following is the SMP case)
\-->do_raw_spin_unlock()
\-->arch_spin_unlock()
\-->nudge_writes()
\-->mb()
\-->wbflush()
\-->__wbflush()
In previous code __wbflush() is initialized in plat_mem_setup(), but
cgroup_init_early() is called before plat_mem_setup(). Therefore, In
this patch we make changes to avoid boot failure.
Signed-off-by: Huacai Chen <chenhc@lemote.com>
Signed-off-by: Hongliang Tao <taohl@lemote.com>
Signed-off-by: Hua Yan <yanh@lemote.com>
Tested-by: Alex Smith <alex.smith@imgtec.com>
Reviewed-by: Alex Smith <alex.smith@imgtec.com>
Cc: John Crispin <john@phrozen.org>
Cc: Steven J. Hill <Steven.Hill@imgtec.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>
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/6638
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | arch/mips/include/asm/mach-loongson/irq.h | 2 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-loongson/loongson.h | 1 | ||||
-rw-r--r-- | arch/mips/loongson/common/init.c | 2 | ||||
-rw-r--r-- | arch/mips/loongson/common/setup.c | 8 | ||||
-rw-r--r-- | arch/mips/loongson/loongson-3/Makefile | 2 | ||||
-rw-r--r-- | arch/mips/loongson/loongson-3/irq.c | 20 | ||||
-rw-r--r-- | arch/mips/loongson/loongson-3/smp.c | 267 | ||||
-rw-r--r-- | arch/mips/loongson/loongson-3/smp.h | 29 |
8 files changed, 326 insertions, 5 deletions
diff --git a/arch/mips/include/asm/mach-loongson/irq.h b/arch/mips/include/asm/mach-loongson/irq.h index 29c2dff3aae8..0c77b22a6630 100644 --- a/arch/mips/include/asm/mach-loongson/irq.h +++ b/arch/mips/include/asm/mach-loongson/irq.h | |||
@@ -37,5 +37,7 @@ | |||
37 | 37 | ||
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | extern void loongson3_ipi_interrupt(struct pt_regs *regs); | ||
41 | |||
40 | #include_next <irq.h> | 42 | #include_next <irq.h> |
41 | #endif /* __ASM_MACH_LOONGSON_IRQ_H_ */ | 43 | #endif /* __ASM_MACH_LOONGSON_IRQ_H_ */ |
diff --git a/arch/mips/include/asm/mach-loongson/loongson.h b/arch/mips/include/asm/mach-loongson/loongson.h index 69e9d9ea90c4..f185907e8ce3 100644 --- a/arch/mips/include/asm/mach-loongson/loongson.h +++ b/arch/mips/include/asm/mach-loongson/loongson.h | |||
@@ -27,6 +27,7 @@ extern void mach_prepare_shutdown(void); | |||
27 | /* environment arguments from bootloader */ | 27 | /* environment arguments from bootloader */ |
28 | extern u32 cpu_clock_freq; | 28 | extern u32 cpu_clock_freq; |
29 | extern u32 memsize, highmemsize; | 29 | extern u32 memsize, highmemsize; |
30 | extern struct plat_smp_ops loongson3_smp_ops; | ||
30 | 31 | ||
31 | /* loongson-specific command line, env and memory initialization */ | 32 | /* loongson-specific command line, env and memory initialization */ |
32 | extern void __init prom_init_memory(void); | 33 | extern void __init prom_init_memory(void); |
diff --git a/arch/mips/loongson/common/init.c b/arch/mips/loongson/common/init.c index 81ba3b4a8f30..f37fe5413b73 100644 --- a/arch/mips/loongson/common/init.c +++ b/arch/mips/loongson/common/init.c | |||
@@ -9,6 +9,7 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/bootmem.h> | 11 | #include <linux/bootmem.h> |
12 | #include <asm/smp-ops.h> | ||
12 | 13 | ||
13 | #include <loongson.h> | 14 | #include <loongson.h> |
14 | 15 | ||
@@ -33,6 +34,7 @@ void __init prom_init(void) | |||
33 | 34 | ||
34 | /*init the uart base address */ | 35 | /*init the uart base address */ |
35 | prom_init_uart_base(); | 36 | prom_init_uart_base(); |
37 | register_smp_ops(&loongson3_smp_ops); | ||
36 | } | 38 | } |
37 | 39 | ||
38 | void __init prom_free_prom_memory(void) | 40 | void __init prom_free_prom_memory(void) |
diff --git a/arch/mips/loongson/common/setup.c b/arch/mips/loongson/common/setup.c index 8223f8acfd59..bb4ac922e47a 100644 --- a/arch/mips/loongson/common/setup.c +++ b/arch/mips/loongson/common/setup.c | |||
@@ -18,9 +18,6 @@ | |||
18 | #include <linux/screen_info.h> | 18 | #include <linux/screen_info.h> |
19 | #endif | 19 | #endif |
20 | 20 | ||
21 | void (*__wbflush)(void); | ||
22 | EXPORT_SYMBOL(__wbflush); | ||
23 | |||
24 | static void wbflush_loongson(void) | 21 | static void wbflush_loongson(void) |
25 | { | 22 | { |
26 | asm(".set\tpush\n\t" | 23 | asm(".set\tpush\n\t" |
@@ -32,10 +29,11 @@ static void wbflush_loongson(void) | |||
32 | ".set mips0\n\t"); | 29 | ".set mips0\n\t"); |
33 | } | 30 | } |
34 | 31 | ||
32 | void (*__wbflush)(void) = wbflush_loongson; | ||
33 | EXPORT_SYMBOL(__wbflush); | ||
34 | |||
35 | void __init plat_mem_setup(void) | 35 | void __init plat_mem_setup(void) |
36 | { | 36 | { |
37 | __wbflush = wbflush_loongson; | ||
38 | |||
39 | #ifdef CONFIG_VT | 37 | #ifdef CONFIG_VT |
40 | #if defined(CONFIG_VGA_CONSOLE) | 38 | #if defined(CONFIG_VGA_CONSOLE) |
41 | conswitchp = &vga_con; | 39 | conswitchp = &vga_con; |
diff --git a/arch/mips/loongson/loongson-3/Makefile b/arch/mips/loongson/loongson-3/Makefile index b9968cd1602e..70152b252ddc 100644 --- a/arch/mips/loongson/loongson-3/Makefile +++ b/arch/mips/loongson/loongson-3/Makefile | |||
@@ -2,3 +2,5 @@ | |||
2 | # Makefile for Loongson-3 family machines | 2 | # Makefile for Loongson-3 family machines |
3 | # | 3 | # |
4 | obj-y += irq.o | 4 | obj-y += irq.o |
5 | |||
6 | obj-$(CONFIG_SMP) += smp.o | ||
diff --git a/arch/mips/loongson/loongson-3/irq.c b/arch/mips/loongson/loongson-3/irq.c index b2dc62b97a0f..088fd5e4fd64 100644 --- a/arch/mips/loongson/loongson-3/irq.c +++ b/arch/mips/loongson/loongson-3/irq.c | |||
@@ -26,6 +26,10 @@ void mach_irq_dispatch(unsigned int pending) | |||
26 | { | 26 | { |
27 | if (pending & CAUSEF_IP7) | 27 | if (pending & CAUSEF_IP7) |
28 | do_IRQ(LOONGSON_TIMER_IRQ); | 28 | do_IRQ(LOONGSON_TIMER_IRQ); |
29 | #if defined(CONFIG_SMP) | ||
30 | else if (pending & CAUSEF_IP6) | ||
31 | loongson3_ipi_interrupt(NULL); | ||
32 | #endif | ||
29 | else if (pending & CAUSEF_IP3) | 33 | else if (pending & CAUSEF_IP3) |
30 | ht_irqdispatch(); | 34 | ht_irqdispatch(); |
31 | else if (pending & CAUSEF_IP2) | 35 | else if (pending & CAUSEF_IP2) |
@@ -45,10 +49,26 @@ static inline void mask_loongson_irq(struct irq_data *d) | |||
45 | { | 49 | { |
46 | clear_c0_status(0x100 << (d->irq - MIPS_CPU_IRQ_BASE)); | 50 | clear_c0_status(0x100 << (d->irq - MIPS_CPU_IRQ_BASE)); |
47 | irq_disable_hazard(); | 51 | irq_disable_hazard(); |
52 | |||
53 | /* Workaround: UART IRQ may deliver to any core */ | ||
54 | if (d->irq == LOONGSON_UART_IRQ) { | ||
55 | int cpu = smp_processor_id(); | ||
56 | |||
57 | LOONGSON_INT_ROUTER_INTENCLR = 1 << 10; | ||
58 | LOONGSON_INT_ROUTER_LPC = 0x10 + (1<<cpu); | ||
59 | } | ||
48 | } | 60 | } |
49 | 61 | ||
50 | static inline void unmask_loongson_irq(struct irq_data *d) | 62 | static inline void unmask_loongson_irq(struct irq_data *d) |
51 | { | 63 | { |
64 | /* Workaround: UART IRQ may deliver to any core */ | ||
65 | if (d->irq == LOONGSON_UART_IRQ) { | ||
66 | int cpu = smp_processor_id(); | ||
67 | |||
68 | LOONGSON_INT_ROUTER_INTENSET = 1 << 10; | ||
69 | LOONGSON_INT_ROUTER_LPC = 0x10 + (1<<cpu); | ||
70 | } | ||
71 | |||
52 | set_c0_status(0x100 << (d->irq - MIPS_CPU_IRQ_BASE)); | 72 | set_c0_status(0x100 << (d->irq - MIPS_CPU_IRQ_BASE)); |
53 | irq_enable_hazard(); | 73 | irq_enable_hazard(); |
54 | } | 74 | } |
diff --git a/arch/mips/loongson/loongson-3/smp.c b/arch/mips/loongson/loongson-3/smp.c new file mode 100644 index 000000000000..93483c25b4b9 --- /dev/null +++ b/arch/mips/loongson/loongson-3/smp.c | |||
@@ -0,0 +1,267 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010, 2011, 2012, Lemote, Inc. | ||
3 | * Author: Chen Huacai, chenhc@lemote.com | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License | ||
7 | * as published by the Free Software Foundation; either version 2 | ||
8 | * of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/init.h> | ||
18 | #include <linux/cpu.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/smp.h> | ||
21 | #include <linux/cpufreq.h> | ||
22 | #include <asm/processor.h> | ||
23 | #include <asm/time.h> | ||
24 | #include <asm/clock.h> | ||
25 | #include <asm/tlbflush.h> | ||
26 | #include <loongson.h> | ||
27 | |||
28 | #include "smp.h" | ||
29 | |||
30 | /* read a 32bit value from ipi register */ | ||
31 | #define loongson3_ipi_read32(addr) readl(addr) | ||
32 | /* read a 64bit value from ipi register */ | ||
33 | #define loongson3_ipi_read64(addr) readq(addr) | ||
34 | /* write a 32bit value to ipi register */ | ||
35 | #define loongson3_ipi_write32(action, addr) \ | ||
36 | do { \ | ||
37 | writel(action, addr); \ | ||
38 | __wbflush(); \ | ||
39 | } while (0) | ||
40 | /* write a 64bit value to ipi register */ | ||
41 | #define loongson3_ipi_write64(action, addr) \ | ||
42 | do { \ | ||
43 | writeq(action, addr); \ | ||
44 | __wbflush(); \ | ||
45 | } while (0) | ||
46 | |||
47 | static void *ipi_set0_regs[] = { | ||
48 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE0_OFFSET + SET0), | ||
49 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE1_OFFSET + SET0), | ||
50 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE2_OFFSET + SET0), | ||
51 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE3_OFFSET + SET0), | ||
52 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE0_OFFSET + SET0), | ||
53 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE1_OFFSET + SET0), | ||
54 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE2_OFFSET + SET0), | ||
55 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE3_OFFSET + SET0), | ||
56 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE0_OFFSET + SET0), | ||
57 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE1_OFFSET + SET0), | ||
58 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE2_OFFSET + SET0), | ||
59 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE3_OFFSET + SET0), | ||
60 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE0_OFFSET + SET0), | ||
61 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE1_OFFSET + SET0), | ||
62 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE2_OFFSET + SET0), | ||
63 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE3_OFFSET + SET0), | ||
64 | }; | ||
65 | |||
66 | static void *ipi_clear0_regs[] = { | ||
67 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE0_OFFSET + CLEAR0), | ||
68 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE1_OFFSET + CLEAR0), | ||
69 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE2_OFFSET + CLEAR0), | ||
70 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE3_OFFSET + CLEAR0), | ||
71 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE0_OFFSET + CLEAR0), | ||
72 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE1_OFFSET + CLEAR0), | ||
73 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE2_OFFSET + CLEAR0), | ||
74 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE3_OFFSET + CLEAR0), | ||
75 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE0_OFFSET + CLEAR0), | ||
76 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE1_OFFSET + CLEAR0), | ||
77 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE2_OFFSET + CLEAR0), | ||
78 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE3_OFFSET + CLEAR0), | ||
79 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE0_OFFSET + CLEAR0), | ||
80 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE1_OFFSET + CLEAR0), | ||
81 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE2_OFFSET + CLEAR0), | ||
82 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE3_OFFSET + CLEAR0), | ||
83 | }; | ||
84 | |||
85 | static void *ipi_status0_regs[] = { | ||
86 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE0_OFFSET + STATUS0), | ||
87 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE1_OFFSET + STATUS0), | ||
88 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE2_OFFSET + STATUS0), | ||
89 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE3_OFFSET + STATUS0), | ||
90 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE0_OFFSET + STATUS0), | ||
91 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE1_OFFSET + STATUS0), | ||
92 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE2_OFFSET + STATUS0), | ||
93 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE3_OFFSET + STATUS0), | ||
94 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE0_OFFSET + STATUS0), | ||
95 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE1_OFFSET + STATUS0), | ||
96 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE2_OFFSET + STATUS0), | ||
97 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE3_OFFSET + STATUS0), | ||
98 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE0_OFFSET + STATUS0), | ||
99 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE1_OFFSET + STATUS0), | ||
100 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE2_OFFSET + STATUS0), | ||
101 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE3_OFFSET + STATUS0), | ||
102 | }; | ||
103 | |||
104 | static void *ipi_en0_regs[] = { | ||
105 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE0_OFFSET + EN0), | ||
106 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE1_OFFSET + EN0), | ||
107 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE2_OFFSET + EN0), | ||
108 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE3_OFFSET + EN0), | ||
109 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE0_OFFSET + EN0), | ||
110 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE1_OFFSET + EN0), | ||
111 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE2_OFFSET + EN0), | ||
112 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE3_OFFSET + EN0), | ||
113 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE0_OFFSET + EN0), | ||
114 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE1_OFFSET + EN0), | ||
115 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE2_OFFSET + EN0), | ||
116 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE3_OFFSET + EN0), | ||
117 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE0_OFFSET + EN0), | ||
118 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE1_OFFSET + EN0), | ||
119 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE2_OFFSET + EN0), | ||
120 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE3_OFFSET + EN0), | ||
121 | }; | ||
122 | |||
123 | static void *ipi_mailbox_buf[] = { | ||
124 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE0_OFFSET + BUF), | ||
125 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE1_OFFSET + BUF), | ||
126 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE2_OFFSET + BUF), | ||
127 | (void *)(SMP_CORE_GROUP0_BASE + SMP_CORE3_OFFSET + BUF), | ||
128 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE0_OFFSET + BUF), | ||
129 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE1_OFFSET + BUF), | ||
130 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE2_OFFSET + BUF), | ||
131 | (void *)(SMP_CORE_GROUP1_BASE + SMP_CORE3_OFFSET + BUF), | ||
132 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE0_OFFSET + BUF), | ||
133 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE1_OFFSET + BUF), | ||
134 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE2_OFFSET + BUF), | ||
135 | (void *)(SMP_CORE_GROUP2_BASE + SMP_CORE3_OFFSET + BUF), | ||
136 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE0_OFFSET + BUF), | ||
137 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE1_OFFSET + BUF), | ||
138 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE2_OFFSET + BUF), | ||
139 | (void *)(SMP_CORE_GROUP3_BASE + SMP_CORE3_OFFSET + BUF), | ||
140 | }; | ||
141 | |||
142 | /* | ||
143 | * Simple enough, just poke the appropriate ipi register | ||
144 | */ | ||
145 | static void loongson3_send_ipi_single(int cpu, unsigned int action) | ||
146 | { | ||
147 | loongson3_ipi_write32((u32)action, ipi_set0_regs[cpu]); | ||
148 | } | ||
149 | |||
150 | static void | ||
151 | loongson3_send_ipi_mask(const struct cpumask *mask, unsigned int action) | ||
152 | { | ||
153 | unsigned int i; | ||
154 | |||
155 | for_each_cpu(i, mask) | ||
156 | loongson3_ipi_write32((u32)action, ipi_set0_regs[i]); | ||
157 | } | ||
158 | |||
159 | void loongson3_ipi_interrupt(struct pt_regs *regs) | ||
160 | { | ||
161 | int cpu = smp_processor_id(); | ||
162 | unsigned int action; | ||
163 | |||
164 | /* Load the ipi register to figure out what we're supposed to do */ | ||
165 | action = loongson3_ipi_read32(ipi_status0_regs[cpu]); | ||
166 | |||
167 | /* Clear the ipi register to clear the interrupt */ | ||
168 | loongson3_ipi_write32((u32)action, ipi_clear0_regs[cpu]); | ||
169 | |||
170 | if (action & SMP_RESCHEDULE_YOURSELF) | ||
171 | scheduler_ipi(); | ||
172 | |||
173 | if (action & SMP_CALL_FUNCTION) | ||
174 | smp_call_function_interrupt(); | ||
175 | } | ||
176 | |||
177 | /* | ||
178 | * SMP init and finish on secondary CPUs | ||
179 | */ | ||
180 | static void loongson3_init_secondary(void) | ||
181 | { | ||
182 | int i; | ||
183 | unsigned int imask = STATUSF_IP7 | STATUSF_IP6 | | ||
184 | STATUSF_IP3 | STATUSF_IP2; | ||
185 | |||
186 | /* Set interrupt mask, but don't enable */ | ||
187 | change_c0_status(ST0_IM, imask); | ||
188 | |||
189 | for (i = 0; i < loongson_sysconf.nr_cpus; i++) | ||
190 | loongson3_ipi_write32(0xffffffff, ipi_en0_regs[i]); | ||
191 | } | ||
192 | |||
193 | static void loongson3_smp_finish(void) | ||
194 | { | ||
195 | write_c0_compare(read_c0_count() + mips_hpt_frequency/HZ); | ||
196 | local_irq_enable(); | ||
197 | loongson3_ipi_write64(0, | ||
198 | (void *)(ipi_mailbox_buf[smp_processor_id()]+0x0)); | ||
199 | pr_info("CPU#%d finished, CP0_ST=%x\n", | ||
200 | smp_processor_id(), read_c0_status()); | ||
201 | } | ||
202 | |||
203 | static void __init loongson3_smp_setup(void) | ||
204 | { | ||
205 | int i, num; | ||
206 | |||
207 | init_cpu_possible(cpu_none_mask); | ||
208 | set_cpu_possible(0, true); | ||
209 | |||
210 | __cpu_number_map[0] = 0; | ||
211 | __cpu_logical_map[0] = 0; | ||
212 | |||
213 | /* For unified kernel, NR_CPUS is the maximum possible value, | ||
214 | * loongson_sysconf.nr_cpus is the really present value */ | ||
215 | for (i = 1, num = 0; i < loongson_sysconf.nr_cpus; i++) { | ||
216 | set_cpu_possible(i, true); | ||
217 | __cpu_number_map[i] = ++num; | ||
218 | __cpu_logical_map[num] = i; | ||
219 | } | ||
220 | pr_info("Detected %i available secondary CPU(s)\n", num); | ||
221 | } | ||
222 | |||
223 | static void __init loongson3_prepare_cpus(unsigned int max_cpus) | ||
224 | { | ||
225 | } | ||
226 | |||
227 | /* | ||
228 | * Setup the PC, SP, and GP of a secondary processor and start it runing! | ||
229 | */ | ||
230 | static void loongson3_boot_secondary(int cpu, struct task_struct *idle) | ||
231 | { | ||
232 | unsigned long startargs[4]; | ||
233 | |||
234 | pr_info("Booting CPU#%d...\n", cpu); | ||
235 | |||
236 | /* startargs[] are initial PC, SP and GP for secondary CPU */ | ||
237 | startargs[0] = (unsigned long)&smp_bootstrap; | ||
238 | startargs[1] = (unsigned long)__KSTK_TOS(idle); | ||
239 | startargs[2] = (unsigned long)task_thread_info(idle); | ||
240 | startargs[3] = 0; | ||
241 | |||
242 | pr_debug("CPU#%d, func_pc=%lx, sp=%lx, gp=%lx\n", | ||
243 | cpu, startargs[0], startargs[1], startargs[2]); | ||
244 | |||
245 | loongson3_ipi_write64(startargs[3], (void *)(ipi_mailbox_buf[cpu]+0x18)); | ||
246 | loongson3_ipi_write64(startargs[2], (void *)(ipi_mailbox_buf[cpu]+0x10)); | ||
247 | loongson3_ipi_write64(startargs[1], (void *)(ipi_mailbox_buf[cpu]+0x8)); | ||
248 | loongson3_ipi_write64(startargs[0], (void *)(ipi_mailbox_buf[cpu]+0x0)); | ||
249 | } | ||
250 | |||
251 | /* | ||
252 | * Final cleanup after all secondaries booted | ||
253 | */ | ||
254 | static void __init loongson3_cpus_done(void) | ||
255 | { | ||
256 | } | ||
257 | |||
258 | struct plat_smp_ops loongson3_smp_ops = { | ||
259 | .send_ipi_single = loongson3_send_ipi_single, | ||
260 | .send_ipi_mask = loongson3_send_ipi_mask, | ||
261 | .init_secondary = loongson3_init_secondary, | ||
262 | .smp_finish = loongson3_smp_finish, | ||
263 | .cpus_done = loongson3_cpus_done, | ||
264 | .boot_secondary = loongson3_boot_secondary, | ||
265 | .smp_setup = loongson3_smp_setup, | ||
266 | .prepare_cpus = loongson3_prepare_cpus, | ||
267 | }; | ||
diff --git a/arch/mips/loongson/loongson-3/smp.h b/arch/mips/loongson/loongson-3/smp.h new file mode 100644 index 000000000000..3453e8c4f2f0 --- /dev/null +++ b/arch/mips/loongson/loongson-3/smp.h | |||
@@ -0,0 +1,29 @@ | |||
1 | #ifndef __LOONGSON_SMP_H_ | ||
2 | #define __LOONGSON_SMP_H_ | ||
3 | |||
4 | /* for Loongson-3A smp support */ | ||
5 | |||
6 | /* 4 groups(nodes) in maximum in numa case */ | ||
7 | #define SMP_CORE_GROUP0_BASE 0x900000003ff01000 | ||
8 | #define SMP_CORE_GROUP1_BASE 0x900010003ff01000 | ||
9 | #define SMP_CORE_GROUP2_BASE 0x900020003ff01000 | ||
10 | #define SMP_CORE_GROUP3_BASE 0x900030003ff01000 | ||
11 | |||
12 | /* 4 cores in each group(node) */ | ||
13 | #define SMP_CORE0_OFFSET 0x000 | ||
14 | #define SMP_CORE1_OFFSET 0x100 | ||
15 | #define SMP_CORE2_OFFSET 0x200 | ||
16 | #define SMP_CORE3_OFFSET 0x300 | ||
17 | |||
18 | /* ipi registers offsets */ | ||
19 | #define STATUS0 0x00 | ||
20 | #define EN0 0x04 | ||
21 | #define SET0 0x08 | ||
22 | #define CLEAR0 0x0c | ||
23 | #define STATUS1 0x10 | ||
24 | #define MASK1 0x14 | ||
25 | #define SET1 0x18 | ||
26 | #define CLEAR1 0x1c | ||
27 | #define BUF 0x20 | ||
28 | |||
29 | #endif | ||