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