1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2012 - 2014 Cisco Systems
4  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
5  */
6 
7 #ifndef __TIMER_INTERNAL_H__
8 #define __TIMER_INTERNAL_H__
9 #include <linux/list.h>
10 
11 #define TIMER_MULTIPLIER 256
12 #define TIMER_MIN_DELTA  500
13 
14 enum time_travel_mode {
15 	TT_MODE_OFF,
16 	TT_MODE_BASIC,
17 	TT_MODE_INFCPU,
18 	TT_MODE_EXTERNAL,
19 };
20 
21 #ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT
22 struct time_travel_event {
23 	unsigned long long time;
24 	void (*fn)(struct time_travel_event *d);
25 	struct list_head list;
26 	bool pending, onstack;
27 };
28 
29 extern enum time_travel_mode time_travel_mode;
30 
31 void time_travel_sleep(unsigned long long duration);
32 
33 static inline void
time_travel_set_event_fn(struct time_travel_event * e,void (* fn)(struct time_travel_event * d))34 time_travel_set_event_fn(struct time_travel_event *e,
35 			 void (*fn)(struct time_travel_event *d))
36 {
37 	e->fn = fn;
38 }
39 
40 void __time_travel_propagate_time(void);
41 
time_travel_propagate_time(void)42 static inline void time_travel_propagate_time(void)
43 {
44 	if (time_travel_mode == TT_MODE_EXTERNAL)
45 		__time_travel_propagate_time();
46 }
47 
48 void __time_travel_wait_readable(int fd);
49 
time_travel_wait_readable(int fd)50 static inline void time_travel_wait_readable(int fd)
51 {
52 	if (time_travel_mode == TT_MODE_EXTERNAL)
53 		__time_travel_wait_readable(fd);
54 }
55 
56 void time_travel_add_irq_event(struct time_travel_event *e);
57 #else
58 struct time_travel_event {
59 };
60 
61 #define time_travel_mode TT_MODE_OFF
62 
time_travel_sleep(unsigned long long duration)63 static inline void time_travel_sleep(unsigned long long duration)
64 {
65 }
66 
67 /* this is a macro so the event/function need not exist */
68 #define time_travel_set_event_fn(e, fn) do {} while (0)
69 
time_travel_propagate_time(void)70 static inline void time_travel_propagate_time(void)
71 {
72 }
73 
time_travel_wait_readable(int fd)74 static inline void time_travel_wait_readable(int fd)
75 {
76 }
77 #endif /* CONFIG_UML_TIME_TRAVEL_SUPPORT */
78 
79 /*
80  * Without CONFIG_UML_TIME_TRAVEL_SUPPORT this is a linker error if used,
81  * which is intentional since we really shouldn't link it in that case.
82  */
83 void time_travel_ndelay(unsigned long nsec);
84 #endif /* __TIMER_INTERNAL_H__ */
85