2 * Precise Delay Loops for parisc
5 * Copyright (C) 1993 Linus Torvalds
7 * Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>
9 * parisc implementation:
14 #include <linux/module.h>
15 #include <linux/preempt.h>
16 #include <linux/init.h>
18 #include <asm/processor.h>
19 #include <asm/delay.h>
21 #include <asm/special_insns.h> /* for mfctl() */
22 #include <asm/processor.h> /* for boot_cpu_data */
24 /* CR16 based delay: */
25 static void __cr16_delay(unsigned long __loops)
28 * Note: Due to unsigned math, cr16 rollovers shouldn't be
29 * a problem here. However, on 32 bit, we need to make sure
30 * we don't pass in too big a value. The current default
31 * value of MAX_UDELAY_MS should help prevent this.
33 u32 bclock, now, loops = __loops;
37 cpu = smp_processor_id();
41 if ((now - bclock) >= loops)
44 /* Allow RT tasks to run */
46 asm volatile(" nop\n");
51 * It is possible that we moved to another CPU, and
52 * since CR16's are per-cpu we need to calculate
53 * that. The delay must guarantee that we wait "at
54 * least" the amount of time. Being moved to another
55 * CPU could make the wait longer but we just need to
56 * make sure we waited long enough. Rebalance the
57 * counter for this CPU.
59 if (unlikely(cpu != smp_processor_id())) {
60 loops -= (now - bclock);
61 cpu = smp_processor_id();
69 void __udelay(unsigned long usecs)
71 __cr16_delay(usecs * ((unsigned long)boot_cpu_data.cpu_hz / 1000000UL));
73 EXPORT_SYMBOL(__udelay);