OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [s390x/] [kernel/] [time.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  arch/s390/kernel/time.c
3
 *
4
 *  S390 version
5
 *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
6
 *    Author(s): Hartmut Penner (hp@de.ibm.com),
7
 *               Martin Schwidefsky (schwidefsky@de.ibm.com),
8
 *               Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
9
 *
10
 *  Derived from "arch/i386/kernel/time.c"
11
 *    Copyright (C) 1991, 1992, 1995  Linus Torvalds
12
 */
13
 
14
#include <linux/errno.h>
15
#include <linux/sched.h>
16
#include <linux/kernel.h>
17
#include <linux/param.h>
18
#include <linux/string.h>
19
#include <linux/mm.h>
20
#include <linux/interrupt.h>
21
#include <linux/time.h>
22
#include <linux/delay.h>
23
#include <linux/init.h>
24
#include <linux/smp.h>
25
#include <linux/types.h>
26
 
27
#include <asm/uaccess.h>
28
#include <asm/delay.h>
29
 
30
#include <linux/timex.h>
31
#include <linux/config.h>
32
 
33
#include <asm/irq.h>
34
#include <asm/s390_ext.h>
35
 
36
/* change this if you have some constant time drift */
37
#define USECS_PER_JIFFY     ((unsigned long) 1000000/HZ)
38
#define CLK_TICKS_PER_JIFFY ((unsigned long) USECS_PER_JIFFY << 12)
39
 
40
#define TICK_SIZE tick
41
 
42
static ext_int_info_t ext_int_info_timer;
43
static uint64_t init_timer_cc;
44
 
45
extern rwlock_t xtime_lock;
46
extern unsigned long wall_jiffies;
47
 
48
void tod_to_timeval(__u64 todval, struct timeval *xtime)
49
{
50
        todval >>= 12;
51
        xtime->tv_sec = todval / 1000000;
52
        xtime->tv_usec = todval % 1000000;
53
}
54
 
55
static inline unsigned long do_gettimeoffset(void)
56
{
57
        __u64 now;
58
 
59
        asm ("STCK 0(%0)" : : "a" (&now) : "memory", "cc");
60
        now = (now - init_timer_cc) >> 12;
61
        /* We require the offset from the latest update of xtime */
62
        now -= (__u64) wall_jiffies*USECS_PER_JIFFY;
63
        return (unsigned long) now;
64
}
65
 
66
/*
67
 * This version of gettimeofday has microsecond resolution.
68
 */
69
void do_gettimeofday(struct timeval *tv)
70
{
71
        unsigned long flags;
72
        unsigned long usec, sec;
73
 
74
        read_lock_irqsave(&xtime_lock, flags);
75
        sec = xtime.tv_sec;
76
        usec = xtime.tv_usec + do_gettimeoffset();
77
        read_unlock_irqrestore(&xtime_lock, flags);
78
 
79
        while (usec >= 1000000) {
80
                usec -= 1000000;
81
                sec++;
82
        }
83
 
84
        tv->tv_sec = sec;
85
        tv->tv_usec = usec;
86
}
87
 
88
void do_settimeofday(struct timeval *tv)
89
{
90
 
91
        write_lock_irq(&xtime_lock);
92
        /* This is revolting. We need to set the xtime.tv_usec
93
         * correctly. However, the value in this location is
94
         * is value at the last tick.
95
         * Discover what correction gettimeofday
96
         * would have done, and then undo it!
97
         */
98
        tv->tv_usec -= do_gettimeoffset();
99
 
100
        while (tv->tv_usec < 0) {
101
                tv->tv_usec += 1000000;
102
                tv->tv_sec--;
103
        }
104
 
105
        xtime = *tv;
106
        time_adjust = 0;         /* stop active adjtime() */
107
        time_status |= STA_UNSYNC;
108
        time_maxerror = NTP_PHASE_LIMIT;
109
        time_esterror = NTP_PHASE_LIMIT;
110
        write_unlock_irq(&xtime_lock);
111
}
112
 
113
/*
114
 * timer_interrupt() needs to keep up the real-time clock,
115
 * as well as call the "do_timer()" routine every clocktick
116
 */
117
 
118
#ifdef CONFIG_SMP
119
extern __u16 boot_cpu_addr;
120
#endif
121
 
122
static void do_comparator_interrupt(struct pt_regs *regs, __u16 error_code)
123
{
124
        int cpu = smp_processor_id();
125
 
126
        irq_enter(cpu, 0);
127
 
128
        /*
129
         * set clock comparator for next tick
130
         */
131
        S390_lowcore.jiffy_timer += CLK_TICKS_PER_JIFFY;
132
        asm volatile ("SCKC %0" : : "m" (S390_lowcore.jiffy_timer));
133
 
134
#ifdef CONFIG_SMP
135
        if (S390_lowcore.cpu_data.cpu_addr == boot_cpu_addr)
136
                write_lock(&xtime_lock);
137
 
138
        update_process_times(user_mode(regs));
139
 
140
        if (S390_lowcore.cpu_data.cpu_addr == boot_cpu_addr) {
141
                do_timer(regs);
142
                write_unlock(&xtime_lock);
143
        }
144
#else
145
        do_timer(regs);
146
#endif
147
 
148
        irq_exit(cpu, 0);
149
}
150
 
151
/*
152
 * Start the clock comparator on the current CPU
153
 */
154
void init_cpu_timer(void)
155
{
156
        unsigned long cr0;
157
 
158
        S390_lowcore.jiffy_timer = (__u64) jiffies * CLK_TICKS_PER_JIFFY;
159
        S390_lowcore.jiffy_timer += init_timer_cc + CLK_TICKS_PER_JIFFY;
160
        asm volatile ("SCKC %0" : : "m" (S390_lowcore.jiffy_timer));
161
        /* allow clock comparator timer interrupt */
162
        asm volatile ("STCTG 0,0,%0" : "=m" (cr0) : : "memory");
163
        cr0 |= 0x800;
164
        asm volatile ("LCTLG 0,0,%0" : : "m" (cr0) : "memory");
165
}
166
 
167
/*
168
 * Initialize the TOD clock and the CPU timer of
169
 * the boot cpu.
170
 */
171
void __init time_init(void)
172
{
173
        __u64 set_time_cc;
174
        int cc;
175
 
176
        /* kick the TOD clock */
177
        asm volatile ("STCK 0(%1)\n\t"
178
                      "IPM  %0\n\t"
179
                      "SRL  %0,28" : "=r" (cc) : "a" (&init_timer_cc)
180
                                   : "memory", "cc");
181
        switch (cc) {
182
        case 0: /* clock in set state: all is fine */
183
                break;
184
        case 1: /* clock in non-set state: FIXME */
185
                printk("time_init: TOD clock in non-set state\n");
186
                break;
187
        case 2: /* clock in error state: FIXME */
188
                printk("time_init: TOD clock in error state\n");
189
                break;
190
        case 3: /* clock in stopped or not-operational state: FIXME */
191
                printk("time_init: TOD clock stopped/non-operational\n");
192
                break;
193
        }
194
 
195
        /* set xtime */
196
        set_time_cc = init_timer_cc - 0x8126d60e46000000LL +
197
                      (0x3c26700LL*1000000*4096);
198
        tod_to_timeval(set_time_cc, &xtime);
199
 
200
        /* request the 0x1004 external interrupt */
201
        if (register_early_external_interrupt(0x1004, do_comparator_interrupt,
202
                                              &ext_int_info_timer) != 0)
203
                panic("Couldn't request external interrupt 0x1004");
204
 
205
        /* init CPU timer */
206
        init_cpu_timer();
207
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.