xref: /openbmc/linux/include/vdso/datapage.h (revision dc6a81c3)
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/bits.h>
8 #include <linux/time.h>
9 #include <linux/types.h>
10 
11 #define VDSO_BASES	(CLOCK_TAI + 1)
12 #define VDSO_HRES	(BIT(CLOCK_REALTIME)		| \
13 			 BIT(CLOCK_MONOTONIC)		| \
14 			 BIT(CLOCK_BOOTTIME)		| \
15 			 BIT(CLOCK_TAI))
16 #define VDSO_COARSE	(BIT(CLOCK_REALTIME_COARSE)	| \
17 			 BIT(CLOCK_MONOTONIC_COARSE))
18 #define VDSO_RAW	(BIT(CLOCK_MONOTONIC_RAW))
19 
20 #define CS_HRES_COARSE	0
21 #define CS_RAW		1
22 #define CS_BASES	(CS_RAW + 1)
23 
24 #define VCLOCK_TIMENS	UINT_MAX
25 
26 /**
27  * struct vdso_timestamp - basetime per clock_id
28  * @sec:	seconds
29  * @nsec:	nanoseconds
30  *
31  * There is one vdso_timestamp object in vvar for each vDSO-accelerated
32  * clock_id. For high-resolution clocks, this encodes the time
33  * corresponding to vdso_data.cycle_last. For coarse clocks this encodes
34  * the actual time.
35  *
36  * To be noticed that for highres clocks nsec is left-shifted by
37  * vdso_data.cs[x].shift.
38  */
39 struct vdso_timestamp {
40 	u64	sec;
41 	u64	nsec;
42 };
43 
44 /**
45  * struct vdso_data - vdso datapage representation
46  * @seq:		timebase sequence counter
47  * @clock_mode:		clock mode
48  * @cycle_last:		timebase at clocksource init
49  * @mask:		clocksource mask
50  * @mult:		clocksource multiplier
51  * @shift:		clocksource shift
52  * @basetime[clock_id]:	basetime per clock_id
53  * @offset[clock_id]:	time namespace offset per clock_id
54  * @tz_minuteswest:	minutes west of Greenwich
55  * @tz_dsttime:		type of DST correction
56  * @hrtimer_res:	hrtimer resolution
57  * @__unused:		unused
58  *
59  * vdso_data will be accessed by 64 bit and compat code at the same time
60  * so we should be careful before modifying this structure.
61  *
62  * @basetime is used to store the base time for the system wide time getter
63  * VVAR page.
64  *
65  * @offset is used by the special time namespace VVAR pages which are
66  * installed instead of the real VVAR page. These namespace pages must set
67  * @seq to 1 and @clock_mode to VLOCK_TIMENS to force the code into the
68  * time namespace slow path. The namespace aware functions retrieve the
69  * real system wide VVAR page, read host time and add the per clock offset.
70  * For clocks which are not affected by time namespace adjustment the
71  * offset must be zero.
72  */
73 struct vdso_data {
74 	u32			seq;
75 
76 	s32			clock_mode;
77 	u64			cycle_last;
78 	u64			mask;
79 	u32			mult;
80 	u32			shift;
81 
82 	union {
83 		struct vdso_timestamp	basetime[VDSO_BASES];
84 		struct timens_offset	offset[VDSO_BASES];
85 	};
86 
87 	s32			tz_minuteswest;
88 	s32			tz_dsttime;
89 	u32			hrtimer_res;
90 	u32			__unused;
91 };
92 
93 /*
94  * We use the hidden visibility to prevent the compiler from generating a GOT
95  * relocation. Not only is going through a GOT useless (the entry couldn't and
96  * must not be overridden by another library), it does not even work: the linker
97  * cannot generate an absolute address to the data page.
98  *
99  * With the hidden visibility, the compiler simply generates a PC-relative
100  * relocation, and this is what we need.
101  */
102 extern struct vdso_data _vdso_data[CS_BASES] __attribute__((visibility("hidden")));
103 
104 #endif /* !__ASSEMBLY__ */
105 
106 #endif /* __VDSO_DATAPAGE_H */
107