1 /*- 2 * SPDX-License-Identifier: Beerware 3 * 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 * ---------------------------------------------------------------------------- 10 * 11 * $FreeBSD$ 12 */ 13 14 #ifndef _SYS_TIMETC_H_ 15 #define _SYS_TIMETC_H_ 16 17 #ifndef _KERNEL 18 #error "no user-serviceable parts inside" 19 #endif 20 21 /*- 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. 24 * 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.) 30 */ 31 32 struct timecounter; 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 *); 41 42 struct timecounter { 43 timecounter_get_t *tc_get_timecount; 44 /* 45 * This function reads the counter. It is not required to 46 * mask any unimplemented bits out, as long as they are 47 * constant. 48 */ 49 timecounter_pps_t *tc_poll_pps; 50 /* 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. 55 */ 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. */ 60 const char *tc_name; 61 /* Name of the timecounter. */ 62 int tc_quality; 63 /* 64 * Used to determine if this timecounter is better than 65 * another timecounter higher means better. Negative 66 * means "only use at explicit request". 67 */ 68 u_int tc_flags; 69 #define TC_FLAGS_C2STOP 1 /* Timer dies in C2+. */ 70 #define TC_FLAGS_SUSPEND_SAFE 2 /* 71 * Timer functional across 72 * suspend/resume. 73 */ 74 75 void *tc_priv; 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; 81 }; 82 83 extern struct timecounter *timecounter; 84 extern int tc_min_ticktock_freq; /* 85 * Minimal tc_ticktock() call frequency, 86 * required to handle counter wraps. 87 */ 88 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); 94 95 #ifdef SYSCTL_DECL 96 SYSCTL_DECL(_kern_timecounter); 97 #endif 98 99 #endif /* !_SYS_TIMETC_H_ */ 100