Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / arch / s390 / lib / delay.c
blob70f2a862b670649e296d1c6e5277f01241161a11
1 /*
2 * arch/s390/lib/delay.c
3 * Precise Delay Loops for S390
5 * S390 version
6 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
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>
14 #include <linux/sched.h>
15 #include <linux/delay.h>
16 #include <linux/timex.h>
17 #include <linux/irqflags.h>
18 #include <linux/interrupt.h>
20 void __delay(unsigned long loops)
23 * To end the bloody studid and useless discussion about the
24 * BogoMips number I took the liberty to define the __delay
25 * function in a way that that resulting BogoMips number will
26 * yield the megahertz number of the cpu. The important function
27 * is udelay and that is done using the tod clock. -- martin.
29 asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
33 * Waits for 'usecs' microseconds using the TOD clock comparator.
35 void __udelay(unsigned long usecs)
37 u64 end, time, jiffy_timer = 0;
38 unsigned long flags, cr0, mask, dummy;
39 int irq_context;
41 irq_context = in_interrupt();
42 if (!irq_context)
43 local_bh_disable();
44 local_irq_save(flags);
45 if (raw_irqs_disabled_flags(flags)) {
46 jiffy_timer = S390_lowcore.jiffy_timer;
47 S390_lowcore.jiffy_timer = -1ULL - (4096 << 12);
48 __ctl_store(cr0, 0, 0);
49 dummy = (cr0 & 0xffff00e0) | 0x00000800;
50 __ctl_load(dummy , 0, 0);
51 mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
52 } else
53 mask = psw_kernel_bits | PSW_MASK_WAIT |
54 PSW_MASK_EXT | PSW_MASK_IO;
56 end = get_clock() + ((u64) usecs << 12);
57 do {
58 time = end < S390_lowcore.jiffy_timer ?
59 end : S390_lowcore.jiffy_timer;
60 set_clock_comparator(time);
61 trace_hardirqs_on();
62 __load_psw_mask(mask);
63 local_irq_disable();
64 } while (get_clock() < end);
66 if (raw_irqs_disabled_flags(flags)) {
67 __ctl_load(cr0, 0, 0);
68 S390_lowcore.jiffy_timer = jiffy_timer;
70 if (!irq_context)
71 _local_bh_enable();
72 set_clock_comparator(S390_lowcore.jiffy_timer);
73 local_irq_restore(flags);