| 1 | |
| 2 | |
| 3 | * Precise Delay Loops for parisc
|
| 4 | *
|
| 5 | * based on code by:
|
| 6 | * Copyright (C) 1993 Linus Torvalds
|
| 7 | * Copyright (C) 1997 Martin Mares <[email protected]>
|
| 8 | * Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>
|
| 9 | *
|
| 10 | * parisc implementation:
|
| 11 | * Copyright (C) 2013 Helge Deller <[email protected]>
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 | #include <linux/module.h>
|
| 16 | #include <linux/preempt.h>
|
| 17 | #include <linux/init.h>
|
| 18 |
|
| 19 | #include <asm/delay.h>
|
| 20 | #include <asm/special_insns.h>
|
| 21 | #include <asm/processor.h>
|
| 22 |
|
| 23 |
|
| 24 | static void __cr16_delay(unsigned long __loops)
|
| 25 | {
|
| 26 | |
| 27 | * Note: Due to unsigned math, cr16 rollovers shouldn't be
|
| 28 | * a problem here. However, on 32 bit, we need to make sure
|
| 29 | * we don't pass in too big a value. The current default
|
| 30 | * value of MAX_UDELAY_MS should help prevent this.
|
| 31 |
|
| 32 | u32 bclock, now, loops = __loops;
|
| 33 | int cpu;
|
| 34 |
|
| 35 | preempt_disable();
|
| 36 | cpu = smp_processor_id();
|
| 37 | bclock = mfctl(16);
|
| 38 | for (;;) {
|
| 39 | now = mfctl(16);
|
| 40 | if ((now - bclock) >= loops)
|
| 41 | break;
|
| 42 |
|
| 43 |
|
| 44 | preempt_enable();
|
| 45 | asm volatile(" nop\n");
|
| 46 | barrier();
|
| 47 | preempt_disable();
|
| 48 |
|
| 49 | |
| 50 | * It is possible that we moved to another CPU, and
|
| 51 | * since CR16's are per-cpu we need to calculate
|
| 52 | * that. The delay must guarantee that we wait "at
|
| 53 | * least" the amount of time. Being moved to another
|
| 54 | * CPU could make the wait longer but we just need to
|
| 55 | * make sure we waited long enough. Rebalance the
|
| 56 | * counter for this CPU.
|
| 57 |
|
| 58 | if (unlikely(cpu != smp_processor_id())) {
|
| 59 | loops -= (now - bclock);
|
| 60 | cpu = smp_processor_id();
|
| 61 | bclock = mfctl(16);
|
| 62 | }
|
| 63 | }
|
| 64 | preempt_enable();
|
| 65 | }
|
| 66 |
|
| 67 |
|
| 68 | void __udelay(unsigned long usecs)
|
| 69 | {
|
| 70 | __cr16_delay(usecs * ((unsigned long)boot_cpu_data.cpu_hz / 1000000UL));
|
| 71 | }
|
| 72 | EXPORT_SYMBOL(__udelay);
|