Deleted Added
full compact
watchdog.c (167950) watchdog.c (221121)
1/*-
2 * Copyright (c) 2004 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2004 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/watchdog/watchdog.c 167950 2007-03-27 21:03:37Z n_hibma $");
29__FBSDID("$FreeBSD: head/sys/dev/watchdog/watchdog.c 221121 2011-04-27 16:43:03Z attilio $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/conf.h>
34#include <sys/uio.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>
37#include <sys/module.h>
38#include <sys/watchdog.h>
39#include <sys/bus.h>
40#include <machine/bus.h>
41
42static struct cdev *wd_dev;
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/conf.h>
34#include <sys/uio.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>
37#include <sys/module.h>
38#include <sys/watchdog.h>
39#include <sys/bus.h>
40#include <machine/bus.h>
41
42static struct cdev *wd_dev;
43static volatile u_int wd_last_u;
43
44static int
44
45static int
46kern_do_pat(u_int utim)
47{
48 int error;
49
50 if ((utim & WD_LASTVAL) != 0 && (utim & WD_INTERVAL) > 0)
51 return (EINVAL);
52
53 if ((utim & WD_LASTVAL) != 0) {
54 MPASS((wd_last_u & ~WD_INTERVAL) == 0);
55 utim &= ~WD_LASTVAL;
56 utim |= wd_last_u;
57 } else
58 wd_last_u = (utim & WD_INTERVAL);
59 if ((utim & WD_INTERVAL) == WD_TO_NEVER) {
60 utim = 0;
61
62 /* Assume all is well; watchdog signals failure. */
63 error = 0;
64 } else {
65 /* Assume no watchdog available; watchdog flags success */
66 error = EOPNOTSUPP;
67 }
68 EVENTHANDLER_INVOKE(watchdog_list, utim, &error);
69 return (error);
70}
71
72static int
45wd_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data,
46 int flags __unused, struct thread *td)
47{
73wd_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data,
74 int flags __unused, struct thread *td)
75{
48 int error;
49 u_int u;
50
51 if (cmd != WDIOCPATPAT)
52 return (ENOIOCTL);
53 u = *(u_int *)data;
76 u_int u;
77
78 if (cmd != WDIOCPATPAT)
79 return (ENOIOCTL);
80 u = *(u_int *)data;
54 if (u & ~(WD_ACTIVE | WD_PASSIVE | WD_INTERVAL))
81 if (u & ~(WD_ACTIVE | WD_PASSIVE | WD_LASTVAL | WD_INTERVAL))
55 return (EINVAL);
56 if ((u & (WD_ACTIVE | WD_PASSIVE)) == (WD_ACTIVE | WD_PASSIVE))
57 return (EINVAL);
82 return (EINVAL);
83 if ((u & (WD_ACTIVE | WD_PASSIVE)) == (WD_ACTIVE | WD_PASSIVE))
84 return (EINVAL);
58 if ((u & (WD_ACTIVE | WD_PASSIVE)) == 0 && (u & WD_INTERVAL) > 0)
85 if ((u & (WD_ACTIVE | WD_PASSIVE)) == 0 && ((u & WD_INTERVAL) > 0 ||
86 (u & WD_LASTVAL) != 0))
59 return (EINVAL);
60 if (u & WD_PASSIVE)
61 return (ENOSYS); /* XXX Not implemented yet */
87 return (EINVAL);
88 if (u & WD_PASSIVE)
89 return (ENOSYS); /* XXX Not implemented yet */
62 if ((u & WD_INTERVAL) == WD_TO_NEVER) {
63 u = 0;
64 /* Assume all is well; watchdog signals failure. */
65 error = 0;
66 } else {
67 /* Assume no watchdog available; watchdog flags success */
68 error = EOPNOTSUPP;
69 }
70 EVENTHANDLER_INVOKE(watchdog_list, u, &error);
71 return (error);
90 u &= ~(WD_ACTIVE | WD_PASSIVE);
91
92 return (kern_do_pat(u));
72}
73
93}
94
95u_int
96wdog_kern_last_timeout(void)
97{
98
99 return (wd_last_u);
100}
101
102int
103wdog_kern_pat(u_int utim)
104{
105
106 if (utim & ~(WD_LASTVAL | WD_INTERVAL))
107 return (EINVAL);
108
109 return (kern_do_pat(utim));
110}
111
74static struct cdevsw wd_cdevsw = {
75 .d_version = D_VERSION,
76 .d_ioctl = wd_ioctl,
77 .d_name = "watchdog",
78};
79
80static int
81watchdog_modevent(module_t mod __unused, int type, void *data __unused)

--- 17 unchanged lines hidden ---
112static struct cdevsw wd_cdevsw = {
113 .d_version = D_VERSION,
114 .d_ioctl = wd_ioctl,
115 .d_name = "watchdog",
116};
117
118static int
119watchdog_modevent(module_t mod __unused, int type, void *data __unused)

--- 17 unchanged lines hidden ---