aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell King <rmk@dyn-67.arm.linux.org.uk>2009-06-01 13:35:26 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2009-06-01 13:35:26 -0400
commitc7f7ff179cb9f2f1e0244ef2c80afbb93c74ce2a (patch)
tree717656ebdba1fea6c763b2c57076c4c6996dfba3
parenta22f277bba321474a01691ae66d5952926459f44 (diff)
parente03cdade0ca945a04e982525e50fef275190b77b (diff)
Merge branch 'smp' into devel
-rw-r--r--arch/arm/Kconfig15
-rw-r--r--arch/arm/include/asm/hardware/arm_twd.h21
-rw-r--r--arch/arm/include/asm/localtimer.h63
-rw-r--r--arch/arm/include/asm/smp.h42
-rw-r--r--arch/arm/include/asm/smp_scu.h7
-rw-r--r--arch/arm/include/asm/smp_twd.h12
-rw-r--r--arch/arm/kernel/Makefile2
-rw-r--r--arch/arm/kernel/smp.c62
-rw-r--r--arch/arm/kernel/smp_scu.c48
-rw-r--r--arch/arm/kernel/smp_twd.c175
-rw-r--r--arch/arm/mach-realview/Makefile3
-rw-r--r--arch/arm/mach-realview/core.h3
-rw-r--r--arch/arm/mach-realview/include/mach/scu.h13
-rw-r--r--arch/arm/mach-realview/localtimer.c188
-rw-r--r--arch/arm/mach-realview/platsmp.c49
-rw-r--r--arch/arm/mach-realview/realview_eb.c1
-rw-r--r--arch/arm/mach-realview/realview_pb11mp.c1
17 files changed, 398 insertions, 307 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 65778839d380..28248b5d6a70 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -844,7 +844,9 @@ source "kernel/time/Kconfig"
844config SMP 844config SMP
845 bool "Symmetric Multi-Processing (EXPERIMENTAL)" 845 bool "Symmetric Multi-Processing (EXPERIMENTAL)"
846 depends on EXPERIMENTAL && (REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP) 846 depends on EXPERIMENTAL && (REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP)
847 depends on GENERIC_CLOCKEVENTS
847 select USE_GENERIC_SMP_HELPERS 848 select USE_GENERIC_SMP_HELPERS
849 select HAVE_ARM_SCU if ARCH_REALVIEW
848 help 850 help
849 This enables support for systems with more than one CPU. If you have 851 This enables support for systems with more than one CPU. If you have
850 a system with only one CPU, like most personal computers, say N. If 852 a system with only one CPU, like most personal computers, say N. If
@@ -862,6 +864,18 @@ config SMP
862 864
863 If you don't know what to do here, say N. 865 If you don't know what to do here, say N.
864 866
867config HAVE_ARM_SCU
868 bool
869 depends on SMP
870 help
871 This option enables support for the ARM system coherency unit
872
873config HAVE_ARM_TWD
874 bool
875 depends on SMP
876 help
877 This options enables support for the ARM timer and watchdog unit
878
865choice 879choice
866 prompt "Memory split" 880 prompt "Memory split"
867 default VMSPLIT_3G 881 default VMSPLIT_3G
@@ -902,6 +916,7 @@ config LOCAL_TIMERS
902 bool "Use local timer interrupts" 916 bool "Use local timer interrupts"
903 depends on SMP && (REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || REALVIEW_EB_A9MP) 917 depends on SMP && (REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || REALVIEW_EB_A9MP)
904 default y 918 default y
919 select HAVE_ARM_TWD if ARCH_REALVIEW
905 help 920 help
906 Enable support for local timers on SMP platforms, rather then the 921 Enable support for local timers on SMP platforms, rather then the
907 legacy IPI broadcast method. Local timers allows the system 922 legacy IPI broadcast method. Local timers allows the system
diff --git a/arch/arm/include/asm/hardware/arm_twd.h b/arch/arm/include/asm/hardware/arm_twd.h
deleted file mode 100644
index e521b70713c8..000000000000
--- a/arch/arm/include/asm/hardware/arm_twd.h
+++ /dev/null
@@ -1,21 +0,0 @@
1#ifndef __ASM_HARDWARE_TWD_H
2#define __ASM_HARDWARE_TWD_H
3
4#define TWD_TIMER_LOAD 0x00
5#define TWD_TIMER_COUNTER 0x04
6#define TWD_TIMER_CONTROL 0x08
7#define TWD_TIMER_INTSTAT 0x0C
8
9#define TWD_WDOG_LOAD 0x20
10#define TWD_WDOG_COUNTER 0x24
11#define TWD_WDOG_CONTROL 0x28
12#define TWD_WDOG_INTSTAT 0x2C
13#define TWD_WDOG_RESETSTAT 0x30
14#define TWD_WDOG_DISABLE 0x34
15
16#define TWD_TIMER_CONTROL_ENABLE (1 << 0)
17#define TWD_TIMER_CONTROL_ONESHOT (0 << 1)
18#define TWD_TIMER_CONTROL_PERIODIC (1 << 1)
19#define TWD_TIMER_CONTROL_IT_ENABLE (1 << 2)
20
21#endif
diff --git a/arch/arm/include/asm/localtimer.h b/arch/arm/include/asm/localtimer.h
new file mode 100644
index 000000000000..50c7e7cfd670
--- /dev/null
+++ b/arch/arm/include/asm/localtimer.h
@@ -0,0 +1,63 @@
1/*
2 * arch/arm/include/asm/localtimer.h
3 *
4 * Copyright (C) 2004-2005 ARM Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef __ASM_ARM_LOCALTIMER_H
11#define __ASM_ARM_LOCALTIMER_H
12
13struct clock_event_device;
14
15/*
16 * Setup a per-cpu timer, whether it be a local timer or dummy broadcast
17 */
18void percpu_timer_setup(void);
19
20/*
21 * Called from assembly, this is the local timer IRQ handler
22 */
23asmlinkage void do_local_timer(struct pt_regs *);
24
25
26#ifdef CONFIG_LOCAL_TIMERS
27
28#ifdef CONFIG_HAVE_ARM_TWD
29
30#include "smp_twd.h"
31
32#define local_timer_ack() twd_timer_ack()
33#define local_timer_stop() twd_timer_stop()
34
35#else
36
37/*
38 * Platform provides this to acknowledge a local timer IRQ.
39 * Returns true if the local timer IRQ is to be processed.
40 */
41int local_timer_ack(void);
42
43/*
44 * Stop a local timer interrupt.
45 */
46void local_timer_stop(void);
47
48#endif
49
50/*
51 * Setup a local timer interrupt for a CPU.
52 */
53void local_timer_setup(struct clock_event_device *);
54
55#else
56
57static inline void local_timer_stop(void)
58{
59}
60
61#endif
62
63#endif
diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
index 5995935338e1..a06e735b262a 100644
--- a/arch/arm/include/asm/smp.h
+++ b/arch/arm/include/asm/smp.h
@@ -41,7 +41,7 @@ extern void show_ipi_list(struct seq_file *p);
41asmlinkage void do_IPI(struct pt_regs *regs); 41asmlinkage void do_IPI(struct pt_regs *regs);
42 42
43/* 43/*
44 * Setup the SMP cpu_possible_map 44 * Setup the set of possible CPUs (via set_cpu_possible)
45 */ 45 */
46extern void smp_init_cpus(void); 46extern void smp_init_cpus(void);
47 47
@@ -56,11 +56,6 @@ extern void smp_store_cpu_info(unsigned int cpuid);
56extern void smp_cross_call(const struct cpumask *mask); 56extern void smp_cross_call(const struct cpumask *mask);
57 57
58/* 58/*
59 * Broadcast a clock event to other CPUs.
60 */
61extern void smp_timer_broadcast(const struct cpumask *mask);
62
63/*
64 * Boot a secondary CPU, and assign it the specified idle task. 59 * Boot a secondary CPU, and assign it the specified idle task.
65 * This also gives us the initial stack to use for this CPU. 60 * This also gives us the initial stack to use for this CPU.
66 */ 61 */
@@ -101,43 +96,8 @@ extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
101#define arch_send_call_function_ipi_mask arch_send_call_function_ipi_mask 96#define arch_send_call_function_ipi_mask arch_send_call_function_ipi_mask
102 97
103/* 98/*
104 * Local timer interrupt handling function (can be IPI'ed).
105 */
106extern void local_timer_interrupt(void);
107
108#ifdef CONFIG_LOCAL_TIMERS
109
110/*
111 * Stop a local timer interrupt.
112 */
113extern void local_timer_stop(void);
114
115/*
116 * Platform provides this to acknowledge a local timer IRQ
117 */
118extern int local_timer_ack(void);
119
120#else
121
122static inline void local_timer_stop(void)
123{
124}
125
126#endif
127
128/*
129 * Setup a local timer interrupt for a CPU.
130 */
131extern void local_timer_setup(void);
132
133/*
134 * show local interrupt info 99 * show local interrupt info
135 */ 100 */
136extern void show_local_irqs(struct seq_file *); 101extern void show_local_irqs(struct seq_file *);
137 102
138/*
139 * Called from assembly, this is the local timer IRQ handler
140 */
141asmlinkage void do_local_timer(struct pt_regs *);
142
143#endif /* ifndef __ASM_ARM_SMP_H */ 103#endif /* ifndef __ASM_ARM_SMP_H */
diff --git a/arch/arm/include/asm/smp_scu.h b/arch/arm/include/asm/smp_scu.h
new file mode 100644
index 000000000000..2376835015d6
--- /dev/null
+++ b/arch/arm/include/asm/smp_scu.h
@@ -0,0 +1,7 @@
1#ifndef __ASMARM_ARCH_SCU_H
2#define __ASMARM_ARCH_SCU_H
3
4unsigned int scu_get_core_count(void __iomem *);
5void scu_enable(void __iomem *);
6
7#endif
diff --git a/arch/arm/include/asm/smp_twd.h b/arch/arm/include/asm/smp_twd.h
new file mode 100644
index 000000000000..7be0978b2625
--- /dev/null
+++ b/arch/arm/include/asm/smp_twd.h
@@ -0,0 +1,12 @@
1#ifndef __ASMARM_SMP_TWD_H
2#define __ASMARM_SMP_TWD_H
3
4struct clock_event_device;
5
6extern void __iomem *twd_base;
7
8void twd_timer_stop(void);
9int twd_timer_ack(void);
10void twd_timer_setup(struct clock_event_device *);
11
12#endif
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index 11a5197a221f..ff89d0b3abc5 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -22,6 +22,8 @@ obj-$(CONFIG_ARTHUR) += arthur.o
22obj-$(CONFIG_ISA_DMA) += dma-isa.o 22obj-$(CONFIG_ISA_DMA) += dma-isa.o
23obj-$(CONFIG_PCI) += bios32.o isa.o 23obj-$(CONFIG_PCI) += bios32.o isa.o
24obj-$(CONFIG_SMP) += smp.o 24obj-$(CONFIG_SMP) += smp.o
25obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o
26obj-$(CONFIG_HAVE_ARM_TWD) += smp_twd.o
25obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o 27obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
26obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o 28obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
27obj-$(CONFIG_KPROBES) += kprobes.o kprobes-decode.o 29obj-$(CONFIG_KPROBES) += kprobes.o kprobes-decode.o
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 6014dfd22af4..0d8097fa4ca5 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -22,6 +22,8 @@
22#include <linux/smp.h> 22#include <linux/smp.h>
23#include <linux/seq_file.h> 23#include <linux/seq_file.h>
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/percpu.h>
26#include <linux/clockchips.h>
25 27
26#include <asm/atomic.h> 28#include <asm/atomic.h>
27#include <asm/cacheflush.h> 29#include <asm/cacheflush.h>
@@ -32,6 +34,7 @@
32#include <asm/processor.h> 34#include <asm/processor.h>
33#include <asm/tlbflush.h> 35#include <asm/tlbflush.h>
34#include <asm/ptrace.h> 36#include <asm/ptrace.h>
37#include <asm/localtimer.h>
35 38
36/* 39/*
37 * as from 2.5, kernels no longer have an init_tasks structure 40 * as from 2.5, kernels no longer have an init_tasks structure
@@ -163,7 +166,7 @@ int __cpuexit __cpu_disable(void)
163 * Take this CPU offline. Once we clear this, we can't return, 166 * Take this CPU offline. Once we clear this, we can't return,
164 * and we must not schedule until we're ready to give up the cpu. 167 * and we must not schedule until we're ready to give up the cpu.
165 */ 168 */
166 cpu_clear(cpu, cpu_online_map); 169 set_cpu_online(cpu, false);
167 170
168 /* 171 /*
169 * OK - migrate IRQs away from this CPU 172 * OK - migrate IRQs away from this CPU
@@ -274,9 +277,9 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
274 local_fiq_enable(); 277 local_fiq_enable();
275 278
276 /* 279 /*
277 * Setup local timer for this CPU. 280 * Setup the percpu timer for this CPU.
278 */ 281 */
279 local_timer_setup(); 282 percpu_timer_setup();
280 283
281 calibrate_delay(); 284 calibrate_delay();
282 285
@@ -285,7 +288,7 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
285 /* 288 /*
286 * OK, now it's safe to let the boot CPU continue 289 * OK, now it's safe to let the boot CPU continue
287 */ 290 */
288 cpu_set(cpu, cpu_online_map); 291 set_cpu_online(cpu, true);
289 292
290 /* 293 /*
291 * OK, it's off to the idle thread for us 294 * OK, it's off to the idle thread for us
@@ -383,10 +386,16 @@ void show_local_irqs(struct seq_file *p)
383 seq_putc(p, '\n'); 386 seq_putc(p, '\n');
384} 387}
385 388
389/*
390 * Timer (local or broadcast) support
391 */
392static DEFINE_PER_CPU(struct clock_event_device, percpu_clockevent);
393
386static void ipi_timer(void) 394static void ipi_timer(void)
387{ 395{
396 struct clock_event_device *evt = &__get_cpu_var(percpu_clockevent);
388 irq_enter(); 397 irq_enter();
389 local_timer_interrupt(); 398 evt->event_handler(evt);
390 irq_exit(); 399 irq_exit();
391} 400}
392 401
@@ -405,6 +414,42 @@ asmlinkage void __exception do_local_timer(struct pt_regs *regs)
405} 414}
406#endif 415#endif
407 416
417#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
418static void smp_timer_broadcast(const struct cpumask *mask)
419{
420 send_ipi_message(mask, IPI_TIMER);
421}
422
423static void broadcast_timer_set_mode(enum clock_event_mode mode,
424 struct clock_event_device *evt)
425{
426}
427
428static void local_timer_setup(struct clock_event_device *evt)
429{
430 evt->name = "dummy_timer";
431 evt->features = CLOCK_EVT_FEAT_ONESHOT |
432 CLOCK_EVT_FEAT_PERIODIC |
433 CLOCK_EVT_FEAT_DUMMY;
434 evt->rating = 400;
435 evt->mult = 1;
436 evt->set_mode = broadcast_timer_set_mode;
437 evt->broadcast = smp_timer_broadcast;
438
439 clockevents_register_device(evt);
440}
441#endif
442
443void __cpuinit percpu_timer_setup(void)
444{
445 unsigned int cpu = smp_processor_id();
446 struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
447
448 evt->cpumask = cpumask_of(cpu);
449
450 local_timer_setup(evt);
451}
452
408static DEFINE_SPINLOCK(stop_lock); 453static DEFINE_SPINLOCK(stop_lock);
409 454
410/* 455/*
@@ -417,7 +462,7 @@ static void ipi_cpu_stop(unsigned int cpu)
417 dump_stack(); 462 dump_stack();
418 spin_unlock(&stop_lock); 463 spin_unlock(&stop_lock);
419 464
420 cpu_clear(cpu, cpu_online_map); 465 set_cpu_online(cpu, false);
421 466
422 local_fiq_disable(); 467 local_fiq_disable();
423 local_irq_disable(); 468 local_irq_disable();
@@ -501,11 +546,6 @@ void smp_send_reschedule(int cpu)
501 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE); 546 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
502} 547}
503 548
504void smp_timer_broadcast(const struct cpumask *mask)
505{
506 send_ipi_message(mask, IPI_TIMER);
507}
508
509void smp_send_stop(void) 549void smp_send_stop(void)
510{ 550{
511 cpumask_t mask = cpu_online_map; 551 cpumask_t mask = cpu_online_map;
diff --git a/arch/arm/kernel/smp_scu.c b/arch/arm/kernel/smp_scu.c
new file mode 100644
index 000000000000..d3831f616ee9
--- /dev/null
+++ b/arch/arm/kernel/smp_scu.c
@@ -0,0 +1,48 @@
1/*
2 * linux/arch/arm/kernel/smp_scu.c
3 *
4 * Copyright (C) 2002 ARM Ltd.
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/init.h>
12#include <linux/io.h>
13
14#include <asm/smp_scu.h>
15#include <asm/cacheflush.h>
16
17#define SCU_CTRL 0x00
18#define SCU_CONFIG 0x04
19#define SCU_CPU_STATUS 0x08
20#define SCU_INVALIDATE 0x0c
21#define SCU_FPGA_REVISION 0x10
22
23/*
24 * Get the number of CPU cores from the SCU configuration
25 */
26unsigned int __init scu_get_core_count(void __iomem *scu_base)
27{
28 unsigned int ncores = __raw_readl(scu_base + SCU_CONFIG);
29 return (ncores & 0x03) + 1;
30}
31
32/*
33 * Enable the SCU
34 */
35void __init scu_enable(void __iomem *scu_base)
36{
37 u32 scu_ctrl;
38
39 scu_ctrl = __raw_readl(scu_base + SCU_CTRL);
40 scu_ctrl |= 1;
41 __raw_writel(scu_ctrl, scu_base + SCU_CTRL);
42
43 /*
44 * Ensure that the data accessed by CPU0 before the SCU was
45 * initialised is visible to the other CPUs.
46 */
47 flush_cache_all();
48}
diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
new file mode 100644
index 000000000000..d8c88c633c6f
--- /dev/null
+++ b/arch/arm/kernel/smp_twd.c
@@ -0,0 +1,175 @@
1/*
2 * linux/arch/arm/kernel/smp_twd.c
3 *
4 * Copyright (C) 2002 ARM Ltd.
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/delay.h>
14#include <linux/device.h>
15#include <linux/smp.h>
16#include <linux/jiffies.h>
17#include <linux/clockchips.h>
18#include <linux/irq.h>
19#include <linux/io.h>
20
21#include <asm/smp_twd.h>
22#include <asm/hardware/gic.h>
23
24#define TWD_TIMER_LOAD 0x00
25#define TWD_TIMER_COUNTER 0x04
26#define TWD_TIMER_CONTROL 0x08
27#define TWD_TIMER_INTSTAT 0x0C
28
29#define TWD_WDOG_LOAD 0x20
30#define TWD_WDOG_COUNTER 0x24
31#define TWD_WDOG_CONTROL 0x28
32#define TWD_WDOG_INTSTAT 0x2C
33#define TWD_WDOG_RESETSTAT 0x30
34#define TWD_WDOG_DISABLE 0x34
35
36#define TWD_TIMER_CONTROL_ENABLE (1 << 0)
37#define TWD_TIMER_CONTROL_ONESHOT (0 << 1)
38#define TWD_TIMER_CONTROL_PERIODIC (1 << 1)
39#define TWD_TIMER_CONTROL_IT_ENABLE (1 << 2)
40
41/* set up by the platform code */
42void __iomem *twd_base;
43
44static unsigned long twd_timer_rate;
45
46static void twd_set_mode(enum clock_event_mode mode,
47 struct clock_event_device *clk)
48{
49 unsigned long ctrl;
50
51 switch (mode) {
52 case CLOCK_EVT_MODE_PERIODIC:
53 /* timer load already set up */
54 ctrl = TWD_TIMER_CONTROL_ENABLE | TWD_TIMER_CONTROL_IT_ENABLE
55 | TWD_TIMER_CONTROL_PERIODIC;
56 break;
57 case CLOCK_EVT_MODE_ONESHOT:
58 /* period set, and timer enabled in 'next_event' hook */
59 ctrl = TWD_TIMER_CONTROL_IT_ENABLE | TWD_TIMER_CONTROL_ONESHOT;
60 break;
61 case CLOCK_EVT_MODE_UNUSED:
62 case CLOCK_EVT_MODE_SHUTDOWN:
63 default:
64 ctrl = 0;
65 }
66
67 __raw_writel(ctrl, twd_base + TWD_TIMER_CONTROL);
68}
69
70static int twd_set_next_event(unsigned long evt,
71 struct clock_event_device *unused)
72{
73 unsigned long ctrl = __raw_readl(twd_base + TWD_TIMER_CONTROL);
74
75 ctrl |= TWD_TIMER_CONTROL_ENABLE;
76
77 __raw_writel(evt, twd_base + TWD_TIMER_COUNTER);
78 __raw_writel(ctrl, twd_base + TWD_TIMER_CONTROL);
79
80 return 0;
81}
82
83/*
84 * local_timer_ack: checks for a local timer interrupt.
85 *
86 * If a local timer interrupt has occurred, acknowledge and return 1.
87 * Otherwise, return 0.
88 */
89int twd_timer_ack(void)
90{
91 if (__raw_readl(twd_base + TWD_TIMER_INTSTAT)) {
92 __raw_writel(1, twd_base + TWD_TIMER_INTSTAT);
93 return 1;
94 }
95
96 return 0;
97}
98
99static void __cpuinit twd_calibrate_rate(void)
100{
101 unsigned long load, count;
102 u64 waitjiffies;
103
104 /*
105 * If this is the first time round, we need to work out how fast
106 * the timer ticks
107 */
108 if (twd_timer_rate == 0) {
109 printk(KERN_INFO "Calibrating local timer... ");
110
111 /* Wait for a tick to start */
112 waitjiffies = get_jiffies_64() + 1;
113
114 while (get_jiffies_64() < waitjiffies)
115 udelay(10);
116
117 /* OK, now the tick has started, let's get the timer going */
118 waitjiffies += 5;
119
120 /* enable, no interrupt or reload */
121 __raw_writel(0x1, twd_base + TWD_TIMER_CONTROL);
122
123 /* maximum value */
124 __raw_writel(0xFFFFFFFFU, twd_base + TWD_TIMER_COUNTER);
125
126 while (get_jiffies_64() < waitjiffies)
127 udelay(10);
128
129 count = __raw_readl(twd_base + TWD_TIMER_COUNTER);
130
131 twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
132
133 printk("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
134 (twd_timer_rate / 100000) % 100);
135 }
136
137 load = twd_timer_rate / HZ;
138
139 __raw_writel(load, twd_base + TWD_TIMER_LOAD);
140}
141
142/*
143 * Setup the local clock events for a CPU.
144 */
145void __cpuinit twd_timer_setup(struct clock_event_device *clk)
146{
147 unsigned long flags;
148
149 twd_calibrate_rate();
150
151 clk->name = "local_timer";
152 clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
153 clk->rating = 350;
154 clk->set_mode = twd_set_mode;
155 clk->set_next_event = twd_set_next_event;
156 clk->shift = 20;
157 clk->mult = div_sc(twd_timer_rate, NSEC_PER_SEC, clk->shift);
158 clk->max_delta_ns = clockevent_delta2ns(0xffffffff, clk);
159 clk->min_delta_ns = clockevent_delta2ns(0xf, clk);
160
161 /* Make sure our local interrupt controller has this enabled */
162 local_irq_save(flags);
163 get_irq_chip(clk->irq)->unmask(clk->irq);
164 local_irq_restore(flags);
165
166 clockevents_register_device(clk);
167}
168
169/*
170 * take a local timer down
171 */
172void __cpuexit twd_timer_stop(void)
173{
174 __raw_writel(0, twd_base + TWD_TIMER_CONTROL);
175}
diff --git a/arch/arm/mach-realview/Makefile b/arch/arm/mach-realview/Makefile
index 7bea8ffc4b59..e13d0947ad0b 100644
--- a/arch/arm/mach-realview/Makefile
+++ b/arch/arm/mach-realview/Makefile
@@ -7,5 +7,6 @@ obj-$(CONFIG_MACH_REALVIEW_EB) += realview_eb.o
7obj-$(CONFIG_MACH_REALVIEW_PB11MP) += realview_pb11mp.o 7obj-$(CONFIG_MACH_REALVIEW_PB11MP) += realview_pb11mp.o
8obj-$(CONFIG_MACH_REALVIEW_PB1176) += realview_pb1176.o 8obj-$(CONFIG_MACH_REALVIEW_PB1176) += realview_pb1176.o
9obj-$(CONFIG_MACH_REALVIEW_PBA8) += realview_pba8.o 9obj-$(CONFIG_MACH_REALVIEW_PBA8) += realview_pba8.o
10obj-$(CONFIG_SMP) += platsmp.o headsmp.o localtimer.o 10obj-$(CONFIG_SMP) += platsmp.o headsmp.o
11obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o 11obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
12obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
diff --git a/arch/arm/mach-realview/core.h b/arch/arm/mach-realview/core.h
index 21c08637683b..59a337ba4be7 100644
--- a/arch/arm/mach-realview/core.h
+++ b/arch/arm/mach-realview/core.h
@@ -51,9 +51,6 @@ extern struct mmc_platform_data realview_mmc0_plat_data;
51extern struct mmc_platform_data realview_mmc1_plat_data; 51extern struct mmc_platform_data realview_mmc1_plat_data;
52extern struct clcd_board clcd_plat_data; 52extern struct clcd_board clcd_plat_data;
53extern void __iomem *gic_cpu_base_addr; 53extern void __iomem *gic_cpu_base_addr;
54#ifdef CONFIG_LOCAL_TIMERS
55extern void __iomem *twd_base;
56#endif
57extern void __iomem *timer0_va_base; 54extern void __iomem *timer0_va_base;
58extern void __iomem *timer1_va_base; 55extern void __iomem *timer1_va_base;
59extern void __iomem *timer2_va_base; 56extern void __iomem *timer2_va_base;
diff --git a/arch/arm/mach-realview/include/mach/scu.h b/arch/arm/mach-realview/include/mach/scu.h
deleted file mode 100644
index d55802d645af..000000000000
--- a/arch/arm/mach-realview/include/mach/scu.h
+++ /dev/null
@@ -1,13 +0,0 @@
1#ifndef __ASMARM_ARCH_SCU_H
2#define __ASMARM_ARCH_SCU_H
3
4/*
5 * SCU registers
6 */
7#define SCU_CTRL 0x00
8#define SCU_CONFIG 0x04
9#define SCU_CPU_STATUS 0x08
10#define SCU_INVALIDATE 0x0c
11#define SCU_FPGA_REVISION 0x10
12
13#endif
diff --git a/arch/arm/mach-realview/localtimer.c b/arch/arm/mach-realview/localtimer.c
index 1c01d13460f0..60b4e111f459 100644
--- a/arch/arm/mach-realview/localtimer.c
+++ b/arch/arm/mach-realview/localtimer.c
@@ -9,196 +9,18 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/delay.h>
14#include <linux/device.h>
15#include <linux/smp.h> 12#include <linux/smp.h>
16#include <linux/jiffies.h>
17#include <linux/percpu.h>
18#include <linux/clockchips.h> 13#include <linux/clockchips.h>
19#include <linux/irq.h>
20#include <linux/io.h>
21 14
22#include <asm/hardware/arm_twd.h>
23#include <asm/hardware/gic.h>
24#include <mach/hardware.h>
25#include <asm/irq.h> 15#include <asm/irq.h>
26 16#include <asm/smp_twd.h>
27static DEFINE_PER_CPU(struct clock_event_device, local_clockevent); 17#include <asm/localtimer.h>
28
29/*
30 * Used on SMP for either the local timer or IPI_TIMER
31 */
32void local_timer_interrupt(void)
33{
34 struct clock_event_device *clk = &__get_cpu_var(local_clockevent);
35
36 clk->event_handler(clk);
37}
38
39#ifdef CONFIG_LOCAL_TIMERS
40
41/* set up by the platform code */
42void __iomem *twd_base;
43
44static unsigned long mpcore_timer_rate;
45
46static void local_timer_set_mode(enum clock_event_mode mode,
47 struct clock_event_device *clk)
48{
49 unsigned long ctrl;
50
51 switch(mode) {
52 case CLOCK_EVT_MODE_PERIODIC:
53 /* timer load already set up */
54 ctrl = TWD_TIMER_CONTROL_ENABLE | TWD_TIMER_CONTROL_IT_ENABLE
55 | TWD_TIMER_CONTROL_PERIODIC;
56 break;
57 case CLOCK_EVT_MODE_ONESHOT:
58 /* period set, and timer enabled in 'next_event' hook */
59 ctrl = TWD_TIMER_CONTROL_IT_ENABLE | TWD_TIMER_CONTROL_ONESHOT;
60 break;
61 case CLOCK_EVT_MODE_UNUSED:
62 case CLOCK_EVT_MODE_SHUTDOWN:
63 default:
64 ctrl = 0;
65 }
66
67 __raw_writel(ctrl, twd_base + TWD_TIMER_CONTROL);
68}
69
70static int local_timer_set_next_event(unsigned long evt,
71 struct clock_event_device *unused)
72{
73 unsigned long ctrl = __raw_readl(twd_base + TWD_TIMER_CONTROL);
74
75 __raw_writel(evt, twd_base + TWD_TIMER_COUNTER);
76 __raw_writel(ctrl | TWD_TIMER_CONTROL_ENABLE, twd_base + TWD_TIMER_CONTROL);
77
78 return 0;
79}
80
81/*
82 * local_timer_ack: checks for a local timer interrupt.
83 *
84 * If a local timer interrupt has occurred, acknowledge and return 1.
85 * Otherwise, return 0.
86 */
87int local_timer_ack(void)
88{
89 if (__raw_readl(twd_base + TWD_TIMER_INTSTAT)) {
90 __raw_writel(1, twd_base + TWD_TIMER_INTSTAT);
91 return 1;
92 }
93
94 return 0;
95}
96
97static void __cpuinit twd_calibrate_rate(void)
98{
99 unsigned long load, count;
100 u64 waitjiffies;
101
102 /*
103 * If this is the first time round, we need to work out how fast
104 * the timer ticks
105 */
106 if (mpcore_timer_rate == 0) {
107 printk("Calibrating local timer... ");
108
109 /* Wait for a tick to start */
110 waitjiffies = get_jiffies_64() + 1;
111
112 while (get_jiffies_64() < waitjiffies)
113 udelay(10);
114
115 /* OK, now the tick has started, let's get the timer going */
116 waitjiffies += 5;
117
118 /* enable, no interrupt or reload */
119 __raw_writel(0x1, twd_base + TWD_TIMER_CONTROL);
120
121 /* maximum value */
122 __raw_writel(0xFFFFFFFFU, twd_base + TWD_TIMER_COUNTER);
123
124 while (get_jiffies_64() < waitjiffies)
125 udelay(10);
126
127 count = __raw_readl(twd_base + TWD_TIMER_COUNTER);
128
129 mpcore_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
130
131 printk("%lu.%02luMHz.\n", mpcore_timer_rate / 1000000,
132 (mpcore_timer_rate / 100000) % 100);
133 }
134
135 load = mpcore_timer_rate / HZ;
136
137 __raw_writel(load, twd_base + TWD_TIMER_LOAD);
138}
139 18
140/* 19/*
141 * Setup the local clock events for a CPU. 20 * Setup the local clock events for a CPU.
142 */ 21 */
143void __cpuinit local_timer_setup(void) 22void __cpuinit local_timer_setup(struct clock_event_device *evt)
144{
145 unsigned int cpu = smp_processor_id();
146 struct clock_event_device *clk = &per_cpu(local_clockevent, cpu);
147 unsigned long flags;
148
149 twd_calibrate_rate();
150
151 clk->name = "local_timer";
152 clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
153 clk->rating = 350;
154 clk->set_mode = local_timer_set_mode;
155 clk->set_next_event = local_timer_set_next_event;
156 clk->irq = IRQ_LOCALTIMER;
157 clk->cpumask = cpumask_of(cpu);
158 clk->shift = 20;
159 clk->mult = div_sc(mpcore_timer_rate, NSEC_PER_SEC, clk->shift);
160 clk->max_delta_ns = clockevent_delta2ns(0xffffffff, clk);
161 clk->min_delta_ns = clockevent_delta2ns(0xf, clk);
162
163 /* Make sure our local interrupt controller has this enabled */
164 local_irq_save(flags);
165 get_irq_chip(IRQ_LOCALTIMER)->unmask(IRQ_LOCALTIMER);
166 local_irq_restore(flags);
167
168 clockevents_register_device(clk);
169}
170
171/*
172 * take a local timer down
173 */
174void __cpuexit local_timer_stop(void)
175{ 23{
176 __raw_writel(0, twd_base + TWD_TIMER_CONTROL); 24 evt->irq = IRQ_LOCALTIMER;
25 twd_timer_setup(evt);
177} 26}
178
179#else /* CONFIG_LOCAL_TIMERS */
180
181static void dummy_timer_set_mode(enum clock_event_mode mode,
182 struct clock_event_device *clk)
183{
184}
185
186void __cpuinit local_timer_setup(void)
187{
188 unsigned int cpu = smp_processor_id();
189 struct clock_event_device *clk = &per_cpu(local_clockevent, cpu);
190
191 clk->name = "dummy_timer";
192 clk->features = CLOCK_EVT_FEAT_ONESHOT |
193 CLOCK_EVT_FEAT_PERIODIC |
194 CLOCK_EVT_FEAT_DUMMY;
195 clk->rating = 400;
196 clk->mult = 1;
197 clk->set_mode = dummy_timer_set_mode;
198 clk->broadcast = smp_timer_broadcast;
199 clk->cpumask = cpumask_of(cpu);
200
201 clockevents_register_device(clk);
202}
203
204#endif /* !CONFIG_LOCAL_TIMERS */
diff --git a/arch/arm/mach-realview/platsmp.c b/arch/arm/mach-realview/platsmp.c
index 30a9c68591f6..ca742172ea78 100644
--- a/arch/arm/mach-realview/platsmp.c
+++ b/arch/arm/mach-realview/platsmp.c
@@ -19,10 +19,11 @@
19#include <asm/cacheflush.h> 19#include <asm/cacheflush.h>
20#include <mach/hardware.h> 20#include <mach/hardware.h>
21#include <asm/mach-types.h> 21#include <asm/mach-types.h>
22#include <asm/localtimer.h>
22 23
23#include <mach/board-eb.h> 24#include <mach/board-eb.h>
24#include <mach/board-pb11mp.h> 25#include <mach/board-pb11mp.h>
25#include <mach/scu.h> 26#include <asm/smp_scu.h>
26 27
27#include "core.h" 28#include "core.h"
28 29
@@ -44,31 +45,12 @@ static void __iomem *scu_base_addr(void)
44 return (void __iomem *)0; 45 return (void __iomem *)0;
45} 46}
46 47
47static unsigned int __init get_core_count(void) 48static inline unsigned int get_core_count(void)
48{ 49{
49 unsigned int ncores;
50 void __iomem *scu_base = scu_base_addr(); 50 void __iomem *scu_base = scu_base_addr();
51 51 if (scu_base)
52 if (scu_base) { 52 return scu_get_core_count(scu_base);
53 ncores = __raw_readl(scu_base + SCU_CONFIG); 53 return 1;
54 ncores = (ncores & 0x03) + 1;
55 } else
56 ncores = 1;
57
58 return ncores;
59}
60
61/*
62 * Setup the SCU
63 */
64static void scu_enable(void)
65{
66 u32 scu_ctrl;
67 void __iomem *scu_base = scu_base_addr();
68
69 scu_ctrl = __raw_readl(scu_base + SCU_CTRL);
70 scu_ctrl |= 1;
71 __raw_writel(scu_ctrl, scu_base + SCU_CTRL);
72} 54}
73 55
74static DEFINE_SPINLOCK(boot_lock); 56static DEFINE_SPINLOCK(boot_lock);
@@ -184,7 +166,7 @@ void __init smp_init_cpus(void)
184 unsigned int i, ncores = get_core_count(); 166 unsigned int i, ncores = get_core_count();
185 167
186 for (i = 0; i < ncores; i++) 168 for (i = 0; i < ncores; i++)
187 cpu_set(i, cpu_possible_map); 169 set_cpu_possible(i, true);
188} 170}
189 171
190void __init smp_prepare_cpus(unsigned int max_cpus) 172void __init smp_prepare_cpus(unsigned int max_cpus)
@@ -217,19 +199,12 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
217 if (max_cpus > ncores) 199 if (max_cpus > ncores)
218 max_cpus = ncores; 200 max_cpus = ncores;
219 201
220#if defined(CONFIG_LOCAL_TIMERS) || defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
221 /*
222 * Enable the local timer or broadcast device for the boot CPU.
223 */
224 local_timer_setup();
225#endif
226
227 /* 202 /*
228 * Initialise the present map, which describes the set of CPUs 203 * Initialise the present map, which describes the set of CPUs
229 * actually populated at the present time. 204 * actually populated at the present time.
230 */ 205 */
231 for (i = 0; i < max_cpus; i++) 206 for (i = 0; i < max_cpus; i++)
232 cpu_set(i, cpu_present_map); 207 set_cpu_present(i, true);
233 208
234 /* 209 /*
235 * Initialise the SCU if there are more than one CPU and let 210 * Initialise the SCU if there are more than one CPU and let
@@ -239,7 +214,13 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
239 * WFI 214 * WFI
240 */ 215 */
241 if (max_cpus > 1) { 216 if (max_cpus > 1) {
242 scu_enable(); 217 /*
218 * Enable the local timer or broadcast device for the
219 * boot CPU, but only if we have more than one CPU.
220 */
221 percpu_timer_setup();
222
223 scu_enable(scu_base_addr());
243 poke_milo(); 224 poke_milo();
244 } 225 }
245} 226}
diff --git a/arch/arm/mach-realview/realview_eb.c b/arch/arm/mach-realview/realview_eb.c
index c20fbef122b3..8dfa44e08a94 100644
--- a/arch/arm/mach-realview/realview_eb.c
+++ b/arch/arm/mach-realview/realview_eb.c
@@ -32,6 +32,7 @@
32#include <asm/hardware/gic.h> 32#include <asm/hardware/gic.h>
33#include <asm/hardware/icst307.h> 33#include <asm/hardware/icst307.h>
34#include <asm/hardware/cache-l2x0.h> 34#include <asm/hardware/cache-l2x0.h>
35#include <asm/localtimer.h>
35 36
36#include <asm/mach/arch.h> 37#include <asm/mach/arch.h>
37#include <asm/mach/map.h> 38#include <asm/mach/map.h>
diff --git a/arch/arm/mach-realview/realview_pb11mp.c b/arch/arm/mach-realview/realview_pb11mp.c
index ea1e60eca359..dc4b16943907 100644
--- a/arch/arm/mach-realview/realview_pb11mp.c
+++ b/arch/arm/mach-realview/realview_pb11mp.c
@@ -32,6 +32,7 @@
32#include <asm/hardware/gic.h> 32#include <asm/hardware/gic.h>
33#include <asm/hardware/icst307.h> 33#include <asm/hardware/icst307.h>
34#include <asm/hardware/cache-l2x0.h> 34#include <asm/hardware/cache-l2x0.h>
35#include <asm/localtimer.h>
35 36
36#include <asm/mach/arch.h> 37#include <asm/mach/arch.h>
37#include <asm/mach/flash.h> 38#include <asm/mach/flash.h>