From abde710ca8776f851e41c3dfe78ad7dcafa26dc9 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Tue, 10 Jan 2012 19:07:28 +0000 Subject: ARM: smp_twd: make local_timer_stop a symbol instead of a #define When CONFIG_HAVE_ARM_TWD is selected, local_timer_stop is a #define, while all other local timers are using a real function. Convert it to an alias of twd_timer_stop, as it helps converting all local timers to another internal API in a sane way. Signed-off-by: Marc Zyngier --- arch/arm/kernel/smp_twd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'arch/arm/kernel') diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index 4285daa077b0..b39916ad31c2 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c @@ -87,12 +87,17 @@ int twd_timer_ack(void) return 0; } -void twd_timer_stop(struct clock_event_device *clk) +static void twd_timer_stop(struct clock_event_device *clk) { twd_set_mode(CLOCK_EVT_MODE_UNUSED, clk); disable_percpu_irq(clk->irq); } +/* Temporary hack to be removed when all TWD users are converted to + the new registration interface */ +void local_timer_stop(struct clock_event_device *clk) + __attribute__ ((alias ("twd_timer_stop"))); + #ifdef CONFIG_CPU_FREQ /* -- cgit v1.2.1 From 0ef330e10dcdbca8f4566e9eaf77015f8ce039d3 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Tue, 10 Jan 2012 19:26:45 +0000 Subject: ARM: local timers: introduce a new registration interface In order to switch to a runtime selectable local timer, add a registration interface that timer drivers can use to register to the core. local_timer_setup() and local_timer_stop() are made weak symbols in order not to break existing setups. Signed-off-by: Marc Zyngier --- arch/arm/kernel/smp.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'arch/arm/kernel') diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index cdeb727527d3..89bb02c90ae1 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -459,6 +459,33 @@ static void __cpuinit broadcast_timer_setup(struct clock_event_device *evt) clockevents_register_device(evt); } +static struct local_timer_ops *lt_ops; + +#ifdef CONFIG_LOCAL_TIMERS +int local_timer_register(struct local_timer_ops *ops) +{ + if (lt_ops) + return -EBUSY; + + lt_ops = ops; + return 0; +} +#endif + +int __cpuinit __attribute__ ((weak)) local_timer_setup(struct clock_event_device *clk) +{ + if (lt_ops) + return lt_ops->setup(clk); + + return -ENXIO; +} + +void __attribute__ ((weak)) local_timer_stop(struct clock_event_device *clk) +{ + if (lt_ops) + lt_ops->stop(clk); +} + void __cpuinit percpu_timer_setup(void) { unsigned int cpu = smp_processor_id(); -- cgit v1.2.1 From 81e46f7b6dcec485bcb1f988ba4dc5b20189573c Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Tue, 10 Jan 2012 19:39:26 +0000 Subject: ARM: smp_twd: add runtime registration support Add support for the new registration interface to smp_twd. Platforms can populate a struct twd_local_timer with MMIO and IRQ resources, and then call twd_local_timer_register() to have the timer registered with the core. Signed-off-by: Marc Zyngier --- arch/arm/kernel/smp_twd.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'arch/arm/kernel') diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index b39916ad31c2..18c55f1e4e48 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c @@ -32,6 +32,7 @@ static struct clk *twd_clk; static unsigned long twd_timer_rate; static struct clock_event_device __percpu **twd_evt; +static int twd_ppi; static void twd_set_mode(enum clock_event_mode mode, struct clock_event_device *clk) @@ -227,7 +228,7 @@ static struct clk *twd_get_clock(void) /* * Setup the local clock events for a CPU. */ -void __cpuinit twd_timer_setup(struct clock_event_device *clk) +int __cpuinit twd_timer_setup(struct clock_event_device *clk) { struct clock_event_device **this_cpu_clk; @@ -237,7 +238,7 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk) twd_evt = alloc_percpu(struct clock_event_device *); if (!twd_evt) { pr_err("twd: can't allocate memory\n"); - return; + return -ENOMEM; } err = request_percpu_irq(clk->irq, twd_handler, @@ -245,7 +246,7 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk) if (err) { pr_err("twd: can't register interrupt %d (%d)\n", clk->irq, err); - return; + return err; } } @@ -265,6 +266,8 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk) clk->rating = 350; clk->set_mode = twd_set_mode; clk->set_next_event = twd_set_next_event; + if (!clk->irq) + clk->irq = twd_ppi; this_cpu_clk = __this_cpu_ptr(twd_evt); *this_cpu_clk = clk; @@ -272,4 +275,46 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk) clockevents_config_and_register(clk, twd_timer_rate, 0xf, 0xffffffff); enable_percpu_irq(clk->irq, 0); + + return 0; +} + +static struct local_timer_ops twd_lt_ops __cpuinitdata = { + .setup = twd_timer_setup, + .stop = twd_timer_stop, +}; + +int __init twd_local_timer_register(struct twd_local_timer *tlt) +{ + int err; + + if (twd_base || twd_evt) + return -EBUSY; + + twd_ppi = tlt->res[1].start; + + twd_evt = alloc_percpu(struct clock_event_device *); + twd_base = ioremap(tlt->res[0].start, resource_size(&tlt->res[0])); + if (!twd_base || !twd_evt) { + err = -ENOMEM; + goto out; + } + + err = request_percpu_irq(twd_ppi, twd_handler, "twd", twd_evt); + if (err) { + pr_err("twd: can't register interrupt %d (%d)\n", twd_ppi, err); + goto out; + } + + err = local_timer_register(&twd_lt_ops); + if (err) + goto out; + + return 0; + +out: + iounmap(twd_base); + free_percpu(twd_evt); + twd_base = twd_evt = NULL; + return err; } -- cgit v1.2.1 From d8e0364364d333feb4564bb7d7d983182b34427e Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Tue, 10 Jan 2012 22:15:45 +0000 Subject: ARM: smp_twd: add device tree support Add bindings to support DT discovery of the ARM Timer Watchdog (aka TWD). Only the timer side is converted by this patch. Acked-by: Rob Herring Signed-off-by: Marc Zyngier --- arch/arm/kernel/smp_twd.c | 77 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 13 deletions(-) (limited to 'arch/arm/kernel') diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index 18c55f1e4e48..761826c628b1 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -284,37 +286,86 @@ static struct local_timer_ops twd_lt_ops __cpuinitdata = { .stop = twd_timer_stop, }; -int __init twd_local_timer_register(struct twd_local_timer *tlt) +static int __init twd_local_timer_common_register(void) { int err; - if (twd_base || twd_evt) - return -EBUSY; - - twd_ppi = tlt->res[1].start; - twd_evt = alloc_percpu(struct clock_event_device *); - twd_base = ioremap(tlt->res[0].start, resource_size(&tlt->res[0])); - if (!twd_base || !twd_evt) { + if (!twd_evt) { err = -ENOMEM; - goto out; + goto out_free; } err = request_percpu_irq(twd_ppi, twd_handler, "twd", twd_evt); if (err) { pr_err("twd: can't register interrupt %d (%d)\n", twd_ppi, err); - goto out; + goto out_free; } err = local_timer_register(&twd_lt_ops); if (err) - goto out; + goto out_irq; return 0; -out: +out_irq: + free_percpu_irq(twd_ppi, twd_evt); +out_free: iounmap(twd_base); + twd_base = NULL; free_percpu(twd_evt); - twd_base = twd_evt = NULL; + return err; } + +int __init twd_local_timer_register(struct twd_local_timer *tlt) +{ + if (twd_base || twd_evt) + return -EBUSY; + + twd_ppi = tlt->res[1].start; + + twd_base = ioremap(tlt->res[0].start, resource_size(&tlt->res[0])); + if (!twd_base) + return -ENOMEM; + + return twd_local_timer_common_register(); +} + +#ifdef CONFIG_OF +const static struct of_device_id twd_of_match[] __initconst = { + { .compatible = "arm,cortex-a9-twd-timer", }, + { .compatible = "arm,cortex-a5-twd-timer", }, + { .compatible = "arm,arm11mp-twd-timer", }, + { }, +}; + +void __init twd_local_timer_of_register(void) +{ + struct device_node *np; + int err; + + np = of_find_matching_node(NULL, twd_of_match); + if (!np) { + err = -ENODEV; + goto out; + } + + twd_ppi = irq_of_parse_and_map(np, 0); + if (!twd_ppi) { + err = -EINVAL; + goto out; + } + + twd_base = of_iomap(np, 0); + if (!twd_base) { + err = -ENOMEM; + goto out; + } + + err = twd_local_timer_common_register(); + +out: + WARN(err, "twd_local_timer_of_register failed (%d)\n", err); +} +#endif -- cgit v1.2.1 From 9248510469b46bc17b90cf62cb8d9e7c9a5f9965 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Tue, 10 Jan 2012 23:00:54 +0000 Subject: ARM: smp_twd: remove old local timer interface Now that all users of the previous local timer interface have been converted to the runtime registration API, make this interface the only one supported for this driver. Signed-off-by: Marc Zyngier --- arch/arm/kernel/smp_twd.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'arch/arm/kernel') diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index 761826c628b1..a622e7a8b121 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -28,7 +28,7 @@ #include /* set up by the platform code */ -void __iomem *twd_base; +static void __iomem *twd_base; static struct clk *twd_clk; static unsigned long twd_timer_rate; @@ -80,7 +80,7 @@ static int twd_set_next_event(unsigned long evt, * If a local timer interrupt has occurred, acknowledge and return 1. * Otherwise, return 0. */ -int twd_timer_ack(void) +static int twd_timer_ack(void) { if (__raw_readl(twd_base + TWD_TIMER_INTSTAT)) { __raw_writel(1, twd_base + TWD_TIMER_INTSTAT); @@ -96,11 +96,6 @@ static void twd_timer_stop(struct clock_event_device *clk) disable_percpu_irq(clk->irq); } -/* Temporary hack to be removed when all TWD users are converted to - the new registration interface */ -void local_timer_stop(struct clock_event_device *clk) - __attribute__ ((alias ("twd_timer_stop"))); - #ifdef CONFIG_CPU_FREQ /* @@ -230,28 +225,10 @@ static struct clk *twd_get_clock(void) /* * Setup the local clock events for a CPU. */ -int __cpuinit twd_timer_setup(struct clock_event_device *clk) +static int __cpuinit twd_timer_setup(struct clock_event_device *clk) { struct clock_event_device **this_cpu_clk; - if (!twd_evt) { - int err; - - twd_evt = alloc_percpu(struct clock_event_device *); - if (!twd_evt) { - pr_err("twd: can't allocate memory\n"); - return -ENOMEM; - } - - err = request_percpu_irq(clk->irq, twd_handler, - "twd", twd_evt); - if (err) { - pr_err("twd: can't register interrupt %d (%d)\n", - clk->irq, err); - return err; - } - } - if (!twd_clk) twd_clk = twd_get_clock(); @@ -268,8 +245,7 @@ int __cpuinit twd_timer_setup(struct clock_event_device *clk) clk->rating = 350; clk->set_mode = twd_set_mode; clk->set_next_event = twd_set_next_event; - if (!clk->irq) - clk->irq = twd_ppi; + clk->irq = twd_ppi; this_cpu_clk = __this_cpu_ptr(twd_evt); *this_cpu_clk = clk; -- cgit v1.2.1 From d45785929f1248d2e769f959f180f0504e326622 Mon Sep 17 00:00:00 2001 From: Marc Zyngier Date: Tue, 10 Jan 2012 23:38:25 +0000 Subject: ARM: local timers: make the runtime registration interface mandatory Remove all traces of the compile-time local timer interface, and make the runtime selection mandatory. Signed-off-by: Marc Zyngier --- arch/arm/kernel/smp.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'arch/arm/kernel') diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 89bb02c90ae1..1ad84a6c9bfb 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -246,6 +246,8 @@ static void __cpuinit smp_store_cpu_info(unsigned int cpuid) store_cpu_topology(cpuid); } +static void percpu_timer_setup(void); + /* * This is the secondary CPU boot entry. We're using this CPUs * idle thread stack, but a set of temporary page tables. @@ -472,21 +474,7 @@ int local_timer_register(struct local_timer_ops *ops) } #endif -int __cpuinit __attribute__ ((weak)) local_timer_setup(struct clock_event_device *clk) -{ - if (lt_ops) - return lt_ops->setup(clk); - - return -ENXIO; -} - -void __attribute__ ((weak)) local_timer_stop(struct clock_event_device *clk) -{ - if (lt_ops) - lt_ops->stop(clk); -} - -void __cpuinit percpu_timer_setup(void) +static void __cpuinit percpu_timer_setup(void) { unsigned int cpu = smp_processor_id(); struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu); @@ -494,7 +482,7 @@ void __cpuinit percpu_timer_setup(void) evt->cpumask = cpumask_of(cpu); evt->broadcast = smp_timer_broadcast; - if (local_timer_setup(evt)) + if (!lt_ops || lt_ops->setup(evt)) broadcast_timer_setup(evt); } @@ -509,7 +497,8 @@ static void percpu_timer_stop(void) unsigned int cpu = smp_processor_id(); struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu); - local_timer_stop(evt); + if (lt_ops) + lt_ops->stop(evt); } #endif -- cgit v1.2.1