mm: Add range_cont mode for writeback
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / um / kernel / time.c
blobc3e2f369c33cae2af0c682eb5a9a32a03781e056
1 /*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <linux/clockchips.h>
7 #include <linux/init.h>
8 #include <linux/interrupt.h>
9 #include <linux/jiffies.h>
10 #include <linux/threads.h>
11 #include <asm/irq.h>
12 #include <asm/param.h>
13 #include "kern_util.h"
14 #include "os.h"
17 * Scheduler clock - returns current time in nanosec units.
19 unsigned long long sched_clock(void)
21 return (unsigned long long)jiffies_64 * (NSEC_PER_SEC / HZ);
24 void timer_handler(int sig, struct uml_pt_regs *regs)
26 unsigned long flags;
28 local_irq_save(flags);
29 do_IRQ(TIMER_IRQ, regs);
30 local_irq_restore(flags);
33 static void itimer_set_mode(enum clock_event_mode mode,
34 struct clock_event_device *evt)
36 switch (mode) {
37 case CLOCK_EVT_MODE_PERIODIC:
38 set_interval();
39 break;
41 case CLOCK_EVT_MODE_SHUTDOWN:
42 case CLOCK_EVT_MODE_UNUSED:
43 case CLOCK_EVT_MODE_ONESHOT:
44 disable_timer();
45 break;
47 case CLOCK_EVT_MODE_RESUME:
48 break;
52 static int itimer_next_event(unsigned long delta,
53 struct clock_event_device *evt)
55 return timer_one_shot(delta + 1);
58 static struct clock_event_device itimer_clockevent = {
59 .name = "itimer",
60 .rating = 250,
61 .cpumask = CPU_MASK_ALL,
62 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
63 .set_mode = itimer_set_mode,
64 .set_next_event = itimer_next_event,
65 .shift = 32,
66 .irq = 0,
69 static irqreturn_t um_timer(int irq, void *dev)
71 (*itimer_clockevent.event_handler)(&itimer_clockevent);
73 return IRQ_HANDLED;
76 static cycle_t itimer_read(void)
78 return os_nsecs() / 1000;
81 static struct clocksource itimer_clocksource = {
82 .name = "itimer",
83 .rating = 300,
84 .read = itimer_read,
85 .mask = CLOCKSOURCE_MASK(64),
86 .mult = 1000,
87 .shift = 0,
88 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
91 static void __init setup_itimer(void)
93 int err;
95 err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL);
96 if (err != 0)
97 printk(KERN_ERR "register_timer : request_irq failed - "
98 "errno = %d\n", -err);
100 itimer_clockevent.mult = div_sc(HZ, NSEC_PER_SEC, 32);
101 itimer_clockevent.max_delta_ns =
102 clockevent_delta2ns(60 * HZ, &itimer_clockevent);
103 itimer_clockevent.min_delta_ns =
104 clockevent_delta2ns(1, &itimer_clockevent);
105 err = clocksource_register(&itimer_clocksource);
106 if (err) {
107 printk(KERN_ERR "clocksource_register returned %d\n", err);
108 return;
110 clockevents_register_device(&itimer_clockevent);
113 void __init time_init(void)
115 long long nsecs;
117 timer_init();
119 nsecs = os_nsecs();
120 set_normalized_timespec(&wall_to_monotonic, -nsecs / NSEC_PER_SEC,
121 -nsecs % NSEC_PER_SEC);
122 set_normalized_timespec(&xtime, nsecs / NSEC_PER_SEC,
123 nsecs % NSEC_PER_SEC);
124 late_time_init = setup_itimer;