1 // SPDX-License-Identifier: GPL-2.0
3 * Precise Delay Loops for parisc
6 * Copyright (C) 1993 Linus Torvalds
7 * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8 * Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>
10 * parisc implementation:
11 * Copyright (C) 2013 Helge Deller <deller@gmx.de>
15 #include <linux/module.h>
16 #include <linux/preempt.h>
17 #include <linux/init.h>
19 #include <asm/processor.h>
20 #include <asm/delay.h>
22 #include <asm/special_insns.h> /* for mfctl() */
23 #include <asm/processor.h> /* for boot_cpu_data */
25 /* CR16 based delay: */
26 static void __cr16_delay(unsigned long __loops)
29 * Note: Due to unsigned math, cr16 rollovers shouldn't be
30 * a problem here. However, on 32 bit, we need to make sure
31 * we don't pass in too big a value. The current default
32 * value of MAX_UDELAY_MS should help prevent this.
34 u32 bclock, now, loops = __loops;
38 cpu = smp_processor_id();
42 if ((now - bclock) >= loops)
45 /* Allow RT tasks to run */
47 asm volatile(" nop\n");
52 * It is possible that we moved to another CPU, and
53 * since CR16's are per-cpu we need to calculate
54 * that. The delay must guarantee that we wait "at
55 * least" the amount of time. Being moved to another
56 * CPU could make the wait longer but we just need to
57 * make sure we waited long enough. Rebalance the
58 * counter for this CPU.
60 if (unlikely(cpu != smp_processor_id())) {
61 loops -= (now - bclock);
62 cpu = smp_processor_id();
70 void __udelay(unsigned long usecs)
72 __cr16_delay(usecs * ((unsigned long)boot_cpu_data.cpu_hz / 1000000UL));
74 EXPORT_SYMBOL(__udelay);