mwifiex: Fix memory corruption in dump_station
[linux/fpc-iii.git] / arch / mips / sgi-ip27 / ip27-timer.c
blob61f3565f3645a7a311a75c22d6ce0e91fda67615
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copytight (C) 1999, 2000, 05, 06 Ralf Baechle (ralf@linux-mips.org)
4 * Copytight (C) 1999, 2000 Silicon Graphics, Inc.
5 */
6 #include <linux/bcd.h>
7 #include <linux/clockchips.h>
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/sched_clock.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
14 #include <linux/param.h>
15 #include <linux/smp.h>
16 #include <linux/time.h>
17 #include <linux/timex.h>
18 #include <linux/mm.h>
19 #include <linux/platform_device.h>
21 #include <asm/time.h>
22 #include <asm/pgtable.h>
23 #include <asm/sgialib.h>
24 #include <asm/sn/ioc3.h>
25 #include <asm/sn/klconfig.h>
26 #include <asm/sn/arch.h>
27 #include <asm/sn/addrs.h>
28 #include <asm/sn/agent.h>
30 #include "ip27-common.h"
32 #define TICK_SIZE (tick_nsec / 1000)
34 /* Includes for ioc3_init(). */
35 #include <asm/sn/types.h>
36 #include <asm/pci/bridge.h>
38 #include "ip27-common.h"
40 static int rt_next_event(unsigned long delta, struct clock_event_device *evt)
42 unsigned int cpu = smp_processor_id();
43 int slice = cputoslice(cpu);
44 unsigned long cnt;
46 cnt = LOCAL_HUB_L(PI_RT_COUNT);
47 cnt += delta;
48 LOCAL_HUB_S(PI_RT_COMPARE_A + PI_COUNT_OFFSET * slice, cnt);
50 return LOCAL_HUB_L(PI_RT_COUNT) >= cnt ? -ETIME : 0;
53 static DEFINE_PER_CPU(struct clock_event_device, hub_rt_clockevent);
54 static DEFINE_PER_CPU(char [11], hub_rt_name);
56 static irqreturn_t hub_rt_counter_handler(int irq, void *dev_id)
58 unsigned int cpu = smp_processor_id();
59 struct clock_event_device *cd = &per_cpu(hub_rt_clockevent, cpu);
60 int slice = cputoslice(cpu);
63 * Ack
65 LOCAL_HUB_S(PI_RT_PEND_A + PI_COUNT_OFFSET * slice, 0);
66 cd->event_handler(cd);
68 return IRQ_HANDLED;
71 struct irqaction hub_rt_irqaction = {
72 .handler = hub_rt_counter_handler,
73 .percpu_dev_id = &hub_rt_clockevent,
74 .flags = IRQF_PERCPU | IRQF_TIMER,
75 .name = "hub-rt",
79 * This is a hack; we really need to figure these values out dynamically
81 * Since 800 ns works very well with various HUB frequencies, such as
82 * 360, 380, 390 and 400 MHZ, we use 800 ns rtc cycle time.
84 * Ralf: which clock rate is used to feed the counter?
86 #define NSEC_PER_CYCLE 800
87 #define CYCLES_PER_SEC (NSEC_PER_SEC / NSEC_PER_CYCLE)
89 void hub_rt_clock_event_init(void)
91 unsigned int cpu = smp_processor_id();
92 struct clock_event_device *cd = &per_cpu(hub_rt_clockevent, cpu);
93 unsigned char *name = per_cpu(hub_rt_name, cpu);
95 sprintf(name, "hub-rt %d", cpu);
96 cd->name = name;
97 cd->features = CLOCK_EVT_FEAT_ONESHOT;
98 clockevent_set_clock(cd, CYCLES_PER_SEC);
99 cd->max_delta_ns = clockevent_delta2ns(0xfffffffffffff, cd);
100 cd->max_delta_ticks = 0xfffffffffffff;
101 cd->min_delta_ns = clockevent_delta2ns(0x300, cd);
102 cd->min_delta_ticks = 0x300;
103 cd->rating = 200;
104 cd->irq = IP27_RT_TIMER_IRQ;
105 cd->cpumask = cpumask_of(cpu);
106 cd->set_next_event = rt_next_event;
107 clockevents_register_device(cd);
109 enable_percpu_irq(IP27_RT_TIMER_IRQ, IRQ_TYPE_NONE);
112 static void __init hub_rt_clock_event_global_init(void)
114 irq_set_handler(IP27_RT_TIMER_IRQ, handle_percpu_devid_irq);
115 irq_set_percpu_devid(IP27_RT_TIMER_IRQ);
116 setup_percpu_irq(IP27_RT_TIMER_IRQ, &hub_rt_irqaction);
119 static u64 hub_rt_read(struct clocksource *cs)
121 return REMOTE_HUB_L(cputonasid(0), PI_RT_COUNT);
124 struct clocksource hub_rt_clocksource = {
125 .name = "HUB-RT",
126 .rating = 200,
127 .read = hub_rt_read,
128 .mask = CLOCKSOURCE_MASK(52),
129 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
132 static u64 notrace hub_rt_read_sched_clock(void)
134 return REMOTE_HUB_L(cputonasid(0), PI_RT_COUNT);
137 static void __init hub_rt_clocksource_init(void)
139 struct clocksource *cs = &hub_rt_clocksource;
141 clocksource_register_hz(cs, CYCLES_PER_SEC);
143 sched_clock_register(hub_rt_read_sched_clock, 52, CYCLES_PER_SEC);
146 void __init plat_time_init(void)
148 hub_rt_clocksource_init();
149 hub_rt_clock_event_global_init();
150 hub_rt_clock_event_init();
153 void hub_rtc_init(nasid_t nasid)
157 * We only need to initialize the current node.
158 * If this is not the current node then it is a cpuless
159 * node and timeouts will not happen there.
161 if (get_nasid() == nasid) {
162 LOCAL_HUB_S(PI_RT_EN_A, 1);
163 LOCAL_HUB_S(PI_RT_EN_B, 1);
164 LOCAL_HUB_S(PI_PROF_EN_A, 0);
165 LOCAL_HUB_S(PI_PROF_EN_B, 0);
166 LOCAL_HUB_S(PI_RT_COUNT, 0);
167 LOCAL_HUB_S(PI_RT_PEND_A, 0);
168 LOCAL_HUB_S(PI_RT_PEND_B, 0);