RTEMS  5.0.0
timetc.h
1 /*-
2  * ----------------------------------------------------------------------------
3  * "THE BEER-WARE LICENSE" (Revision 42):
4  * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5  * can do whatever you want with this stuff. If we meet some day, and you think
6  * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7  * ----------------------------------------------------------------------------
8  *
9  * $FreeBSD: head/sys/sys/timetc.h 304285 2016-08-17 09:52:09Z kib $
10  */
11 
12 #ifndef _SYS_TIMETC_H_
13 #define _SYS_TIMETC_H_
14 
15 #ifndef __rtems__
16 #ifndef _KERNEL
17 #error "no user-serviceable parts inside"
18 #endif
19 #endif /* __rtems__ */
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 #ifndef __rtems__
36 typedef u_int timecounter_get_t(struct timecounter *);
37 #else /* __rtems__ */
38 typedef uint32_t timecounter_get_t(struct timecounter *);
39 #endif /* __rtems__ */
40 typedef void timecounter_pps_t(struct timecounter *);
41 typedef uint32_t timecounter_fill_vdso_timehands_t(struct vdso_timehands *,
42  struct timecounter *);
43 typedef uint32_t timecounter_fill_vdso_timehands32_t(struct vdso_timehands32 *,
44  struct timecounter *);
45 
46 struct timecounter {
47  timecounter_get_t *tc_get_timecount;
48  /*
49  * This function reads the counter. It is not required to
50  * mask any unimplemented bits out, as long as they are
51  * constant.
52  */
53  timecounter_pps_t *tc_poll_pps;
54  /*
55  * This function is optional. It will be called whenever the
56  * timecounter is rewound, and is intended to check for PPS
57  * events. Normal hardware does not need it but timecounters
58  * which latch PPS in hardware (like sys/pci/xrpu.c) do.
59  */
60  uint32_t tc_counter_mask;
61  /* This mask should mask off any unimplemented bits. */
62  uint64_t tc_frequency;
63  /* Frequency of the counter in Hz. */
64  const char *tc_name;
65  /* Name of the timecounter. */
66  int tc_quality;
67  /*
68  * Used to determine if this timecounter is better than
69  * another timecounter higher means better. Negative
70  * means "only use at explicit request".
71  */
72  u_int tc_flags;
73 #define TC_FLAGS_C2STOP 1 /* Timer dies in C2+. */
74 #define TC_FLAGS_SUSPEND_SAFE 2 /*
75  * Timer functional across
76  * suspend/resume.
77  */
78 
79  void *tc_priv;
80  /* Pointer to the timecounter's private parts. */
81  struct timecounter *tc_next;
82  /* Pointer to the next timecounter. */
83 #ifndef __rtems__
84  timecounter_fill_vdso_timehands_t *tc_fill_vdso_timehands;
85  timecounter_fill_vdso_timehands32_t *tc_fill_vdso_timehands32;
86 #endif /* __rtems__ */
87 };
88 
89 extern struct timecounter *timecounter;
90 extern int tc_min_ticktock_freq; /*
91  * Minimal tc_ticktock() call frequency,
92  * required to handle counter wraps.
93  */
94 
95 u_int64_t tc_getfrequency(void);
96 void tc_init(struct timecounter *tc);
97 void tc_setclock(struct timespec *ts);
98 void tc_ticktock(int cnt);
99 void cpu_tick_calibration(void);
100 
101 #ifdef SYSCTL_DECL
102 SYSCTL_DECL(_kern_timecounter);
103 #endif
104 
105 #endif /* !_SYS_TIMETC_H_ */
Definition: timetc.h:46