~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/riscv/lib/delay.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/riscv/lib/delay.c (Architecture sparc) and /arch/sparc64/lib/delay.c (Architecture sparc64)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 
  2 /*                                                
  3  * Copyright (C) 2012 Regents of the Universit    
  4  */                                               
  5                                                   
  6 #include <linux/delay.h>                          
  7 #include <linux/math.h>                           
  8 #include <linux/param.h>                          
  9 #include <linux/timex.h>                          
 10 #include <linux/types.h>                          
 11 #include <linux/export.h>                         
 12                                                   
 13 #include <asm/processor.h>                        
 14                                                   
 15 /*                                                
 16  * This is copies from arch/arm/include/asm/de    
 17  *                                                
 18  * Loop (or tick) based delay:                    
 19  *                                                
 20  * loops = loops_per_jiffy * jiffies_per_sec *    
 21  *                                                
 22  * where:                                         
 23  *                                                
 24  * jiffies_per_sec = HZ                           
 25  * us_per_sec = 1000000                           
 26  *                                                
 27  * Therefore the constant part is HZ / 1000000    
 28  * fractional number. To make this usable with    
 29  * scale up this constant by 2^31, perform the    
 30  * and scale the result back down by 2^31 with    
 31  *                                                
 32  * loops = (loops_per_jiffy * delay_us * UDELA    
 33  *                                                
 34  * where:                                         
 35  *                                                
 36  * UDELAY_MULT = 2^31 * HZ / 1000000              
 37  *             = (2^31 / 1000000) * HZ            
 38  *             = 2147.483648 * HZ                 
 39  *             = 2147 * HZ + 483648 * HZ / 100    
 40  *                                                
 41  * 31 is the biggest scale shift value that wo    
 42  * delay_us * UDELAY_MULT assuming HZ <= 1000     
 43  */                                               
 44 #define MAX_UDELAY_US   2000                      
 45 #define MAX_UDELAY_HZ   1000                      
 46 #define UDELAY_MULT     (2147UL * HZ + 483648U    
 47 #define UDELAY_SHIFT    31                        
 48                                                   
 49 #if HZ > MAX_UDELAY_HZ                            
 50 #error "HZ > MAX_UDELAY_HZ"                       
 51 #endif                                            
 52                                                   
 53 /*                                                
 54  * RISC-V supports both UDELAY and NDELAY.  Th    
 55  * but with different constants.  I added 10 b    
 56  * the result is that I need a 64-bit multiply    
 57  * platforms.                                     
 58  *                                                
 59  * NDELAY_MULT = 2^41 * HZ / 1000000000           
 60  *             = (2^41 / 1000000000) * HZ         
 61  *             = 2199.02325555 * HZ               
 62  *             = 2199 * HZ + 23255550 * HZ / 1    
 63  *                                                
 64  * The maximum here is to avoid 64-bit overflo    
 65  * won't happen.                                  
 66  */                                               
 67 #define MAX_NDELAY_NS   (1ULL << 42)              
 68 #define MAX_NDELAY_HZ   MAX_UDELAY_HZ             
 69 #define NDELAY_MULT     ((unsigned long long)(    
 70 #define NDELAY_SHIFT    41                        
 71                                                   
 72 #if HZ > MAX_NDELAY_HZ                            
 73 #error "HZ > MAX_NDELAY_HZ"                       
 74 #endif                                            
 75                                                   
 76 void __delay(unsigned long cycles)                
 77 {                                                 
 78         u64 t0 = get_cycles();                    
 79                                                   
 80         while ((unsigned long)(get_cycles() -     
 81                 cpu_relax();                      
 82 }                                                 
 83 EXPORT_SYMBOL(__delay);                           
 84                                                   
 85 void udelay(unsigned long usecs)                  
 86 {                                                 
 87         u64 ucycles = (u64)usecs * lpj_fine *     
 88         u64 n;                                    
 89                                                   
 90         if (unlikely(usecs > MAX_UDELAY_US)) {    
 91                 n = (u64)usecs * riscv_timebas    
 92                 do_div(n, 1000000);               
 93                                                   
 94                 __delay(n);                       
 95                 return;                           
 96         }                                         
 97                                                   
 98         __delay(ucycles >> UDELAY_SHIFT);         
 99 }                                                 
100 EXPORT_SYMBOL(udelay);                            
101                                                   
102 void ndelay(unsigned long nsecs)                  
103 {                                                 
104         /*                                        
105          * This doesn't bother checking for ov    
106          * an hour) of delay.                     
107          */                                       
108         unsigned long long ncycles = nsecs * l    
109         __delay(ncycles >> NDELAY_SHIFT);         
110 }                                                 
111 EXPORT_SYMBOL(ndelay);                            
112                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php