annotate vordog.c @ 8:a28764b2a28e

modify selection of timeout for 2^n nanoseconds
author Thinker K.F. Li <thinker@branda.to>
date Tue, 08 Jul 2008 17:10:01 +0800
parents 5a281ce7453c
children b4f4a69ea86a
rev   line source
3
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
1 /*-
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
2 * Copyright (c) 2008 Kueifong Li <thinker@branda.to>.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
3 * All rights reserved.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
4 *
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
5 * Redistribution and use in source and binary forms, with or without
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
6 * modification, are permitted provided that the following conditions
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
7 * are met:
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
9 * notice, this list of conditions and the following disclaimer.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
12 * documentation and/or other materials provided with the distribution.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
13 *
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
15 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
24 * POSSIBILITY OF SUCH DAMAGE.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
25 */
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 #include <sys/param.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 #include <sys/bus.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 #include <sys/conf.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 #include <sys/kernel.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 #include <sys/module.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 #include <sys/systm.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 #include <sys/proc.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 #include <sys/ioccom.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 #include <sys/types.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 #include <sys/malloc.h>
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
36 #include <sys/watchdog.h>
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 #include "vordog.h"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38
3
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
39 #if 0
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 #undef __FreeBSD_version
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 #define __FreeBSD_version 800029
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 #endif
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 #define VD_STATUS 0x841
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 #define VD_INITVAL 0x84a
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 #define VD_CTR 0x84b
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
47 /* trigger PCIRST */
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
48 #define VD_TIMER_RST 0xc
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 typedef struct vd_softc {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 struct cdev *_cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 device_t dev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 int open_cnt;
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
54 u_int init_val;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
55 eventhandler_tag wd9_tag;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 } *vd_softc_t;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 #define CDEV_2_SOFTC(_cdev) ((_cdev)->si_drv1)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 vordog_open(struct cdev *dev, int oflags, int devtype, struct thread *td) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 sc = CDEV_2_SOFTC(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 sc->open_cnt++;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 vordog_close(struct cdev *dev, int fflag, int devtype, struct thread *td) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 sc = CDEV_2_SOFTC(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 sc->open_cnt--;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 vordog_go_detach(void) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 devclass_t vd_dc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 device_t vd_dev, nexus_dev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 int r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 vd_dc = devclass_find("vordog");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 if(vd_dc == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 return EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 vd_dev = devclass_get_device(vd_dc, 0);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 if(vd_dev == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 return EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 nexus_dev = device_get_parent(vd_dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 if(nexus_dev == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 return EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 r = device_delete_child(nexus_dev, vd_dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 return r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 static void
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 setup_timer(vordog_cfg_t cfg) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 int val;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 val = cfg->init_val & 0xff;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 outb(VD_INITVAL, val);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 val = 0x80 | ((cfg->unit & 0x3) << 4) | VD_TIMER_RST;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 outb(VD_CTR, val);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 static void
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
113 reset_timer(void) {
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 outb(VD_STATUS, 0xc0);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 static void
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 disable_timer(void) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 outb(VD_CTR, 0);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 outb(VD_STATUS, 0xc0);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 vordog_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 int fflag, struct thread *td) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 int r = 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 vordog_cfg_t cfg;
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
129 static const u_int unit_factors[] = {0, 1, 60, 360};
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 sc = CDEV_2_SOFTC(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 switch(cmd) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 case VDCTL_ENABLE:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 cfg = (vordog_cfg_t)data;
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
135 sc->init_val = (cfg->init_val & 0xff) * unit_factors[cfg->unit];
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 setup_timer(cfg);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 case VDCTL_RESET:
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
139 reset_timer();
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 case VDCTL_DISABLE:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 disable_timer();
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144 default:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 r = EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 return r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 struct cdevsw vordog_cdevsw = {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 .d_version = D_VERSION,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 .d_open = vordog_open,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 .d_close = vordog_close,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 .d_ioctl = vordog_ioctl,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 .d_name = "vordog",
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156 };
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
158 /*
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
159 * Implements watchdog(9) compatible driver.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
160 */
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
161 /*! \brief Initialize timer for an interval in specified seconds.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
162 */
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
163 static int
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
164 vordog_wd9_init(u_int timeout) {
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
165 int val;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
166
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
167 if(timeout < 0 || timeout > 255)
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
168 return EINVAL;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
169
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
170 outb(VD_INITVAL, timeout & 0xff);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
171 val = 0x80 | (VDT_1S << 4) | VD_TIMER_RST;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
172 outb(VD_CTR, val);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
173 return 0;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
174 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
175
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
176 /*! \brief Reset timer before it is timeout.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
177 *
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
178 * It make the timer reload it's value from initial value register.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
179 */
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
180 static void
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
181 vordog_wd9_reset(void) {
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
182 outb(VD_STATUS, 0xc0);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
183 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
184
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
185 /*! \brief Stop counting of watchdog timer.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
186 */
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
187 static void
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
188 vordog_wd9_disable(void) {
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
189 outb(VD_CTR, 0);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
190 outb(VD_STATUS, 0xc0);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
191 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
192
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
193 /*! \brief event handler for watchdog(9).
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
194 *
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
195 * Timeout interval of watchdog(9) is defined by power of 2 nanoseconds.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
196 * Watchdog timer of Vortex86 provides only small range of intervals.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
197 * We use only the timer in seconds to simplize the code. It provides
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
198 * interval 1~255 seconds.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
199 *
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
200 * Since, only SFTMR1_STS is work, in my experience, and it is triggered
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
201 * after 4 times of initial value. So, it only (i * 4) seconds in range
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
202 * of 4 ~ (255 * 4), where i is one of positive integer, are supported.
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
203 *
8
a28764b2a28e modify selection of timeout for 2^n nanoseconds
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
204 * The supported time intervals of watchdog(9) are 2^32~2^39 nanoseconds.
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
205 * vordog used a (i * 4) seconds for 2^n seconds while i * 4 seconds is
8
a28764b2a28e modify selection of timeout for 2^n nanoseconds
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
206 * closest to 2^n nanoseconds. The variances between i * 4 seconds and
a28764b2a28e modify selection of timeout for 2^n nanoseconds
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
207 * 2^n nanoseconds are less than 7% (6.8678%).
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
208 */
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
209 static void
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
210 vordog_wd9_evh(void *priv_data, u_int cmd, int *error) {
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
211 vd_softc_t sc;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
212 u_int timeout, u;
8
a28764b2a28e modify selection of timeout for 2^n nanoseconds
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
213 /* 2^32, 2^33, ..., 2^39 nanoseconds */
a28764b2a28e modify selection of timeout for 2^n nanoseconds
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
214 static const int timeouts[] = { 1, 2, 4, 9, 17, 34, 69, 137};
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
215
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
216 sc = (vd_softc_t)priv_data;
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
217
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
218 u = cmd & WD_INTERVAL;
8
a28764b2a28e modify selection of timeout for 2^n nanoseconds
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
219 if(u < 32 || u > 39) {
7
5a281ce7453c Add comments
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
220 /* Out of range! Can not be configured. */
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
221 vordog_wd9_disable();
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
222 sc->init_val = 0;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
223 return;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
224 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
225
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
226 timeout = timeouts[u - 31];
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
227 if(timeout != sc->init_val) {
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
228 vordog_wd9_init(timeout);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
229 sc->init_val = timeout;
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
230 } else {
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
231 vordog_wd9_reset();
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
232 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
233 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
234
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
235 static void
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
236 vordog_wd9_register(vd_softc_t sc) {
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
237 sc->wd9_tag = \
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
238 EVENTHANDLER_REGISTER(watchdog_list, vordog_wd9_evh, sc, 0);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
239 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
240
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
241 static void
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
242 vordog_wd9_unregister(vd_softc_t sc) {
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
243 EVENTHANDLER_DEREGISTER(watchdog_list, sc->wd9_tag);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
244 }
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
245
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
246
5
e59963b503cb Remove tedious messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
247 /* Following implements a new bus device.
e59963b503cb Remove tedious messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
248 * It is attached under nexus bus, an on board device as `vordog0'.
e59963b503cb Remove tedious messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
249 */
e59963b503cb Remove tedious messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
250
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
251 static void vordog_identify(driver_t *driver, device_t parent) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
252 device_t vordog;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
253
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
254 /* make sure vordog device is not in the bus. */
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
255 vordog = device_find_child(parent, "vordog", 0);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
256 if(vordog != NULL)
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
257 return;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
258 vordog = BUS_ADD_CHILD(parent, 10, "vordog", 0);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
259 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
260
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
261 static int vordog_probe(device_t dev) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
262 int b;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
263
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
264 b = inb(VD_INITVAL);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
265 if(b != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
266 return EINVAL;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
267 b = inb(VD_CTR);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
268 if(b != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
269 return EINVAL;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270 b = inb(VD_STATUS);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
271 if(b != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
272 return EINVAL;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
273 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
275
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
276 static int vordog_attach(device_t dev) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
277 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
278 struct cdev *_cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280 sc = (vd_softc_t)malloc(sizeof(struct vd_softc), M_TEMP, M_WAITOK);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
281 if(sc == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
282 return ENOMEM;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
283
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
284 _cdev = make_dev(&vordog_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "vordog0");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
285 if(_cdev == NULL) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
286 free(sc, M_TEMP);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
287 return EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
288 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
289
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 sc->_cdev = _cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291 sc->dev = dev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
293 device_set_softc(dev, sc);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294 CDEV_2_SOFTC(_cdev) = sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
295
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
296 sc->open_cnt = 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
297 sc->init_val = 0;
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
298 sc->wd9_tag = NULL;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
300 device_set_desc(dev, "Watchdog of Vortex86 SoC");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
301 device_printf(dev, "<Vortex86 SoC watchdog> at port 0x%x\n", VD_STATUS);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
302
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
303 vordog_wd9_register(sc);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
304
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
305 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
306 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
307
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
308 static int vordog_detach(device_t dev) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
309 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
310 struct cdev *_cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
311
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
312 sc = device_get_softc(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
313 if(sc->open_cnt != 0)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
314 return EBUSY;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
315
6
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
316 disable_timer();
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
317
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
318 vordog_wd9_unregister(sc);
76ce6e6624b8 Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
319
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
320 _cdev = sc->_cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
321
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
322 destroy_dev(_cdev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
323
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
324 free(sc, M_TEMP);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
325
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
326 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
328
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
329 static device_method_t vordog_methods[] = {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
330 DEVMETHOD(device_identify, vordog_identify),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
331 DEVMETHOD(device_probe, vordog_probe),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
332 DEVMETHOD(device_attach, vordog_attach),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
333 DEVMETHOD(device_detach, vordog_detach),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
334 {0, 0}
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
335 };
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
337 static driver_t vordog_driver = {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
338 "vordog",
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
339 vordog_methods,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
340 0,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341 };
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
344 vordog_evh(module_t mod, int cmd, void *arg) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345 int r = 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
346
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347 switch(cmd) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
348 case MOD_LOAD:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
349 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
350 case MOD_UNLOAD:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
351 vordog_go_detach(); /* remove device from parent */
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
352 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
353 case MOD_SHUTDOWN:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
354 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
355 default:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
356 r = EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
357 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
358 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
359 return r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
360 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
361
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
362 static devclass_t vordog_devclass;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
363
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
364 DRIVER_MODULE(vordog, nexus, vordog_driver, vordog_devclass,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
365 vordog_evh, NULL);