Blame view

kernel/linux-rt-4.4.41/arch/m32r/lib/delay.c 2.92 KB
5113f6f70   김현기   kernel add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  /*
   * linux/arch/m32r/lib/delay.c
   *
   * Copyright (c) 2002  Hitoshi Yamamoto, Hirokazu Takata
   * Copyright (c) 2004  Hirokazu Takata
   */
  
  #include <linux/param.h>
  #include <linux/module.h>
  #ifdef CONFIG_SMP
  #include <linux/sched.h>
  #include <asm/current.h>
  #include <asm/smp.h>
  #endif  /* CONFIG_SMP */
  #include <asm/processor.h>
  
  void __delay(unsigned long loops)
  {
  #ifdef CONFIG_ISA_DUAL_ISSUE
  	__asm__ __volatile__ (
  		"beqz	%0, 2f			
  \t"
  		"addi	%0, #-1			
  \t"
  
  		" .fillinsn			
  \t"
  		"1:				
  \t"
  		"cmpz	%0  ||  addi  %0, #-1	
  \t"
  		"bc	2f  ||  cmpz  %0	
  \t"
  		"bc	2f  ||  addi  %0, #-1	
  \t"
  		"cmpz	%0  ||  addi  %0, #-1	
  \t"
  		"bc	2f  ||  cmpz  %0	
  \t"
  		"bnc	1b  ||  addi  %0, #-1	
  \t"
  		" .fillinsn			
  \t"
  		"2:				
  \t"
  		: "+r" (loops)
  		: "r" (0)
  		: "cbit"
  	);
  #else
  	__asm__ __volatile__ (
  		"beqz	%0, 2f			
  \t"
  		" .fillinsn			
  \t"
  		"1:				
  \t"
  		"addi	%0, #-1			
  \t"
  		"blez	%0, 2f			
  \t"
  		"addi	%0, #-1			
  \t"
  		"blez	%0, 2f			
  \t"
  		"addi	%0, #-1			
  \t"
  		"blez	%0, 2f			
  \t"
  		"addi	%0, #-1			
  \t"
  		"bgtz	%0, 1b			
  \t"
  		" .fillinsn			
  \t"
  		"2:				
  \t"
  		: "+r" (loops)
  		: "r" (0)
  	);
  #endif
  }
  
  void __const_udelay(unsigned long xloops)
  {
  #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
  	/*
  	 * loops [1] = (xloops >> 32) [sec] * loops_per_jiffy [1/jiffy]
  	 *            * HZ [jiffy/sec]
  	 *          = (xloops >> 32) [sec] * (loops_per_jiffy * HZ) [1/sec]
  	 *          = (((xloops * loops_per_jiffy) >> 32) * HZ) [1]
  	 *
  	 * NOTE:
  	 *   - '[]' depicts variable's dimension in the above equation.
  	 *   - "rac" instruction rounds the accumulator in word size.
  	 */
  	__asm__ __volatile__ (
  		"srli	%0, #1				
  \t"
  		"mulwhi	%0, %1	; a0			
  \t"
  		"mulwu1	%0, %1	; a1			
  \t"
  		"sadd		; a0 += (a1 >> 16)	
  \t"
  		"rac	a0, a0, #1			
  \t"
  		"mvfacmi %0, a0				
  \t"
  		: "+r" (xloops)
  		: "r" (current_cpu_data.loops_per_jiffy)
  		: "a0", "a1"
  	);
  #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
  	/*
  	 * u64 ull;
  	 * ull = (u64)xloops * (u64)current_cpu_data.loops_per_jiffy;
  	 * xloops = (ull >> 32);
  	 */
  	__asm__ __volatile__ (
  		"and3	r4, %0, #0xffff		
  \t"
  		"and3	r5, %1, #0xffff		
  \t"
  		"mul	r4, r5			
  \t"
  		"srl3	r6, %0, #16		
  \t"
  		"srli	r4, #16			
  \t"
  		"mul	r5, r6			
  \t"
  		"add	r4, r5			
  \t"
  		"and3	r5, %0, #0xffff		
  \t"
  		"srl3	r6, %1, #16		
  \t"
  		"mul	r5, r6			
  \t"
  		"add	r4, r5			
  \t"
  		"srl3	r5, %0, #16		
  \t"
  		"srli	r4, #16			
  \t"
  		"mul	r5, r6			
  \t"
  		"add	r4, r5			
  \t"
  		"mv	%0, r4			
  \t"
  		: "+r" (xloops)
  		: "r" (current_cpu_data.loops_per_jiffy)
  		: "r4", "r5", "r6"
  	);
  #else
  #error unknown isa configuration
  #endif
  	__delay(xloops * HZ);
  }
  
  void __udelay(unsigned long usecs)
  {
  	__const_udelay(usecs * 0x000010c7);  /* 2**32 / 1000000 (rounded up) */
  }
  
  void __ndelay(unsigned long nsecs)
  {
  	__const_udelay(nsecs * 0x00005);  /* 2**32 / 1000000000 (rounded up) */
  }
  
  EXPORT_SYMBOL(__delay);
  EXPORT_SYMBOL(__const_udelay);
  EXPORT_SYMBOL(__udelay);
  EXPORT_SYMBOL(__ndelay);