Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 1993, 2000 Linus Torvalds
0004  *
0005  * Delay routines, using a pre-computed "loops_per_jiffy" value.
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/sched.h> /* for udelay's use of smp_processor_id */
0010 #include <asm/param.h>
0011 #include <asm/smp.h>
0012 #include <linux/delay.h>
0013 
0014 /*
0015  * Use only for very small delays (< 1 msec). 
0016  *
0017  * The active part of our cycle counter is only 32-bits wide, and
0018  * we're treating the difference between two marks as signed.  On
0019  * a 1GHz box, that's about 2 seconds.
0020  */
0021 
0022 void
0023 __delay(int loops)
0024 {
0025     int tmp;
0026     __asm__ __volatile__(
0027         "   rpcc %0\n"
0028         "   addl %1,%0,%1\n"
0029         "1: rpcc %0\n"
0030         "   subl %1,%0,%0\n"
0031         "   bgt %0,1b"
0032         : "=&r" (tmp), "=r" (loops) : "1"(loops));
0033 }
0034 EXPORT_SYMBOL(__delay);
0035 
0036 #ifdef CONFIG_SMP
0037 #define LPJ  cpu_data[smp_processor_id()].loops_per_jiffy
0038 #else
0039 #define LPJ  loops_per_jiffy
0040 #endif
0041 
0042 void
0043 udelay(unsigned long usecs)
0044 {
0045     usecs *= (((unsigned long)HZ << 32) / 1000000) * LPJ;
0046     __delay((long)usecs >> 32);
0047 }
0048 EXPORT_SYMBOL(udelay);
0049 
0050 void
0051 ndelay(unsigned long nsecs)
0052 {
0053     nsecs *= (((unsigned long)HZ << 32) / 1000000000) * LPJ;
0054     __delay((long)nsecs >> 32);
0055 }
0056 EXPORT_SYMBOL(ndelay);