blob: 02854449b74ba64dea7230b606f72b63c3890218 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Martin Schwidefskyd54853e2007-02-05 21:18:19 +01002 * arch/s390/lib/delay.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Precise Delay Loops for S390
4 *
5 * S390 version
6 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 *
9 * Derived from "arch/i386/lib/delay.c"
10 * Copyright (C) 1993 Linus Torvalds
11 * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sched.h>
15#include <linux/delay.h>
Martin Schwidefskyd54853e2007-02-05 21:18:19 +010016#include <linux/timex.h>
17#include <linux/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19void __delay(unsigned long loops)
20{
21 /*
22 * To end the bloody studid and useless discussion about the
23 * BogoMips number I took the liberty to define the __delay
24 * function in a way that that resulting BogoMips number will
25 * yield the megahertz number of the cpu. The important function
26 * is udelay and that is done using the tod clock. -- martin.
27 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020028 asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
31/*
Martin Schwidefskyd54853e2007-02-05 21:18:19 +010032 * Waits for 'usecs' microseconds using the TOD clock comparator.
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 */
34void __udelay(unsigned long usecs)
35{
Martin Schwidefskyd54853e2007-02-05 21:18:19 +010036 u64 end, time, jiffy_timer = 0;
37 unsigned long flags, cr0, mask, dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Martin Schwidefskyd54853e2007-02-05 21:18:19 +010039 local_irq_save(flags);
40 if (raw_irqs_disabled_flags(flags)) {
41 jiffy_timer = S390_lowcore.jiffy_timer;
42 S390_lowcore.jiffy_timer = -1ULL - (4096 << 12);
43 __ctl_store(cr0, 0, 0);
44 dummy = (cr0 & 0xffff00e0) | 0x00000800;
45 __ctl_load(dummy , 0, 0);
46 mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
47 } else
48 mask = psw_kernel_bits | PSW_MASK_WAIT |
49 PSW_MASK_EXT | PSW_MASK_IO;
50
51 end = get_clock() + ((u64) usecs << 12);
52 do {
53 time = end < S390_lowcore.jiffy_timer ?
54 end : S390_lowcore.jiffy_timer;
55 set_clock_comparator(time);
56 trace_hardirqs_on();
57 __load_psw_mask(mask);
58 local_irq_disable();
59 } while (get_clock() < end);
60
61 if (raw_irqs_disabled_flags(flags)) {
62 __ctl_load(cr0, 0, 0);
63 S390_lowcore.jiffy_timer = jiffy_timer;
64 }
65 set_clock_comparator(S390_lowcore.jiffy_timer);
66 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}