This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / sh64 / kernel / time.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * arch/sh64/kernel/time.c
7  *
8  * Copyright (C) 2000, 2001  Paolo Alberelli
9  * Copyright (C) 2003, 2004  Paul Mundt
10  * Copyright (C) 2003  Richard Curnow
11  *
12  *    Original TMU/RTC code taken from sh version.
13  *    Copyright (C) 1999  Tetsuya Okada & Niibe Yutaka
14  *      Some code taken from i386 version.
15  *      Copyright (C) 1991, 1992, 1995  Linus Torvalds
16  */
17
18 #include <linux/config.h>
19 #include <linux/errno.h>
20 #include <linux/rwsem.h>
21 #include <linux/sched.h>
22 #include <linux/kernel.h>
23 #include <linux/param.h>
24 #include <linux/string.h>
25 #include <linux/mm.h>
26 #include <linux/interrupt.h>
27 #include <linux/time.h>
28 #include <linux/delay.h>
29 #include <linux/init.h>
30 #include <linux/profile.h>
31 #include <linux/smp.h>
32
33 #include <asm/registers.h>       /* required by inline __asm__ stmt. */
34
35 #include <asm/processor.h>
36 #include <asm/uaccess.h>
37 #include <asm/io.h>
38 #include <asm/irq.h>
39 #include <asm/delay.h>
40
41 #include <linux/timex.h>
42 #include <linux/irq.h>
43 #include <asm/hardware.h>
44
45 #define TMU_TOCR_INIT   0x00
46 #define TMU0_TCR_INIT   0x0020
47 #define TMU_TSTR_INIT   1
48
49 /* RCR1 Bits */
50 #define RCR1_CF         0x80    /* Carry Flag             */
51 #define RCR1_CIE        0x10    /* Carry Interrupt Enable */
52 #define RCR1_AIE        0x08    /* Alarm Interrupt Enable */
53 #define RCR1_AF         0x01    /* Alarm Flag             */
54
55 /* RCR2 Bits */
56 #define RCR2_PEF        0x80    /* PEriodic interrupt Flag */
57 #define RCR2_PESMASK    0x70    /* Periodic interrupt Set  */
58 #define RCR2_RTCEN      0x08    /* ENable RTC              */
59 #define RCR2_ADJ        0x04    /* ADJustment (30-second)  */
60 #define RCR2_RESET      0x02    /* Reset bit               */
61 #define RCR2_START      0x01    /* Start bit               */
62
63 /* Clock, Power and Reset Controller */
64 #define CPRC_BLOCK_OFF  0x01010000
65 #define CPRC_BASE       PHYS_PERIPHERAL_BLOCK + CPRC_BLOCK_OFF
66
67 #define FRQCR           (cprc_base+0x0)
68 #define WTCSR           (cprc_base+0x0018)
69 #define STBCR           (cprc_base+0x0030)
70
71 /* Time Management Unit */
72 #define TMU_BLOCK_OFF   0x01020000
73 #define TMU_BASE        PHYS_PERIPHERAL_BLOCK + TMU_BLOCK_OFF
74 #define TMU0_BASE       tmu_base + 0x8 + (0xc * 0x0)
75 #define TMU1_BASE       tmu_base + 0x8 + (0xc * 0x1)
76 #define TMU2_BASE       tmu_base + 0x8 + (0xc * 0x2)
77
78 #define TMU_TOCR        tmu_base+0x0    /* Byte access */
79 #define TMU_TSTR        tmu_base+0x4    /* Byte access */
80
81 #define TMU0_TCOR       TMU0_BASE+0x0   /* Long access */
82 #define TMU0_TCNT       TMU0_BASE+0x4   /* Long access */
83 #define TMU0_TCR        TMU0_BASE+0x8   /* Word access */
84
85 /* Real Time Clock */
86 #define RTC_BLOCK_OFF   0x01040000
87 #define RTC_BASE        PHYS_PERIPHERAL_BLOCK + RTC_BLOCK_OFF
88
89 #define R64CNT          rtc_base+0x00
90 #define RSECCNT         rtc_base+0x04
91 #define RMINCNT         rtc_base+0x08
92 #define RHRCNT          rtc_base+0x0c
93 #define RWKCNT          rtc_base+0x10
94 #define RDAYCNT         rtc_base+0x14
95 #define RMONCNT         rtc_base+0x18
96 #define RYRCNT          rtc_base+0x1c   /* 16bit */
97 #define RSECAR          rtc_base+0x20
98 #define RMINAR          rtc_base+0x24
99 #define RHRAR           rtc_base+0x28
100 #define RWKAR           rtc_base+0x2c
101 #define RDAYAR          rtc_base+0x30
102 #define RMONAR          rtc_base+0x34
103 #define RCR1            rtc_base+0x38
104 #define RCR2            rtc_base+0x3c
105
106 #ifndef BCD_TO_BIN
107 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
108 #endif
109
110 #ifndef BIN_TO_BCD
111 #define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
112 #endif
113
114 #define TICK_SIZE (tick_nsec / 1000)
115
116 extern unsigned long wall_jiffies;
117
118 u64 jiffies_64 = INITIAL_JIFFIES;
119
120 static unsigned long tmu_base, rtc_base;
121 unsigned long cprc_base;
122
123 /* Variables to allow interpolation of time of day to resolution better than a
124  * jiffy. */
125
126 /* This is effectively protected by xtime_lock */
127 static unsigned long ctc_last_interrupt;
128 static unsigned long long usecs_per_jiffy = 1000000/HZ; /* Approximation */
129
130 #define CTC_JIFFY_SCALE_SHIFT 40
131
132 /* 2**CTC_JIFFY_SCALE_SHIFT / ctc_ticks_per_jiffy */
133 static unsigned long long scaled_recip_ctc_ticks_per_jiffy;
134
135 /* Estimate number of microseconds that have elapsed since the last timer tick,
136    by scaling the delta that has occured in the CTC register.
137
138    WARNING WARNING WARNING : This algorithm relies on the CTC decrementing at
139    the CPU clock rate.  If the CPU sleeps, the CTC stops counting.  Bear this
140    in mind if enabling SLEEP_WORKS in process.c.  In that case, this algorithm
141    probably needs to use TMU.TCNT0 instead.  This will work even if the CPU is
142    sleeping, though will be coarser.
143
144    FIXME : What if usecs_per_tick is moving around too much, e.g. if an adjtime
145    is running or if the freq or tick arguments of adjtimex are modified after
146    we have calibrated the scaling factor?  This will result in either a jump at
147    the end of a tick period, or a wrap backwards at the start of the next one,
148    if the application is reading the time of day often enough.  I think we
149    ought to do better than this.  For this reason, usecs_per_jiffy is left
150    separated out in the calculation below.  This allows some future hook into
151    the adjtime-related stuff in kernel/timer.c to remove this hazard.
152
153 */
154
155 static unsigned long usecs_since_tick(void)
156 {
157         unsigned long long current_ctc;
158         long ctc_ticks_since_interrupt;
159         unsigned long long ull_ctc_ticks_since_interrupt;
160         unsigned long result;
161
162         unsigned long long mul1_out;
163         unsigned long long mul1_out_high;
164         unsigned long long mul2_out_low, mul2_out_high;
165
166         /* Read CTC register */
167         asm ("getcon cr62, %0" : "=r" (current_ctc));
168         /* Note, the CTC counts down on each CPU clock, not up.
169            Note(2), use long type to get correct wraparound arithmetic when
170            the counter crosses zero. */
171         ctc_ticks_since_interrupt = (long) ctc_last_interrupt - (long) current_ctc;
172         ull_ctc_ticks_since_interrupt = (unsigned long long) ctc_ticks_since_interrupt;
173
174         /* Inline assembly to do 32x32x32->64 multiplier */
175         asm volatile ("mulu.l %1, %2, %0" :
176              "=r" (mul1_out) :
177              "r" (ull_ctc_ticks_since_interrupt), "r" (usecs_per_jiffy));
178
179         mul1_out_high = mul1_out >> 32;
180
181         asm volatile ("mulu.l %1, %2, %0" :
182              "=r" (mul2_out_low) :
183              "r" (mul1_out), "r" (scaled_recip_ctc_ticks_per_jiffy));
184
185 #if 1
186         asm volatile ("mulu.l %1, %2, %0" :
187              "=r" (mul2_out_high) :
188              "r" (mul1_out_high), "r" (scaled_recip_ctc_ticks_per_jiffy));
189 #endif
190
191         result = (unsigned long) (((mul2_out_high << 32) + mul2_out_low) >> CTC_JIFFY_SCALE_SHIFT);
192
193         return result;
194 }
195
196 void do_gettimeofday(struct timeval *tv)
197 {
198         unsigned long flags;
199         unsigned long seq;
200         unsigned long usec, sec;
201
202         do {
203                 seq = read_seqbegin_irqsave(&xtime_lock, flags);
204                 usec = usecs_since_tick();
205                 {
206                         unsigned long lost = jiffies - wall_jiffies;
207
208                         if (lost)
209                                 usec += lost * (1000000 / HZ);
210                 }
211
212                 sec = xtime.tv_sec;
213                 usec += xtime.tv_nsec / 1000;
214         } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
215
216         while (usec >= 1000000) {
217                 usec -= 1000000;
218                 sec++;
219         }
220
221         tv->tv_sec = sec;
222         tv->tv_usec = usec;
223 }
224
225 int do_settimeofday(struct timespec *tv)
226 {
227         time_t wtm_sec, sec = tv->tv_sec;
228         long wtm_nsec, nsec = tv->tv_nsec;
229
230         if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
231                 return -EINVAL;
232
233         write_seqlock_irq(&xtime_lock);
234         /*
235          * This is revolting. We need to set "xtime" correctly. However, the
236          * value in this location is the value at the most recent update of
237          * wall time.  Discover what correction gettimeofday() would have
238          * made, and then undo it!
239          */
240         nsec -= 1000 * (usecs_since_tick() +
241                                 (jiffies - wall_jiffies) * (1000000 / HZ));
242
243         wtm_sec  = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
244         wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
245
246         set_normalized_timespec(&xtime, sec, nsec);
247         set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
248
249         time_adjust = 0;                /* stop active adjtime() */
250         time_status |= STA_UNSYNC;
251         time_maxerror = NTP_PHASE_LIMIT;
252         time_esterror = NTP_PHASE_LIMIT;
253         write_sequnlock_irq(&xtime_lock);
254         clock_was_set();
255
256         return 0;
257 }
258
259 static int set_rtc_time(unsigned long nowtime)
260 {
261         int retval = 0;
262         int real_seconds, real_minutes, cmos_minutes;
263
264         ctrl_outb(RCR2_RESET, RCR2);  /* Reset pre-scaler & stop RTC */
265
266         cmos_minutes = ctrl_inb(RMINCNT);
267         BCD_TO_BIN(cmos_minutes);
268
269         /*
270          * since we're only adjusting minutes and seconds,
271          * don't interfere with hour overflow. This avoids
272          * messing with unknown time zones but requires your
273          * RTC not to be off by more than 15 minutes
274          */
275         real_seconds = nowtime % 60;
276         real_minutes = nowtime / 60;
277         if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
278                 real_minutes += 30;     /* correct for half hour time zone */
279         real_minutes %= 60;
280
281         if (abs(real_minutes - cmos_minutes) < 30) {
282                 BIN_TO_BCD(real_seconds);
283                 BIN_TO_BCD(real_minutes);
284                 ctrl_outb(real_seconds, RSECCNT);
285                 ctrl_outb(real_minutes, RMINCNT);
286         } else {
287                 printk(KERN_WARNING
288                        "set_rtc_time: can't update from %d to %d\n",
289                        cmos_minutes, real_minutes);
290                 retval = -1;
291         }
292
293         ctrl_outb(RCR2_RTCEN|RCR2_START, RCR2);  /* Start RTC */
294
295         return retval;
296 }
297
298 /* last time the RTC clock got updated */
299 static long last_rtc_update = 0;
300
301 static inline void sh64_do_profile(struct pt_regs *regs)
302 {
303         extern int _stext;
304         unsigned long pc;
305
306         profile_hook(regs);
307
308         if (user_mode(regs))
309                 return;
310
311         /* Don't profile cpu_idle..  */
312         if (!prof_buffer || !current->pid)
313                 return;
314
315         pc = instruction_pointer(regs);
316         pc -= (unsigned long) &_stext;
317         pc >>= prof_shift;
318
319         /*
320          * Don't ignore out-of-bounds PC values silently, put them into the
321          * last histogram slot, so if present, they will show up as a sharp
322          * peak.
323          */
324         if (pc > prof_len - 1)
325                 pc = prof_len - 1;
326
327         /* We could just be sloppy and not lock against a re-entry on this
328            increment, but the profiling code won't always be linked in anyway. */
329         atomic_inc((atomic_t *)&prof_buffer[pc]);
330 }
331
332 /*
333  * timer_interrupt() needs to keep up the real-time clock,
334  * as well as call the "do_timer()" routine every clocktick
335  */
336 static inline void do_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
337 {
338         unsigned long long current_ctc;
339         asm ("getcon cr62, %0" : "=r" (current_ctc));
340         ctc_last_interrupt = (unsigned long) current_ctc;
341
342         do_timer(regs);
343
344         sh64_do_profile(regs);
345
346 #ifdef CONFIG_HEARTBEAT
347         {
348                 extern void heartbeat(void);
349
350                 heartbeat();
351         }
352 #endif
353
354         /*
355          * If we have an externally synchronized Linux clock, then update
356          * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
357          * called as close as possible to 500 ms before the new second starts.
358          */
359         if ((time_status & STA_UNSYNC) == 0 &&
360             xtime.tv_sec > last_rtc_update + 660 &&
361             (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
362             (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
363                 if (set_rtc_time(xtime.tv_sec) == 0)
364                         last_rtc_update = xtime.tv_sec;
365                 else
366                         last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
367         }
368 }
369
370 /*
371  * This is the same as the above, except we _also_ save the current
372  * Time Stamp Counter value at the time of the timer interrupt, so that
373  * we later on can estimate the time of day more exactly.
374  */
375 static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
376 {
377         unsigned long timer_status;
378
379         /* Clear UNF bit */
380         timer_status = ctrl_inw(TMU0_TCR);
381         timer_status &= ~0x100;
382         ctrl_outw(timer_status, TMU0_TCR);
383
384         /*
385          * Here we are in the timer irq handler. We just have irqs locally
386          * disabled but we don't know if the timer_bh is running on the other
387          * CPU. We need to avoid to SMP race with it. NOTE: we don' t need
388          * the irq version of write_lock because as just said we have irq
389          * locally disabled. -arca
390          */
391         write_lock(&xtime_lock);
392         do_timer_interrupt(irq, NULL, regs);
393         write_unlock(&xtime_lock);
394
395         return IRQ_HANDLED;
396 }
397
398 static unsigned long get_rtc_time(void)
399 {
400         unsigned int sec, min, hr, wk, day, mon, yr, yr100;
401
402  again:
403         do {
404                 ctrl_outb(0, RCR1);  /* Clear CF-bit */
405                 sec = ctrl_inb(RSECCNT);
406                 min = ctrl_inb(RMINCNT);
407                 hr  = ctrl_inb(RHRCNT);
408                 wk  = ctrl_inb(RWKCNT);
409                 day = ctrl_inb(RDAYCNT);
410                 mon = ctrl_inb(RMONCNT);
411                 yr  = ctrl_inw(RYRCNT);
412                 yr100 = (yr >> 8);
413                 yr &= 0xff;
414         } while ((ctrl_inb(RCR1) & RCR1_CF) != 0);
415
416         BCD_TO_BIN(yr100);
417         BCD_TO_BIN(yr);
418         BCD_TO_BIN(mon);
419         BCD_TO_BIN(day);
420         BCD_TO_BIN(hr);
421         BCD_TO_BIN(min);
422         BCD_TO_BIN(sec);
423
424         if (yr > 99 || mon < 1 || mon > 12 || day > 31 || day < 1 ||
425             hr > 23 || min > 59 || sec > 59) {
426                 printk(KERN_ERR
427                        "SH RTC: invalid value, resetting to 1 Jan 2000\n");
428                 ctrl_outb(RCR2_RESET, RCR2);  /* Reset & Stop */
429                 ctrl_outb(0, RSECCNT);
430                 ctrl_outb(0, RMINCNT);
431                 ctrl_outb(0, RHRCNT);
432                 ctrl_outb(6, RWKCNT);
433                 ctrl_outb(1, RDAYCNT);
434                 ctrl_outb(1, RMONCNT);
435                 ctrl_outw(0x2000, RYRCNT);
436                 ctrl_outb(RCR2_RTCEN|RCR2_START, RCR2);  /* Start */
437                 goto again;
438         }
439
440         return mktime(yr100 * 100 + yr, mon, day, hr, min, sec);
441 }
442
443 static __init unsigned int get_cpu_hz(void)
444 {
445         unsigned int count;
446         unsigned long __dummy;
447         unsigned long ctc_val_init, ctc_val;
448
449         /*
450         ** Regardless the toolchain, force the compiler to use the
451         ** arbitrary register r3 as a clock tick counter.
452         ** NOTE: r3 must be in accordance with rtc_interrupt()
453         */
454         register unsigned long long  __rtc_irq_flag __asm__ ("r3");
455
456         sti();
457         do {} while (ctrl_inb(R64CNT) != 0);
458         ctrl_outb(RCR1_CIE, RCR1); /* Enable carry interrupt */
459
460         /*
461          * r3 is arbitrary. CDC does not support "=z".
462          */
463         ctc_val_init = 0xffffffff;
464         ctc_val = ctc_val_init;
465
466         asm volatile("gettr     tr0, %1\n\t"
467                      "putcon    %0, " __CTC "\n\t"
468                      "and       %2, r63, %2\n\t"
469                      "pta       $+4, tr0\n\t"
470                      "beq/l     %2, r63, tr0\n\t"
471                      "ptabs     %1, tr0\n\t"
472                      "getcon    " __CTC ", %0\n\t"
473                 : "=r"(ctc_val), "=r" (__dummy), "=r" (__rtc_irq_flag)
474                 : "0" (0));
475         cli();
476         /*
477          * SH-3:
478          * CPU clock = 4 stages * loop
479          * tst    rm,rm      if id ex
480          * bt/s   1b            if id ex
481          * add    #1,rd            if id ex
482          *                            (if) pipe line stole
483          * tst    rm,rm                  if id ex
484          * ....
485          *
486          *
487          * SH-4:
488          * CPU clock = 6 stages * loop
489          * I don't know why.
490          * ....
491          *
492          * SH-5:
493          * Use CTC register to count.  This approach returns the right value
494          * even if the I-cache is disabled (e.g. whilst debugging.)
495          *
496          */
497
498         count = ctc_val_init - ctc_val; /* CTC counts down */
499
500 #if defined (CONFIG_SH_SIMULATOR)
501         /*
502          * Let's pretend we are a 5MHz SH-5 to avoid a too
503          * little timer interval. Also to keep delay
504          * calibration within a reasonable time.
505          */
506         return 5000000;
507 #else
508         /*
509          * This really is count by the number of clock cycles
510          * by the ratio between a complete R64CNT
511          * wrap-around (128) and CUI interrupt being raised (64).
512          */
513         return count*2;
514 #endif
515 }
516
517 static irqreturn_t rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
518 {
519         ctrl_outb(0, RCR1);     /* Disable Carry Interrupts */
520         regs->regs[3] = 1;      /* Using r3 */
521
522         return IRQ_HANDLED;
523 }
524
525 static struct irqaction irq0  = { timer_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "timer", NULL, NULL};
526 static struct irqaction irq1  = { rtc_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "rtc", NULL, NULL};
527
528 void __init time_init(void)
529 {
530         unsigned int cpu_clock, master_clock, bus_clock, module_clock;
531         unsigned long interval;
532         unsigned long frqcr, ifc, pfc;
533         static int ifc_table[] = { 2, 4, 6, 8, 10, 12, 16, 24 };
534 #define bfc_table ifc_table     /* Same */
535 #define pfc_table ifc_table     /* Same */
536
537         tmu_base = onchip_remap(TMU_BASE, 1024, "TMU");
538         if (!tmu_base) {
539                 panic("Unable to remap TMU\n");
540         }
541
542         rtc_base = onchip_remap(RTC_BASE, 1024, "RTC");
543         if (!rtc_base) {
544                 panic("Unable to remap RTC\n");
545         }
546
547         cprc_base = onchip_remap(CPRC_BASE, 1024, "CPRC");
548         if (!cprc_base) {
549                 panic("Unable to remap CPRC\n");
550         }
551
552         xtime.tv_sec = get_rtc_time();
553         xtime.tv_nsec = 0;
554
555         setup_irq(TIMER_IRQ, &irq0);
556         setup_irq(RTC_IRQ, &irq1);
557
558         /* Check how fast it is.. */
559         cpu_clock = get_cpu_hz();
560
561         /* Note careful order of operations to maintain reasonable precision and avoid overflow. */
562         scaled_recip_ctc_ticks_per_jiffy = ((1ULL << CTC_JIFFY_SCALE_SHIFT) / (unsigned long long)(cpu_clock / HZ));
563
564         disable_irq(RTC_IRQ);
565
566         printk("CPU clock: %d.%02dMHz\n",
567                (cpu_clock / 1000000), (cpu_clock % 1000000)/10000);
568         {
569                 unsigned short bfc;
570                 frqcr = ctrl_inl(FRQCR);
571                 ifc  = ifc_table[(frqcr>> 6) & 0x0007];
572                 bfc  = bfc_table[(frqcr>> 3) & 0x0007];
573                 pfc  = pfc_table[(frqcr>> 12) & 0x0007];
574                 master_clock = cpu_clock * ifc;
575                 bus_clock = master_clock/bfc;
576         }
577
578         printk("Bus clock: %d.%02dMHz\n",
579                (bus_clock/1000000), (bus_clock % 1000000)/10000);
580         module_clock = master_clock/pfc;
581         printk("Module clock: %d.%02dMHz\n",
582                (module_clock/1000000), (module_clock % 1000000)/10000);
583         interval = (module_clock/(HZ*4));
584
585         printk("Interval = %ld\n", interval);
586
587         current_cpu_data.cpu_clock    = cpu_clock;
588         current_cpu_data.master_clock = master_clock;
589         current_cpu_data.bus_clock    = bus_clock;
590         current_cpu_data.module_clock = module_clock;
591
592         /* Start TMU0 */
593         ctrl_outb(TMU_TOCR_INIT, TMU_TOCR);
594         ctrl_outw(TMU0_TCR_INIT, TMU0_TCR);
595         ctrl_outl(interval, TMU0_TCOR);
596         ctrl_outl(interval, TMU0_TCNT);
597         ctrl_outb(TMU_TSTR_INIT, TMU_TSTR);
598 }
599
600 void enter_deep_standby(void)
601 {
602         /* Disable watchdog timer */
603         ctrl_outl(0xa5000000, WTCSR);
604         /* Configure deep standby on sleep */
605         ctrl_outl(0x03, STBCR);
606
607 #ifdef CONFIG_SH_ALPHANUMERIC
608         {
609                 extern void mach_alphanum(int position, unsigned char value);
610                 extern void mach_alphanum_brightness(int setting);
611                 char halted[] = "Halted. ";
612                 int i;
613                 mach_alphanum_brightness(6); /* dimmest setting above off */
614                 for (i=0; i<8; i++) {
615                         mach_alphanum(i, halted[i]);
616                 }
617                 asm __volatile__ ("synco");
618         }
619 #endif
620
621         asm __volatile__ ("sleep");
622         asm __volatile__ ("synci");
623         asm __volatile__ ("nop");
624         asm __volatile__ ("nop");
625         asm __volatile__ ("nop");
626         asm __volatile__ ("nop");
627         panic("Unexpected wakeup!\n");
628 }
629
630 /*
631  * Scheduler clock - returns current time in nanosec units.
632  */
633 unsigned long long sched_clock(void)
634 {
635         return (unsigned long long)jiffies * (1000000000 / HZ);
636 }
637