2 * SPDX-License-Identifier: Beerware
4 * ----------------------------------------------------------------------------
5 * "THE BEER-WARE LICENSE" (Revision 42):
6 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
7 * can do whatever you want with this stuff. If we meet some day, and you think
8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
9 * ----------------------------------------------------------------------------
14 #ifndef _SYS_TIMETC_H_
15 #define _SYS_TIMETC_H_
18 #error "no user-serviceable parts inside"
22 * `struct timecounter' is the interface between the hardware which implements
23 * a timecounter and the MI code which uses this to keep track of time.
25 * A timecounter is a binary counter which has two properties:
26 * * it runs at a fixed, known frequency.
27 * * it has sufficient bits to not roll over in less than approximately
28 * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta,
29 * for some indeterminate value of delta.)
33 struct vdso_timehands;
34 struct vdso_timehands32;
35 typedef u_int timecounter_get_t(struct timecounter *);
36 typedef void timecounter_pps_t(struct timecounter *);
37 typedef uint32_t timecounter_fill_vdso_timehands_t(struct vdso_timehands *,
38 struct timecounter *);
39 typedef uint32_t timecounter_fill_vdso_timehands32_t(struct vdso_timehands32 *,
40 struct timecounter *);
43 timecounter_get_t *tc_get_timecount;
45 * This function reads the counter. It is not required to
46 * mask any unimplemented bits out, as long as they are
49 timecounter_pps_t *tc_poll_pps;
51 * This function is optional. It will be called whenever the
52 * timecounter is rewound, and is intended to check for PPS
53 * events. Normal hardware does not need it but timecounters
54 * which latch PPS in hardware (like sys/pci/xrpu.c) do.
56 u_int tc_counter_mask;
57 /* This mask should mask off any unimplemented bits. */
58 uint64_t tc_frequency;
59 /* Frequency of the counter in Hz. */
61 /* Name of the timecounter. */
64 * Used to determine if this timecounter is better than
65 * another timecounter higher means better. Negative
66 * means "only use at explicit request".
69 #define TC_FLAGS_C2STOP 1 /* Timer dies in C2+. */
70 #define TC_FLAGS_SUSPEND_SAFE 2 /*
71 * Timer functional across
76 /* Pointer to the timecounter's private parts. */
77 struct timecounter *tc_next;
78 /* Pointer to the next timecounter. */
79 timecounter_fill_vdso_timehands_t *tc_fill_vdso_timehands;
80 timecounter_fill_vdso_timehands32_t *tc_fill_vdso_timehands32;
83 extern struct timecounter *timecounter;
84 extern int tc_min_ticktock_freq; /*
85 * Minimal tc_ticktock() call frequency,
86 * required to handle counter wraps.
89 u_int64_t tc_getfrequency(void);
90 void tc_init(struct timecounter *tc);
91 void tc_setclock(struct timespec *ts);
92 void tc_ticktock(int cnt);
93 void cpu_tick_calibration(void);
96 SYSCTL_DECL(_kern_timecounter);
99 #endif /* !_SYS_TIMETC_H_ */