This source file includes following definitions.
- set_tod_clock
- store_tod_clock
- set_clock_comparator
- store_clock_comparator
- ptff_query
- local_tick_disable
- local_tick_enable
- get_tod_clock_ext
- get_tod_clock
- get_tod_clock_fast
- get_cycles
- get_tod_clock_monotonic
- tod_to_ns
- tod_after
- tod_after_eq
1
2
3
4
5
6
7
8
9
10 #ifndef _ASM_S390_TIMEX_H
11 #define _ASM_S390_TIMEX_H
12
13 #include <linux/preempt.h>
14 #include <linux/time64.h>
15 #include <asm/lowcore.h>
16
17
18 #define TOD_UNIX_EPOCH 0x7d91048bca000000ULL
19
20 extern u64 clock_comparator_max;
21
22
23 static inline int set_tod_clock(__u64 time)
24 {
25 int cc;
26
27 asm volatile(
28 " sck %1\n"
29 " ipm %0\n"
30 " srl %0,28\n"
31 : "=d" (cc) : "Q" (time) : "cc");
32 return cc;
33 }
34
35 static inline int store_tod_clock(__u64 *time)
36 {
37 int cc;
38
39 asm volatile(
40 " stck %1\n"
41 " ipm %0\n"
42 " srl %0,28\n"
43 : "=d" (cc), "=Q" (*time) : : "cc");
44 return cc;
45 }
46
47 static inline void set_clock_comparator(__u64 time)
48 {
49 asm volatile("sckc %0" : : "Q" (time));
50 }
51
52 static inline void store_clock_comparator(__u64 *time)
53 {
54 asm volatile("stckc %0" : "=Q" (*time));
55 }
56
57 void clock_comparator_work(void);
58
59 void __init time_early_init(void);
60
61 extern unsigned char ptff_function_mask[16];
62
63
64 #define PTFF_QAF 0x00
65 #define PTFF_QTO 0x01
66 #define PTFF_QSI 0x02
67 #define PTFF_QUI 0x04
68 #define PTFF_ATO 0x40
69 #define PTFF_STO 0x41
70 #define PTFF_SFS 0x42
71 #define PTFF_SGS 0x43
72
73
74 struct ptff_qto {
75 unsigned long long physical_clock;
76 unsigned long long tod_offset;
77 unsigned long long logical_tod_offset;
78 unsigned long long tod_epoch_difference;
79 } __packed;
80
81 static inline int ptff_query(unsigned int nr)
82 {
83 unsigned char *ptr;
84
85 ptr = ptff_function_mask + (nr >> 3);
86 return (*ptr & (0x80 >> (nr & 7))) != 0;
87 }
88
89
90 struct ptff_qui {
91 unsigned int tm : 2;
92 unsigned int ts : 2;
93 unsigned int : 28;
94 unsigned int pad_0x04;
95 unsigned long leap_event;
96 short old_leap;
97 short new_leap;
98 unsigned int pad_0x14;
99 unsigned long prt[5];
100 unsigned long cst[3];
101 unsigned int skew;
102 unsigned int pad_0x5c[41];
103 } __packed;
104
105
106
107
108
109
110
111
112 #define ptff(ptff_block, len, func) \
113 ({ \
114 struct addrtype { char _[len]; }; \
115 register unsigned int reg0 asm("0") = func; \
116 register unsigned long reg1 asm("1") = (unsigned long) (ptff_block);\
117 int rc; \
118 \
119 asm volatile( \
120 " .word 0x0104\n" \
121 " ipm %0\n" \
122 " srl %0,28\n" \
123 : "=d" (rc), "+m" (*(struct addrtype *) reg1) \
124 : "d" (reg0), "d" (reg1) : "cc"); \
125 rc; \
126 })
127
128 static inline unsigned long long local_tick_disable(void)
129 {
130 unsigned long long old;
131
132 old = S390_lowcore.clock_comparator;
133 S390_lowcore.clock_comparator = clock_comparator_max;
134 set_clock_comparator(S390_lowcore.clock_comparator);
135 return old;
136 }
137
138 static inline void local_tick_enable(unsigned long long comp)
139 {
140 S390_lowcore.clock_comparator = comp;
141 set_clock_comparator(S390_lowcore.clock_comparator);
142 }
143
144 #define CLOCK_TICK_RATE 1193180
145 #define STORE_CLOCK_EXT_SIZE 16
146
147 typedef unsigned long long cycles_t;
148
149 static inline void get_tod_clock_ext(char *clk)
150 {
151 typedef struct { char _[STORE_CLOCK_EXT_SIZE]; } addrtype;
152
153 asm volatile("stcke %0" : "=Q" (*(addrtype *) clk) : : "cc");
154 }
155
156 static inline unsigned long long get_tod_clock(void)
157 {
158 char clk[STORE_CLOCK_EXT_SIZE];
159
160 get_tod_clock_ext(clk);
161 return *((unsigned long long *)&clk[1]);
162 }
163
164 static inline unsigned long long get_tod_clock_fast(void)
165 {
166 #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
167 unsigned long long clk;
168
169 asm volatile("stckf %0" : "=Q" (clk) : : "cc");
170 return clk;
171 #else
172 return get_tod_clock();
173 #endif
174 }
175
176 static inline cycles_t get_cycles(void)
177 {
178 return (cycles_t) get_tod_clock() >> 2;
179 }
180
181 int get_phys_clock(unsigned long *clock);
182 void init_cpu_timer(void);
183 unsigned long long monotonic_clock(void);
184
185 extern unsigned char tod_clock_base[16] __aligned(8);
186
187
188
189
190
191
192
193
194 static inline unsigned long long get_tod_clock_monotonic(void)
195 {
196 unsigned long long tod;
197
198 preempt_disable_notrace();
199 tod = get_tod_clock() - *(unsigned long long *) &tod_clock_base[1];
200 preempt_enable_notrace();
201 return tod;
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223 static inline unsigned long long tod_to_ns(unsigned long long todval)
224 {
225 return ((todval >> 9) * 125) + (((todval & 0x1ff) * 125) >> 9);
226 }
227
228
229
230
231
232
233
234
235 static inline int tod_after(unsigned long long a, unsigned long long b)
236 {
237 if (MACHINE_HAS_SCC)
238 return (long long) a > (long long) b;
239 return a > b;
240 }
241
242
243
244
245
246
247
248
249 static inline int tod_after_eq(unsigned long long a, unsigned long long b)
250 {
251 if (MACHINE_HAS_SCC)
252 return (long long) a >= (long long) b;
253 return a >= b;
254 }
255
256 #endif