2 * Copyright (c) 2003 Poul-Henning Kamp
3 * Copyright (c) 2013 iXsystems.com,
4 * author: Alfred Perlstein <alfred@freebsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef _SYS_WATCHDOG_H
32 #define _SYS_WATCHDOG_H
34 #include <sys/ioccom.h>
36 #define _PATH_WATCHDOG "fido"
38 #define WDIOCPATPAT _IOW('W', 42, u_int) /* pat the watchdog */
39 #define WDIOC_SETTIMEOUT _IOW('W', 43, int) /* set/reset the timer */
40 #define WDIOC_GETTIMEOUT _IOR('W', 44, int) /* get total timeout */
41 #define WDIOC_GETTIMELEFT _IOR('W', 45, int) /* get time left */
42 #define WDIOC_GETPRETIMEOUT _IOR('W', 46, int) /* get the pre-timeout */
43 #define WDIOC_SETPRETIMEOUT _IOW('W', 47, int) /* set the pre-timeout */
44 /* set the action when a pre-timeout occurs see: WD_SOFT_* */
45 #define WDIOC_SETPRETIMEOUTACT _IOW('W', 48, int)
47 /* use software watchdog instead of hardware */
48 #define WDIOC_SETSOFT _IOW('W', 49, int)
49 #define WDIOC_SETSOFTTIMEOUTACT _IOW('W', 50, int)
51 #define WD_ACTIVE 0x8000000
53 * Watchdog reset, timeout set to value in WD_INTERVAL field.
54 * The kernel will arm the watchdog and unless the userland
55 * program calls WDIOCPATPAT again before the timer expires
56 * the system will reinitialize.
59 #define WD_PASSIVE 0x0400000
61 * Set the watchdog in passive mode.
62 * The kernel will chose an appropriate timeout duration and
63 * periodically reset the timer provided everything looks all
64 * right to the kernel.
67 #define WD_LASTVAL 0x0200000
69 * Use the already last used timeout value.
70 * The kernel will use as timeout the last valid timeout provided.
73 #define WD_INTERVAL 0x00000ff
75 * Mask for duration bits.
76 * The watchdog will have a nominal patience of 2^N * nanoseconds.
77 * Example: N == 30 gives a patience of 2^30 nanoseconds ~= 1 second.
78 * NB: Expect variance in the +/- 10-20% range.
81 /* Handy macros for humans not used to power of two nanoseconds */
84 #define WD_TO_125MS 27
85 #define WD_TO_250MS 28
86 #define WD_TO_500MS 29
91 #define WD_TO_16SEC 34
92 #define WD_TO_32SEC 35
93 #define WD_TO_64SEC 36
94 #define WD_TO_128SEC 37
96 /* action on pre-timeout trigger */
97 #define WD_SOFT_PANIC 0x01 /* panic */
98 #define WD_SOFT_DDB 0x02 /* enter debugger */
99 #define WD_SOFT_LOG 0x04 /* log(9) */
100 #define WD_SOFT_PRINTF 0x08 /* printf(9) */
101 #define WD_SOFT_MASK 0x0f /* all of the above */
105 #include <sys/eventhandler.h>
107 typedef void (*watchdog_fn)(void *, u_int, int *);
109 EVENTHANDLER_DECLARE(watchdog_list, watchdog_fn);
111 u_int wdog_kern_last_timeout(void);
112 int wdog_kern_pat(u_int utim);
115 #endif /* _SYS_WATCHDOG_H */