Mercurial > vordog
comparison vordog.c @ 1:0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 08 Jul 2008 11:07:31 +0800 |
parents | 71475f5afa92 |
children | 60a234c9c03f |
comparison
equal
deleted
inserted
replaced
0:71475f5afa92 | 1:0b9854adb86c |
---|---|
79 static void | 79 static void |
80 setup_timer(vordog_cfg_t cfg) { | 80 setup_timer(vordog_cfg_t cfg) { |
81 int val; | 81 int val; |
82 #define VD_TIMER_RST 0xc | 82 #define VD_TIMER_RST 0xc |
83 | 83 |
84 #if 0 | |
85 outb(VD_STATUS, 0xc0); /* Clear events or it would be reset | |
86 * immediately, since it is setted | |
87 * by last timeout before PCIRST. | |
88 */ | |
89 #endif | |
90 val = cfg->init_val & 0xff; | 84 val = cfg->init_val & 0xff; |
91 printf("setup_timer 1 (%x)\n", val); | |
92 pause("vordog setup", hz); | |
93 outb(VD_INITVAL, val); | 85 outb(VD_INITVAL, val); |
94 printf("setup_timer 2\n"); | |
95 val = 0x80 | ((cfg->unit & 0x3) << 4) | VD_TIMER_RST; | 86 val = 0x80 | ((cfg->unit & 0x3) << 4) | VD_TIMER_RST; |
96 printf("setup_timer 3 (%x)\n", val); | |
97 pause("vordog setup", hz); | |
98 outb(VD_CTR, val); | 87 outb(VD_CTR, val); |
99 printf("setup_timer 4\n"); | |
100 } | 88 } |
101 | 89 |
102 static void | 90 static void |
103 reset_timer(int init_val) { | 91 reset_timer(int init_val) { |
104 #if 0 | |
105 printf("reset_timer 1\n"); | |
106 pause("vordog setup", hz); | |
107 outb(VD_INITVAL, init_val); | |
108 #endif | |
109 printf("reset_timer 2\n"); | |
110 pause("vordog setup", hz); | |
111 outb(VD_STATUS, 0xc0); | 92 outb(VD_STATUS, 0xc0); |
112 printf("reset_timer 3\n"); | |
113 pause("vordog setup", hz); | |
114 } | 93 } |
115 | 94 |
116 static void | 95 static void |
117 disable_timer(void) { | 96 disable_timer(void) { |
118 outb(VD_CTR, 0); | 97 outb(VD_CTR, 0); |
127 vordog_cfg_t cfg; | 106 vordog_cfg_t cfg; |
128 | 107 |
129 sc = CDEV_2_SOFTC(dev); | 108 sc = CDEV_2_SOFTC(dev); |
130 switch(cmd) { | 109 switch(cmd) { |
131 case VDCTL_ENABLE: | 110 case VDCTL_ENABLE: |
132 printf("VDCTL_ENABLE\n"); | |
133 cfg = (vordog_cfg_t)data; | 111 cfg = (vordog_cfg_t)data; |
134 sc->init_val = cfg->init_val & 0xff; | 112 sc->init_val = cfg->init_val & 0xff; |
135 setup_timer(cfg); | 113 setup_timer(cfg); |
136 break; | 114 break; |
137 case VDCTL_RESET: | 115 case VDCTL_RESET: |
138 printf("VDCTL_RESET\n"); | |
139 reset_timer(sc->init_val); | 116 reset_timer(sc->init_val); |
140 break; | 117 break; |
141 case VDCTL_DISABLE: | 118 case VDCTL_DISABLE: |
142 printf("VDCTL_DISABLE\n"); | |
143 disable_timer(); | 119 disable_timer(); |
144 break; | 120 break; |
145 default: | 121 default: |
146 r = EINVAL; | 122 r = EINVAL; |
147 } | 123 } |
159 static void vordog_identify(driver_t *driver, device_t parent) { | 135 static void vordog_identify(driver_t *driver, device_t parent) { |
160 device_t vordog; | 136 device_t vordog; |
161 | 137 |
162 /* make sure vordog device is not in the bus. */ | 138 /* make sure vordog device is not in the bus. */ |
163 vordog = device_find_child(parent, "vordog", 0); | 139 vordog = device_find_child(parent, "vordog", 0); |
164 if(vordog != NULL) { | 140 if(vordog != NULL) |
165 printf("vordog is still existing!"); | |
166 return; | 141 return; |
167 } | |
168 vordog = BUS_ADD_CHILD(parent, 10, "vordog", 0); | 142 vordog = BUS_ADD_CHILD(parent, 10, "vordog", 0); |
169 printf("vordog_identify\n"); | |
170 } | 143 } |
171 | 144 |
172 static int vordog_probe(device_t dev) { | 145 static int vordog_probe(device_t dev) { |
173 int b; | 146 int b; |
174 | 147 |
175 printf("vordog_probe\n"); | |
176 b = inb(VD_INITVAL); | 148 b = inb(VD_INITVAL); |
177 printf("init val: %x\n", b); | 149 if(b != 0) |
150 return EINVAL; | |
178 b = inb(VD_CTR); | 151 b = inb(VD_CTR); |
179 printf("ctr: %x\n", b); | 152 if(b != 0) |
153 return EINVAL; | |
180 b = inb(VD_STATUS); | 154 b = inb(VD_STATUS); |
181 printf("status: %x\n", b); | 155 if(b != 0) |
156 return EINVAL; | |
182 return 0; | 157 return 0; |
183 } | 158 } |
184 | 159 |
185 static int vordog_attach(device_t dev) { | 160 static int vordog_attach(device_t dev) { |
186 vd_softc_t sc; | 161 vd_softc_t sc; |
187 struct cdev *_cdev; | 162 struct cdev *_cdev; |
188 | |
189 printf("vordog_attach 1\n"); | |
190 | 163 |
191 sc = (vd_softc_t)malloc(sizeof(struct vd_softc), M_TEMP, M_WAITOK); | 164 sc = (vd_softc_t)malloc(sizeof(struct vd_softc), M_TEMP, M_WAITOK); |
192 if(sc == NULL) | 165 if(sc == NULL) |
193 return ENOMEM; | 166 return ENOMEM; |
194 | 167 |
195 printf("vordog_attach 2\n"); | |
196 _cdev = make_dev(&vordog_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "vordog0"); | 168 _cdev = make_dev(&vordog_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "vordog0"); |
197 if(_cdev == NULL) { | 169 if(_cdev == NULL) { |
198 free(sc, M_TEMP); | 170 free(sc, M_TEMP); |
199 return EINVAL; | 171 return EINVAL; |
200 } | 172 } |
201 | 173 |
202 sc->_cdev = _cdev; | 174 sc->_cdev = _cdev; |
203 sc->dev = dev; | 175 sc->dev = dev; |
204 | 176 |
205 printf("vordog_attach 3\n"); | |
206 device_set_softc(dev, sc); | 177 device_set_softc(dev, sc); |
207 CDEV_2_SOFTC(_cdev) = sc; | 178 CDEV_2_SOFTC(_cdev) = sc; |
208 | 179 |
209 sc->open_cnt = 0; | 180 sc->open_cnt = 0; |
210 sc->init_val = 0; | 181 sc->init_val = 0; |
211 | 182 |
183 device_set_desc(dev, "Watchdog of Vortex86 SoC"); | |
184 device_printf(dev, "<Vortex86 SoC watchdog> at port 0x%x\n", VD_STATUS); | |
185 | |
212 return 0; | 186 return 0; |
213 } | 187 } |
214 | 188 |
215 static int vordog_detach(device_t dev) { | 189 static int vordog_detach(device_t dev) { |
216 vd_softc_t sc; | 190 vd_softc_t sc; |
217 struct cdev *_cdev; | 191 struct cdev *_cdev; |
218 | 192 |
219 printf("vordog_detach 1\n"); | |
220 sc = device_get_softc(dev); | 193 sc = device_get_softc(dev); |
221 if(sc->open_cnt != 0) | 194 if(sc->open_cnt != 0) |
222 return EBUSY; | 195 return EBUSY; |
223 | 196 |
224 printf("vordog_detach 2\n"); | |
225 _cdev = sc->_cdev; | 197 _cdev = sc->_cdev; |
226 | 198 |
227 printf("vordog_detach 3\n"); | |
228 destroy_dev(_cdev); | 199 destroy_dev(_cdev); |
229 printf("vordog_detach 4\n"); | |
230 | 200 |
231 free(sc, M_TEMP); | 201 free(sc, M_TEMP); |
232 | 202 |
233 return 0; | 203 return 0; |
234 } | 204 } |
251 vordog_evh(module_t mod, int cmd, void *arg) { | 221 vordog_evh(module_t mod, int cmd, void *arg) { |
252 int r = 0; | 222 int r = 0; |
253 | 223 |
254 switch(cmd) { | 224 switch(cmd) { |
255 case MOD_LOAD: | 225 case MOD_LOAD: |
256 printf("MOD_LOAD\n"); | |
257 break; | 226 break; |
258 case MOD_UNLOAD: | 227 case MOD_UNLOAD: |
259 printf("MOD_UNLOAD\n"); | |
260 vordog_go_detach(); /* remove device from parent */ | 228 vordog_go_detach(); /* remove device from parent */ |
261 break; | 229 break; |
262 case MOD_SHUTDOWN: | 230 case MOD_SHUTDOWN: |
263 printf("MOD_SHUTDOWN\n"); | |
264 break; | 231 break; |
265 default: | 232 default: |
266 r = EINVAL; | 233 r = EINVAL; |
267 break; | 234 break; |
268 } | 235 } |