Mercurial > vordog
annotate vordog.c @ 6:76ce6e6624b8
Make vordog compatible with watchdog(9).
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 08 Jul 2008 14:41:47 +0800 |
parents | e59963b503cb |
children | 5a281ce7453c |
rev | line source |
---|---|
3 | 1 /*- |
2 * Copyright (c) 2008 Kueifong Li <thinker@branda.to>. | |
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 | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
15 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
24 * POSSIBILITY OF SUCH DAMAGE. | |
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 | 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 |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
158 /* Implements watchdog(9) compatible driver. */ |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
159 static int |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
160 vordog_wd9_init(int timeout) { |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
161 int val; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
162 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
163 if(timeout < 0 || timeout > 255) |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
164 return EINVAL; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
165 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
166 outb(VD_INITVAL, timeout & 0xff); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
167 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
|
168 outb(VD_CTR, val); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
169 return 0; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
170 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
171 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
172 static void |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
173 vordog_wd9_reset(void) { |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
174 outb(VD_STATUS, 0xc0); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
175 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
176 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
177 static void |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
178 vordog_wd9_disable(void) { |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
179 outb(VD_CTR, 0); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
180 outb(VD_STATUS, 0xc0); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
181 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
182 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
183 static void |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
184 vordog_wd9_evh(void *private, u_int cmd, int *error) { |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
185 vd_softc_t sc; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
186 u_int timeout, u; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
187 static const int timeouts[] = { 1, 2, 3, 5, 9, 18, 35, 69, 138}; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
188 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
189 sc = (vd_softc_t)private; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
190 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
191 u = cmd & WD_INTERVAL; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
192 if(u < 31 || u > 39) { |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
193 vordog_wd9_disable(); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
194 sc->init_val = 0; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
195 return; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
196 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
197 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
198 timeout = timeouts[u - 31]; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
199 if(timeout != sc->init_val) { |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
200 vordog_wd9_init(timeout); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
201 sc->init_val = timeout; |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
202 } else { |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
203 vordog_wd9_reset(); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
204 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
205 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
206 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
207 static void |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
208 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
|
209 sc->wd9_tag = \ |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
210 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
|
211 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
212 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
213 static void |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
214 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
|
215 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
|
216 } |
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 |
5 | 219 /* Following implements a new bus device. |
220 * It is attached under nexus bus, an on board device as `vordog0'. | |
221 */ | |
222 | |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
223 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
|
224 device_t vordog; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
225 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
226 /* 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
|
227 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
|
228 if(vordog != NULL) |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
229 return; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
230 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
|
231 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
232 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
233 static int vordog_probe(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
234 int b; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
235 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
236 b = inb(VD_INITVAL); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
237 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
238 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
239 b = inb(VD_CTR); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
240 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
241 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
242 b = inb(VD_STATUS); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
243 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
244 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
245 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
246 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
247 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
248 static int vordog_attach(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
249 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
250 struct cdev *_cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
251 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
252 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
|
253 if(sc == NULL) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 return ENOMEM; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
255 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
256 _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
|
257 if(_cdev == NULL) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
258 free(sc, M_TEMP); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
259 return EINVAL; |
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 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
262 sc->_cdev = _cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
263 sc->dev = dev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
264 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
265 device_set_softc(dev, sc); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
266 CDEV_2_SOFTC(_cdev) = sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
267 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
268 sc->open_cnt = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
269 sc->init_val = 0; |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
270 sc->wd9_tag = NULL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
271 |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
272 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
|
273 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
|
274 |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
275 vordog_wd9_register(sc); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
276 |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
277 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
278 } |
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 static int vordog_detach(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
281 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
282 struct cdev *_cdev; |
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 sc = device_get_softc(dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
285 if(sc->open_cnt != 0) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
286 return EBUSY; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
287 |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
288 disable_timer(); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
289 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
290 vordog_wd9_unregister(sc); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
291 |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
292 _cdev = sc->_cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
293 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
294 destroy_dev(_cdev); |
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 free(sc, M_TEMP); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
299 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
300 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
301 static device_method_t vordog_methods[] = { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 DEVMETHOD(device_identify, vordog_identify), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 DEVMETHOD(device_probe, vordog_probe), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
304 DEVMETHOD(device_attach, vordog_attach), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 DEVMETHOD(device_detach, vordog_detach), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
306 {0, 0} |
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 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
309 static driver_t vordog_driver = { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
310 "vordog", |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
311 vordog_methods, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
312 0, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
313 }; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
314 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
315 static int |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
316 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
|
317 int r = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
318 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
319 switch(cmd) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
320 case MOD_LOAD: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
321 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
322 case MOD_UNLOAD: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
323 vordog_go_detach(); /* remove device from parent */ |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
324 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
325 case MOD_SHUTDOWN: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
326 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
327 default: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
328 r = EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
329 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
330 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
331 return r; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
332 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
333 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
334 static devclass_t vordog_devclass; |
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 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
|
337 vordog_evh, NULL); |