Mercurial > vordog
annotate vordog.c @ 13:e4e6727f530f tip
To work with bootstrap code's configuration on the timer
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 09 Jul 2008 13:05:43 +0800 |
parents | 6bfd60bcd7b8 |
children |
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 |
7 | 158 /* |
159 * Implements watchdog(9) compatible driver. | |
160 */ | |
161 /*! \brief Initialize timer for an interval in specified seconds. | |
162 */ | |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
163 static int |
7 | 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 | 176 /*! \brief Reset timer before it is timeout. |
177 * | |
178 * It make the timer reload it's value from initial value register. | |
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 | 185 /*! \brief Stop counting of watchdog timer. |
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 | 193 /*! \brief event handler for watchdog(9). |
194 * | |
195 * Timeout interval of watchdog(9) is defined by power of 2 nanoseconds. | |
196 * Watchdog timer of Vortex86 provides only small range of intervals. | |
197 * We use only the timer in seconds to simplize the code. It provides | |
198 * interval 1~255 seconds. | |
199 * | |
200 * Since, only SFTMR1_STS is work, in my experience, and it is triggered | |
201 * after 4 times of initial value. So, it only (i * 4) seconds in range | |
202 * of 4 ~ (255 * 4), where i is one of positive integer, are supported. | |
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 | 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 | 208 */ |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
209 static void |
7 | 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 | 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 | 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 } |
9
b4f4a69ea86a
clear error after event handler for watchdog(9)
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
233 *error = 0; |
6
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 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
236 static void |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
237 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
|
238 sc->wd9_tag = \ |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
239 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
|
240 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
241 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
242 static void |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
243 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
|
244 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
|
245 } |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
246 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
247 |
5 | 248 /* Following implements a new bus device. |
249 * It is attached under nexus bus, an on board device as `vordog0'. | |
250 */ | |
251 | |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
252 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
|
253 device_t vordog; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
255 /* 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
|
256 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
|
257 if(vordog != NULL) |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
258 return; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
259 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
|
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 static int vordog_probe(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
263 int b; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
264 |
13
e4e6727f530f
To work with bootstrap code's configuration on the timer
Thinker K.F. Li <thinker@branda.to>
parents:
12
diff
changeset
|
265 disable_timer(); /* To work with bootstrap code |
e4e6727f530f
To work with bootstrap code's configuration on the timer
Thinker K.F. Li <thinker@branda.to>
parents:
12
diff
changeset
|
266 * that may configure the timer. */ |
e4e6727f530f
To work with bootstrap code's configuration on the timer
Thinker K.F. Li <thinker@branda.to>
parents:
12
diff
changeset
|
267 |
e4e6727f530f
To work with bootstrap code's configuration on the timer
Thinker K.F. Li <thinker@branda.to>
parents:
12
diff
changeset
|
268 outb(VD_INITVAL, 0xaa); |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
269 b = inb(VD_INITVAL); |
13
e4e6727f530f
To work with bootstrap code's configuration on the timer
Thinker K.F. Li <thinker@branda.to>
parents:
12
diff
changeset
|
270 if(b != 0xaa) |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
271 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
272 b = inb(VD_CTR); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
273 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
274 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
275 b = inb(VD_STATUS); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
276 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
277 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
278 return 0; |
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 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
281 static int vordog_attach(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
282 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
283 struct cdev *_cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
284 |
11
3968bbb5303d
disable timer before attached
Thinker K.F. Li <thinker@branda.to>
parents:
9
diff
changeset
|
285 disable_timer(); |
3968bbb5303d
disable timer before attached
Thinker K.F. Li <thinker@branda.to>
parents:
9
diff
changeset
|
286 |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
287 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
|
288 if(sc == NULL) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
289 return ENOMEM; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
290 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
291 _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
|
292 if(_cdev == NULL) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
293 free(sc, M_TEMP); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
294 return EINVAL; |
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 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 sc->_cdev = _cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 sc->dev = dev; |
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 device_set_softc(dev, sc); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
301 CDEV_2_SOFTC(_cdev) = sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 sc->open_cnt = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
304 sc->init_val = 0; |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
305 sc->wd9_tag = NULL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
306 |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
307 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
|
308 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
|
309 |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
310 vordog_wd9_register(sc); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
311 |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
312 return 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 vordog_detach(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
316 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
317 struct cdev *_cdev; |
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 sc = device_get_softc(dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
320 if(sc->open_cnt != 0) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
321 return EBUSY; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
322 |
6
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
323 disable_timer(); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
324 |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
325 vordog_wd9_unregister(sc); |
76ce6e6624b8
Make vordog compatible with watchdog(9).
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
326 |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
327 _cdev = sc->_cdev; |
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 destroy_dev(_cdev); |
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 free(sc, M_TEMP); |
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 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
334 } |
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 static device_method_t vordog_methods[] = { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
337 DEVMETHOD(device_identify, vordog_identify), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
338 DEVMETHOD(device_probe, vordog_probe), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
339 DEVMETHOD(device_attach, vordog_attach), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
340 DEVMETHOD(device_detach, vordog_detach), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
341 {0, 0} |
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 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
344 static driver_t vordog_driver = { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
345 "vordog", |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
346 vordog_methods, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
347 0, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
348 }; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
349 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
350 static int |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
351 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
|
352 int r = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
353 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
354 switch(cmd) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
355 case MOD_LOAD: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
356 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
357 case MOD_UNLOAD: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
358 vordog_go_detach(); /* remove device from parent */ |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
359 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
360 case MOD_SHUTDOWN: |
12
6bfd60bcd7b8
disable timer when shuting down
Thinker K.F. Li <thinker@branda.to>
parents:
11
diff
changeset
|
361 disable_timer(); /* prevent system reset when shuting down */ |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
362 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
363 default: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
364 r = EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
365 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
366 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
367 return r; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
368 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
369 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
370 static devclass_t vordog_devclass; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
371 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
372 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
|
373 vordog_evh, NULL); |