2 * Precise Delay Loops for S390
4 * Copyright IBM Corp. 1999,2008
5 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
6 * Heiko Carstens <heiko.carstens@de.ibm.com>,
9 #include <linux/sched.h>
10 #include <linux/delay.h>
11 #include <linux/timex.h>
12 #include <linux/irqflags.h>
13 #include <linux/interrupt.h>
15 void __delay(unsigned long loops)
18 * To end the bloody studid and useless discussion about the
19 * BogoMips number I took the liberty to define the __delay
20 * function in a way that that resulting BogoMips number will
21 * yield the megahertz number of the cpu. The important function
22 * is udelay and that is done using the tod clock. -- martin.
24 asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
27 static void __udelay_disabled(unsigned long usecs)
29 unsigned long mask, cr0, cr0_saved;
32 clock_saved = local_tick_disable();
33 set_clock_comparator(get_clock() + ((u64) usecs << 12));
34 __ctl_store(cr0_saved, 0, 0);
35 cr0 = (cr0_saved & 0xffff00e0) | 0x00000800;
36 __ctl_load(cr0 , 0, 0);
37 mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
39 __load_psw_mask(mask);
41 __ctl_load(cr0_saved, 0, 0);
42 local_tick_enable(clock_saved);
43 set_clock_comparator(S390_lowcore.clock_comparator);
46 static void __udelay_enabled(unsigned long usecs)
51 mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT | PSW_MASK_IO;
52 end = get_clock() + ((u64) usecs << 12);
54 time = end < S390_lowcore.clock_comparator ?
55 end : S390_lowcore.clock_comparator;
56 set_clock_comparator(time);
58 __load_psw_mask(mask);
60 } while (get_clock() < end);
61 set_clock_comparator(S390_lowcore.clock_comparator);
65 * Waits for 'usecs' microseconds using the TOD clock comparator.
67 void __udelay(unsigned long usecs)
72 local_irq_save(flags);
74 __udelay_disabled(usecs);
78 if (raw_irqs_disabled_flags(flags))
79 __udelay_disabled(usecs);
81 __udelay_enabled(usecs);
84 if (raw_irqs_disabled_flags(flags)) {
86 __udelay_disabled(usecs);
90 __udelay_enabled(usecs);
92 local_irq_restore(flags);
97 * Simple udelay variant. To be used on startup and reboot
98 * when the interrupt handler isn't working.
100 void udelay_simple(unsigned long usecs)
104 end = get_clock() + ((u64) usecs << 12);
105 while (get_clock() < end)