2 * arch/s390/lib/delay.c
3 * Precise Delay Loops for S390
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, old_cc = 0;
38 unsigned long flags, cr0, mask, dummy;
41 irq_context = in_interrupt();
44 local_irq_save(flags);
45 if (raw_irqs_disabled_flags(flags)) {
46 old_cc = S390_lowcore.clock_comparator;
47 S390_lowcore.clock_comparator = -1ULL;
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;
53 mask = psw_kernel_bits | PSW_MASK_WAIT |
54 PSW_MASK_EXT | PSW_MASK_IO;
56 end = get_clock() + ((u64) usecs << 12);
58 time = end < S390_lowcore.clock_comparator ?
59 end : S390_lowcore.clock_comparator;
60 set_clock_comparator(time);
62 __load_psw_mask(mask);
64 } while (get_clock() < end);
66 if (raw_irqs_disabled_flags(flags)) {
67 __ctl_load(cr0, 0, 0);
68 S390_lowcore.clock_comparator = old_cc;
72 set_clock_comparator(S390_lowcore.clock_comparator);
73 local_irq_restore(flags);