]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/s390/include/asm/timex.h
3 * Copyright IBM Corp. 1999
5 * Derived from "include/asm-i386/timex.h"
6 * Copyright (C) 1992, Linus Torvalds
9 #ifndef _ASM_S390_TIMEX_H
10 #define _ASM_S390_TIMEX_H
12 #include <asm/lowcore.h>
13 #include <linux/time64.h>
15 /* The value of the TOD clock for 1.1.1970. */
16 #define TOD_UNIX_EPOCH 0x7d91048bca000000ULL
18 /* Inline functions for clock register access. */
19 static inline int set_tod_clock(__u64 time
)
27 : "=d" (cc
) : "Q" (time
) : "cc");
31 static inline int store_tod_clock(__u64
*time
)
39 : "=d" (cc
), "=Q" (*time
) : : "cc");
43 static inline void set_clock_comparator(__u64 time
)
45 asm volatile("sckc %0" : : "Q" (time
));
48 static inline void store_clock_comparator(__u64
*time
)
50 asm volatile("stckc %0" : "=Q" (*time
));
53 void clock_comparator_work(void);
55 void __init
ptff_init(void);
57 extern unsigned char ptff_function_mask
[16];
58 extern unsigned long lpar_offset
;
60 /* Function codes for the ptff instruction. */
61 #define PTFF_QAF 0x00 /* query available functions */
62 #define PTFF_QTO 0x01 /* query tod offset */
63 #define PTFF_QSI 0x02 /* query steering information */
64 #define PTFF_ATO 0x40 /* adjust tod offset */
65 #define PTFF_STO 0x41 /* set tod offset */
66 #define PTFF_SFS 0x42 /* set fine steering rate */
67 #define PTFF_SGS 0x43 /* set gross steering rate */
69 /* Query TOD offset result */
71 unsigned long long physical_clock
;
72 unsigned long long tod_offset
;
73 unsigned long long logical_tod_offset
;
74 unsigned long long tod_epoch_difference
;
77 static inline int ptff_query(unsigned int nr
)
81 ptr
= ptff_function_mask
+ (nr
>> 3);
82 return (*ptr
& (0x80 >> (nr
& 7))) != 0;
85 static inline int ptff(void *ptff_block
, size_t len
, unsigned int func
)
87 typedef struct { char _
[len
]; } addrtype
;
88 register unsigned int reg0
asm("0") = func
;
89 register unsigned long reg1
asm("1") = (unsigned long) ptff_block
;
96 : "=d" (rc
), "+m" (*(addrtype
*) ptff_block
)
97 : "d" (reg0
), "d" (reg1
) : "cc");
101 static inline unsigned long long local_tick_disable(void)
103 unsigned long long old
;
105 old
= S390_lowcore
.clock_comparator
;
106 S390_lowcore
.clock_comparator
= -1ULL;
107 set_clock_comparator(S390_lowcore
.clock_comparator
);
111 static inline void local_tick_enable(unsigned long long comp
)
113 S390_lowcore
.clock_comparator
= comp
;
114 set_clock_comparator(S390_lowcore
.clock_comparator
);
117 #define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
118 #define STORE_CLOCK_EXT_SIZE 16 /* stcke writes 16 bytes */
120 typedef unsigned long long cycles_t
;
122 static inline void get_tod_clock_ext(char *clk
)
124 typedef struct { char _
[STORE_CLOCK_EXT_SIZE
]; } addrtype
;
126 asm volatile("stcke %0" : "=Q" (*(addrtype
*) clk
) : : "cc");
129 static inline unsigned long long get_tod_clock(void)
131 unsigned char clk
[STORE_CLOCK_EXT_SIZE
];
133 get_tod_clock_ext(clk
);
134 return *((unsigned long long *)&clk
[1]);
137 static inline unsigned long long get_tod_clock_fast(void)
139 #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
140 unsigned long long clk
;
142 asm volatile("stckf %0" : "=Q" (clk
) : : "cc");
145 return get_tod_clock();
149 static inline cycles_t
get_cycles(void)
151 return (cycles_t
) get_tod_clock() >> 2;
154 int get_phys_clock(unsigned long long *clock
);
155 void init_cpu_timer(void);
156 unsigned long long monotonic_clock(void);
158 void tod_to_timeval(__u64 todval
, struct timespec64
*xt
);
161 void stck_to_timespec64(unsigned long long stck
, struct timespec64
*ts
)
163 tod_to_timeval(stck
- TOD_UNIX_EPOCH
, ts
);
166 extern u64 sched_clock_base_cc
;
169 * get_clock_monotonic - returns current time in clock rate units
171 * The caller must ensure that preemption is disabled.
172 * The clock and sched_clock_base get changed via stop_machine.
173 * Therefore preemption must be disabled when calling this
174 * function, otherwise the returned value is not guaranteed to
177 static inline unsigned long long get_tod_clock_monotonic(void)
179 return get_tod_clock() - sched_clock_base_cc
;
183 * tod_to_ns - convert a TOD format value to nanoseconds
184 * @todval: to be converted TOD format value
185 * Returns: number of nanoseconds that correspond to the TOD format value
187 * Converting a 64 Bit TOD format value to nanoseconds means that the value
188 * must be divided by 4.096. In order to achieve that we multiply with 125
191 * ns = (todval * 125) >> 9;
193 * In order to avoid an overflow with the multiplication we can rewrite this.
194 * With a split todval == 2^32 * th + tl (th upper 32 bits, tl lower 32 bits)
197 * ns = ((2^32 * th + tl) * 125 ) >> 9;
198 * -> ns = (2^23 * th * 125) + ((tl * 125) >> 9);
201 static inline unsigned long long tod_to_ns(unsigned long long todval
)
203 unsigned long long ns
;
205 ns
= ((todval
>> 32) << 23) * 125;
206 ns
+= ((todval
& 0xffffffff) * 125) >> 9;