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

TOMOYO Linux Cross Reference
Linux/arch/s390/include/asm/timex.h

Version: ~ [ linux-5.2-rc1 ] ~ [ linux-5.1.2 ] ~ [ linux-5.0.16 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.43 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.119 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.176 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.179 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.139 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.67 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  S390 version
  3  *    Copyright IBM Corp. 1999
  4  *
  5  *  Derived from "include/asm-i386/timex.h"
  6  *    Copyright (C) 1992, Linus Torvalds
  7  */
  8 
  9 #ifndef _ASM_S390_TIMEX_H
 10 #define _ASM_S390_TIMEX_H
 11 
 12 #include <asm/lowcore.h>
 13 #include <linux/time64.h>
 14 
 15 /* The value of the TOD clock for 1.1.1970. */
 16 #define TOD_UNIX_EPOCH 0x7d91048bca000000ULL
 17 
 18 /* Inline functions for clock register access. */
 19 static inline int set_tod_clock(__u64 time)
 20 {
 21         int cc;
 22 
 23         asm volatile(
 24                 "   sck   %1\n"
 25                 "   ipm   %0\n"
 26                 "   srl   %0,28\n"
 27                 : "=d" (cc) : "Q" (time) : "cc");
 28         return cc;
 29 }
 30 
 31 static inline int store_tod_clock(__u64 *time)
 32 {
 33         int cc;
 34 
 35         asm volatile(
 36                 "   stck  %1\n"
 37                 "   ipm   %0\n"
 38                 "   srl   %0,28\n"
 39                 : "=d" (cc), "=Q" (*time) : : "cc");
 40         return cc;
 41 }
 42 
 43 static inline void set_clock_comparator(__u64 time)
 44 {
 45         asm volatile("sckc %0" : : "Q" (time));
 46 }
 47 
 48 static inline void store_clock_comparator(__u64 *time)
 49 {
 50         asm volatile("stckc %0" : "=Q" (*time));
 51 }
 52 
 53 void clock_comparator_work(void);
 54 
 55 void __init time_early_init(void);
 56 
 57 extern unsigned char ptff_function_mask[16];
 58 
 59 /* Function codes for the ptff instruction. */
 60 #define PTFF_QAF        0x00    /* query available functions */
 61 #define PTFF_QTO        0x01    /* query tod offset */
 62 #define PTFF_QSI        0x02    /* query steering information */
 63 #define PTFF_QUI        0x04    /* query UTC 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 */
 68 
 69 /* Query TOD offset result */
 70 struct ptff_qto {
 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;
 75 } __packed;
 76 
 77 static inline int ptff_query(unsigned int nr)
 78 {
 79         unsigned char *ptr;
 80 
 81         ptr = ptff_function_mask + (nr >> 3);
 82         return (*ptr & (0x80 >> (nr & 7))) != 0;
 83 }
 84 
 85 /* Query UTC information result */
 86 struct ptff_qui {
 87         unsigned int tm : 2;
 88         unsigned int ts : 2;
 89         unsigned int : 28;
 90         unsigned int pad_0x04;
 91         unsigned long leap_event;
 92         short old_leap;
 93         short new_leap;
 94         unsigned int pad_0x14;
 95         unsigned long prt[5];
 96         unsigned long cst[3];
 97         unsigned int skew;
 98         unsigned int pad_0x5c[41];
 99 } __packed;
100 
101 /*
102  * ptff - Perform timing facility function
103  * @ptff_block: Pointer to ptff parameter block
104  * @len: Length of parameter block
105  * @func: Function code
106  * Returns: Condition code (0 on success)
107  */
108 #define ptff(ptff_block, len, func)                                     \
109 ({                                                                      \
110         struct addrtype { char _[len]; };                               \
111         register unsigned int reg0 asm("") = func;                     \
112         register unsigned long reg1 asm("1") = (unsigned long) (ptff_block);\
113         int rc;                                                         \
114                                                                         \
115         asm volatile(                                                   \
116                 "       .word   0x0104\n"                               \
117                 "       ipm     %0\n"                                   \
118                 "       srl     %0,28\n"                                \
119                 : "=d" (rc), "+m" (*(struct addrtype *) reg1)           \
120                 : "d" (reg0), "d" (reg1) : "cc");                       \
121         rc;                                                             \
122 })
123 
124 static inline unsigned long long local_tick_disable(void)
125 {
126         unsigned long long old;
127 
128         old = S390_lowcore.clock_comparator;
129         S390_lowcore.clock_comparator = -1ULL;
130         set_clock_comparator(S390_lowcore.clock_comparator);
131         return old;
132 }
133 
134 static inline void local_tick_enable(unsigned long long comp)
135 {
136         S390_lowcore.clock_comparator = comp;
137         set_clock_comparator(S390_lowcore.clock_comparator);
138 }
139 
140 #define CLOCK_TICK_RATE         1193180 /* Underlying HZ */
141 #define STORE_CLOCK_EXT_SIZE    16      /* stcke writes 16 bytes */
142 
143 typedef unsigned long long cycles_t;
144 
145 static inline void get_tod_clock_ext(char *clk)
146 {
147         typedef struct { char _[STORE_CLOCK_EXT_SIZE]; } addrtype;
148 
149         asm volatile("stcke %0" : "=Q" (*(addrtype *) clk) : : "cc");
150 }
151 
152 static inline unsigned long long get_tod_clock(void)
153 {
154         unsigned char clk[STORE_CLOCK_EXT_SIZE];
155 
156         get_tod_clock_ext(clk);
157         return *((unsigned long long *)&clk[1]);
158 }
159 
160 static inline unsigned long long get_tod_clock_fast(void)
161 {
162 #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
163         unsigned long long clk;
164 
165         asm volatile("stckf %0" : "=Q" (clk) : : "cc");
166         return clk;
167 #else
168         return get_tod_clock();
169 #endif
170 }
171 
172 static inline cycles_t get_cycles(void)
173 {
174         return (cycles_t) get_tod_clock() >> 2;
175 }
176 
177 int get_phys_clock(unsigned long long *clock);
178 void init_cpu_timer(void);
179 unsigned long long monotonic_clock(void);
180 
181 void tod_to_timeval(__u64 todval, struct timespec64 *xt);
182 
183 static inline
184 void stck_to_timespec64(unsigned long long stck, struct timespec64 *ts)
185 {
186         tod_to_timeval(stck - TOD_UNIX_EPOCH, ts);
187 }
188 
189 extern u64 sched_clock_base_cc;
190 
191 /**
192  * get_clock_monotonic - returns current time in clock rate units
193  *
194  * The caller must ensure that preemption is disabled.
195  * The clock and sched_clock_base get changed via stop_machine.
196  * Therefore preemption must be disabled when calling this
197  * function, otherwise the returned value is not guaranteed to
198  * be monotonic.
199  */
200 static inline unsigned long long get_tod_clock_monotonic(void)
201 {
202         return get_tod_clock() - sched_clock_base_cc;
203 }
204 
205 /**
206  * tod_to_ns - convert a TOD format value to nanoseconds
207  * @todval: to be converted TOD format value
208  * Returns: number of nanoseconds that correspond to the TOD format value
209  *
210  * Converting a 64 Bit TOD format value to nanoseconds means that the value
211  * must be divided by 4.096. In order to achieve that we multiply with 125
212  * and divide by 512:
213  *
214  *    ns = (todval * 125) >> 9;
215  *
216  * In order to avoid an overflow with the multiplication we can rewrite this.
217  * With a split todval == 2^32 * th + tl (th upper 32 bits, tl lower 32 bits)
218  * we end up with
219  *
220  *    ns = ((2^32 * th + tl) * 125 ) >> 9;
221  * -> ns = (2^23 * th * 125) + ((tl * 125) >> 9);
222  *
223  */
224 static inline unsigned long long tod_to_ns(unsigned long long todval)
225 {
226         unsigned long long ns;
227 
228         ns = ((todval >> 32) << 23) * 125;
229         ns += ((todval & 0xffffffff) * 125) >> 9;
230         return ns;
231 }
232 
233 #endif
234 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp