• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __VDSO_DATAPAGE_H
3 #define __VDSO_DATAPAGE_H
4 
5 #ifndef __ASSEMBLY__
6 
7 #include <linux/compiler.h>
8 #include <uapi/linux/time.h>
9 #include <uapi/linux/types.h>
10 #include <uapi/asm-generic/errno-base.h>
11 
12 #include <vdso/bits.h>
13 #include <vdso/clocksource.h>
14 #include <vdso/ktime.h>
15 #include <vdso/limits.h>
16 #include <vdso/math64.h>
17 #include <vdso/processor.h>
18 #include <vdso/time.h>
19 #include <vdso/time32.h>
20 #include <vdso/time64.h>
21 
22 #define VDSO_BASES	(CLOCK_TAI + 1)
23 #define VDSO_HRES	(BIT(CLOCK_REALTIME)		| \
24 			 BIT(CLOCK_MONOTONIC)		| \
25 			 BIT(CLOCK_BOOTTIME)		| \
26 			 BIT(CLOCK_TAI))
27 #define VDSO_COARSE	(BIT(CLOCK_REALTIME_COARSE)	| \
28 			 BIT(CLOCK_MONOTONIC_COARSE))
29 #define VDSO_RAW	(BIT(CLOCK_MONOTONIC_RAW))
30 
31 #define CS_HRES_COARSE	0
32 #define CS_RAW		1
33 #define CS_BASES	(CS_RAW + 1)
34 
35 /**
36  * struct vdso_timestamp - basetime per clock_id
37  * @sec:	seconds
38  * @nsec:	nanoseconds
39  *
40  * There is one vdso_timestamp object in vvar for each vDSO-accelerated
41  * clock_id. For high-resolution clocks, this encodes the time
42  * corresponding to vdso_data.cycle_last. For coarse clocks this encodes
43  * the actual time.
44  *
45  * To be noticed that for highres clocks nsec is left-shifted by
46  * vdso_data.cs[x].shift.
47  */
48 struct vdso_timestamp {
49 	u64	sec;
50 	u64	nsec;
51 };
52 
53 /**
54  * struct vdso_data - vdso datapage representation
55  * @seq:		timebase sequence counter
56  * @clock_mode:		clock mode
57  * @cycle_last:		timebase at clocksource init
58  * @mask:		clocksource mask
59  * @mult:		clocksource multiplier
60  * @shift:		clocksource shift
61  * @basetime[clock_id]:	basetime per clock_id
62  * @tz_minuteswest:	minutes west of Greenwich
63  * @tz_dsttime:		type of DST correction
64  * @hrtimer_res:	hrtimer resolution
65  * @__unused:		unused
66  *
67  * vdso_data will be accessed by 64 bit and compat code at the same time
68  * so we should be careful before modifying this structure.
69  */
70 struct vdso_data {
71 	u32			seq;
72 
73 	s32			clock_mode;
74 	u64			cycle_last;
75 	u64			mask;
76 	u32			mult;
77 	u32			shift;
78 
79 	struct vdso_timestamp	basetime[VDSO_BASES];
80 
81 	s32			tz_minuteswest;
82 	s32			tz_dsttime;
83 	u32			hrtimer_res;
84 	u32			__unused;
85 };
86 
87 /*
88  * We use the hidden visibility to prevent the compiler from generating a GOT
89  * relocation. Not only is going through a GOT useless (the entry couldn't and
90  * must not be overridden by another library), it does not even work: the linker
91  * cannot generate an absolute address to the data page.
92  *
93  * With the hidden visibility, the compiler simply generates a PC-relative
94  * relocation, and this is what we need.
95  */
96 extern struct vdso_data _vdso_data[CS_BASES] __attribute__((visibility("hidden")));
97 
98 /*
99  * The generic vDSO implementation requires that gettimeofday.h
100  * provides:
101  * - __arch_get_vdso_data(): to get the vdso datapage.
102  * - __arch_get_hw_counter(): to get the hw counter based on the
103  *   clock_mode.
104  * - gettimeofday_fallback(): fallback for gettimeofday.
105  * - clock_gettime_fallback(): fallback for clock_gettime.
106  * - clock_getres_fallback(): fallback for clock_getres.
107  */
108 #ifdef ENABLE_COMPAT_VDSO
109 #include <asm/vdso/compat_gettimeofday.h>
110 #else
111 #include <asm/vdso/gettimeofday.h>
112 #endif /* ENABLE_COMPAT_VDSO */
113 
114 #endif /* !__ASSEMBLY__ */
115 
116 #endif /* __VDSO_DATAPAGE_H */
117