xref: /linux/include/vdso/datapage.h (revision 44f57d788e7deecb504843534081d3449c2eede9)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __VDSO_DATAPAGE_H
3 #define __VDSO_DATAPAGE_H
4 
5 #ifdef __KERNEL__
6 
7 #ifndef __ASSEMBLY__
8 
9 #include <linux/bits.h>
10 #include <linux/time.h>
11 #include <linux/types.h>
12 
13 #define VDSO_BASES	(CLOCK_TAI + 1)
14 #define VDSO_HRES	(BIT(CLOCK_REALTIME)		| \
15 			 BIT(CLOCK_MONOTONIC)		| \
16 			 BIT(CLOCK_BOOTTIME)		| \
17 			 BIT(CLOCK_TAI))
18 #define VDSO_COARSE	(BIT(CLOCK_REALTIME_COARSE)	| \
19 			 BIT(CLOCK_MONOTONIC_COARSE))
20 #define VDSO_RAW	(BIT(CLOCK_MONOTONIC_RAW))
21 
22 #define CS_HRES_COARSE	0
23 #define CS_RAW		1
24 #define CS_BASES	(CS_RAW + 1)
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  * @tz_minuteswest:	minutes west of Greenwich
54  * @tz_dsttime:		type of DST correction
55  * @hrtimer_res:	hrtimer resolution
56  * @__unused:		unused
57  *
58  * vdso_data will be accessed by 64 bit and compat code at the same time
59  * so we should be careful before modifying this structure.
60  */
61 struct vdso_data {
62 	u32			seq;
63 
64 	s32			clock_mode;
65 	u64			cycle_last;
66 	u64			mask;
67 	u32			mult;
68 	u32			shift;
69 
70 	struct vdso_timestamp	basetime[VDSO_BASES];
71 
72 	s32			tz_minuteswest;
73 	s32			tz_dsttime;
74 	u32			hrtimer_res;
75 	u32			__unused;
76 };
77 
78 /*
79  * We use the hidden visibility to prevent the compiler from generating a GOT
80  * relocation. Not only is going through a GOT useless (the entry couldn't and
81  * must not be overridden by another library), it does not even work: the linker
82  * cannot generate an absolute address to the data page.
83  *
84  * With the hidden visibility, the compiler simply generates a PC-relative
85  * relocation, and this is what we need.
86  */
87 extern struct vdso_data _vdso_data[CS_BASES] __attribute__((visibility("hidden")));
88 
89 #endif /* !__ASSEMBLY__ */
90 
91 #endif /* __KERNEL__ */
92 
93 #endif /* __VDSO_DATAPAGE_H */
94