xref: /netbsd-src/sys/external/bsd/drm2/include/linux/hrtimer.h (revision 147f7663cf2cbe2cc5e5fbd2b3d4b5956344b310)
1 /*	$NetBSD: hrtimer.h,v 1.7 2021/12/19 11:55:47 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Taylor R. Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LINUX_HRTIMER_H_
33 #define _LINUX_HRTIMER_H_
34 
35 #include <sys/types.h>
36 
37 #include <sys/callout.h>
38 
39 #include <linux/ktime.h>
40 #include <linux/timer.h>
41 
42 enum hrtimer_mode {
43 	HRTIMER_MODE_ABS,
44 	HRTIMER_MODE_REL,
45 	HRTIMER_MODE_REL_PINNED,
46 };
47 
48 struct hrtimer {
49 	enum hrtimer_restart (*function)(struct hrtimer *);
50 
51 	struct callout		hrt_ch;
52 	enum hrtimer_mode	hrt_mode;
53 	ktime_t			hrt_expires;
54 };
55 
56 enum hrtimer_restart {
57 	HRTIMER_NORESTART,
58 	HRTIMER_RESTART,
59 };
60 
61 #define	hrtimer_active		linux_hrtimer_active
62 #define	hrtimer_add_expires_ns	linux_hrtimer_add_expires_ns
63 #define	hrtimer_cancel		linux_hrtimer_cancel
64 #define	hrtimer_forward		linux_hrtimer_forward
65 #define	hrtimer_forward_now	linux_hrtimer_forward_now
66 #define	hrtimer_init		linux_hrtimer_init
67 #define	hrtimer_set_expires	linux_hrtimer_set_expiresp
68 #define	hrtimer_start		linux_hrtimer_start
69 #define	hrtimer_start_range_ns	linux_hrtimer_start_range_ns
70 
71 void hrtimer_init(struct hrtimer *, clockid_t, enum hrtimer_mode);
72 void hrtimer_set_expires(struct hrtimer *, ktime_t);
73 void hrtimer_add_expires_ns(struct hrtimer *, uint64_t);
74 void hrtimer_start(struct hrtimer *, ktime_t, enum hrtimer_mode);
75 void hrtimer_start_range_ns(struct hrtimer *, ktime_t, uint64_t,
76     enum hrtimer_mode);
77 int hrtimer_cancel(struct hrtimer *);
78 bool hrtimer_active(struct hrtimer *);
79 uint64_t hrtimer_forward(struct hrtimer *, ktime_t, ktime_t);
80 uint64_t hrtimer_forward_now(struct hrtimer *, ktime_t);
81 
82 #endif  /* _LINUX_HRTIMER_H_ */
83