// SPDX-License-Identifier: GPL-2.01/*2* Precise Delay Loops for parisc3*4* based on code by:5* Copyright (C) 1993 Linus Torvalds6* Copyright (C) 1997 Martin Mares <[email protected]>7* Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>8*9* parisc implementation:10* Copyright (C) 2013 Helge Deller <[email protected]>11*/121314#include <linux/module.h>15#include <linux/preempt.h>16#include <linux/init.h>1718#include <asm/delay.h>19#include <asm/special_insns.h> /* for mfctl() */20#include <asm/processor.h> /* for boot_cpu_data */2122/* CR16 based delay: */23static void __cr16_delay(unsigned long __loops)24{25/*26* Note: Due to unsigned math, cr16 rollovers shouldn't be27* a problem here. However, on 32 bit, we need to make sure28* we don't pass in too big a value. The current default29* value of MAX_UDELAY_MS should help prevent this.30*/31u32 bclock, now, loops = __loops;32int cpu;3334preempt_disable();35cpu = smp_processor_id();36bclock = mfctl(16);37for (;;) {38now = mfctl(16);39if ((now - bclock) >= loops)40break;4142/* Allow RT tasks to run */43preempt_enable();44asm volatile(" nop\n");45barrier();46preempt_disable();4748/*49* It is possible that we moved to another CPU, and50* since CR16's are per-cpu we need to calculate51* that. The delay must guarantee that we wait "at52* least" the amount of time. Being moved to another53* CPU could make the wait longer but we just need to54* make sure we waited long enough. Rebalance the55* counter for this CPU.56*/57if (unlikely(cpu != smp_processor_id())) {58loops -= (now - bclock);59cpu = smp_processor_id();60bclock = mfctl(16);61}62}63preempt_enable();64}656667void __udelay(unsigned long usecs)68{69__cr16_delay(usecs * ((unsigned long)boot_cpu_data.cpu_hz / 1000000UL));70}71EXPORT_SYMBOL(__udelay);727374