weasel_pci.c revision 1.1.2.2 1 1.1.2.2 nathanw /* $NetBSD: weasel_pci.c,v 1.1.2.2 2002/01/08 00:31:19 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*-
4 1.1.2.2 nathanw * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 nathanw * by Herb Peyerl and Jason Thorpe.
9 1.1.2.2 nathanw *
10 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.2.2 nathanw * are met:
13 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 nathanw * must display the following acknowledgement:
20 1.1.2.2 nathanw * This product includes software developed by the NetBSD
21 1.1.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.2.2 nathanw * from this software without specific prior written permission.
25 1.1.2.2 nathanw *
26 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 nathanw */
38 1.1.2.2 nathanw
39 1.1.2.2 nathanw /*
40 1.1.2.2 nathanw * Device driver for the control space on the Middle Digital, Inc.
41 1.1.2.2 nathanw * PCI-Weasel serial console board.
42 1.1.2.2 nathanw *
43 1.1.2.2 nathanw * Since the other functions of the PCI-Weasel already appear in
44 1.1.2.2 nathanw * PCI configuration space, we just need to hook up the watchdog
45 1.1.2.2 nathanw * timer.
46 1.1.2.2 nathanw */
47 1.1.2.2 nathanw
48 1.1.2.2 nathanw #include <sys/cdefs.h>
49 1.1.2.2 nathanw __KERNEL_RCSID(0, "$NetBSD: weasel_pci.c,v 1.1.2.2 2002/01/08 00:31:19 nathanw Exp $");
50 1.1.2.2 nathanw
51 1.1.2.2 nathanw #include <sys/param.h>
52 1.1.2.2 nathanw #include <sys/systm.h>
53 1.1.2.2 nathanw #include <sys/device.h>
54 1.1.2.2 nathanw #include <sys/wdog.h>
55 1.1.2.2 nathanw #include <sys/endian.h>
56 1.1.2.2 nathanw
57 1.1.2.2 nathanw #include <machine/bus.h>
58 1.1.2.2 nathanw
59 1.1.2.2 nathanw #include <dev/pci/pcireg.h>
60 1.1.2.2 nathanw #include <dev/pci/pcivar.h>
61 1.1.2.2 nathanw #include <dev/pci/pcidevs.h>
62 1.1.2.2 nathanw
63 1.1.2.2 nathanw #include <dev/pci/weaselreg.h>
64 1.1.2.2 nathanw
65 1.1.2.2 nathanw #include <dev/sysmon/sysmonvar.h>
66 1.1.2.2 nathanw
67 1.1.2.2 nathanw struct weasel_softc {
68 1.1.2.2 nathanw struct device sc_dev; /* generic device glue */
69 1.1.2.2 nathanw
70 1.1.2.2 nathanw bus_space_tag_t sc_st;
71 1.1.2.2 nathanw bus_space_handle_t sc_sh;
72 1.1.2.2 nathanw
73 1.1.2.2 nathanw struct sysmon_wdog sc_smw;
74 1.1.2.2 nathanw
75 1.1.2.2 nathanw int sc_wdog_armed;
76 1.1.2.2 nathanw int sc_wdog_period;
77 1.1.2.2 nathanw };
78 1.1.2.2 nathanw
79 1.1.2.2 nathanw int weasel_pci_match(struct device *, struct cfdata *, void *);
80 1.1.2.2 nathanw void weasel_pci_attach(struct device *, struct device *, void *);
81 1.1.2.2 nathanw extern int sysmon_wdog_setmode(struct sysmon_wdog *, int, u_int);
82 1.1.2.2 nathanw
83 1.1.2.2 nathanw struct cfattach weasel_pci_ca = {
84 1.1.2.2 nathanw sizeof(struct weasel_softc), weasel_pci_match, weasel_pci_attach,
85 1.1.2.2 nathanw };
86 1.1.2.2 nathanw
87 1.1.2.2 nathanw int weasel_pci_wdog_setmode(struct sysmon_wdog *);
88 1.1.2.2 nathanw int weasel_pci_wdog_tickle(struct sysmon_wdog *);
89 1.1.2.2 nathanw
90 1.1.2.2 nathanw int weasel_wait_response(struct weasel_softc *);
91 1.1.2.2 nathanw int weasel_issue_command(struct weasel_softc *, uint8_t cmd);
92 1.1.2.2 nathanw
93 1.1.2.2 nathanw int weasel_pci_wdog_arm(struct weasel_softc *);
94 1.1.2.2 nathanw int weasel_pci_wdog_disarm(struct weasel_softc *);
95 1.1.2.2 nathanw
96 1.1.2.2 nathanw int weasel_pci_wdog_query_state(struct weasel_softc *);
97 1.1.2.2 nathanw
98 1.1.2.2 nathanw int
99 1.1.2.2 nathanw weasel_pci_match(struct device *parent, struct cfdata *cf, void *aux)
100 1.1.2.2 nathanw {
101 1.1.2.2 nathanw struct pci_attach_args *pa = aux;
102 1.1.2.2 nathanw
103 1.1.2.2 nathanw if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_MIDDLE_DIGITAL &&
104 1.1.2.2 nathanw PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_MIDDLE_DIGITAL_WEASEL_CONTROL)
105 1.1.2.2 nathanw return (1);
106 1.1.2.2 nathanw
107 1.1.2.2 nathanw return (0);
108 1.1.2.2 nathanw }
109 1.1.2.2 nathanw
110 1.1.2.2 nathanw void
111 1.1.2.2 nathanw weasel_pci_attach(struct device *parent, struct device *self, void *aux)
112 1.1.2.2 nathanw {
113 1.1.2.2 nathanw struct weasel_softc *sc = (void *) self;
114 1.1.2.2 nathanw struct pci_attach_args *pa = aux;
115 1.1.2.2 nathanw struct weasel_config_block cfg;
116 1.1.2.2 nathanw const char *vers, *mode;
117 1.1.2.2 nathanw uint8_t v, *cp;
118 1.1.2.2 nathanw uint16_t cfg_size;
119 1.1.2.2 nathanw uint8_t buf[8];
120 1.1.2.2 nathanw
121 1.1.2.2 nathanw printf(": PCI-Weasel watchdog timer\n");
122 1.1.2.2 nathanw
123 1.1.2.2 nathanw if (pci_mapreg_map(pa, PCI_MAPREG_START,
124 1.1.2.2 nathanw PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
125 1.1.2.2 nathanw &sc->sc_st, &sc->sc_sh, NULL, NULL) != 0) {
126 1.1.2.2 nathanw printf("%s: unable to map device registers\n",
127 1.1.2.2 nathanw sc->sc_dev.dv_xname);
128 1.1.2.2 nathanw return;
129 1.1.2.2 nathanw }
130 1.1.2.2 nathanw
131 1.1.2.2 nathanw /* Ping the Weasel to see if it's alive. */
132 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_PING)) {
133 1.1.2.2 nathanw printf("%s: Weasel didn't respond to PING\n",
134 1.1.2.2 nathanw sc->sc_dev.dv_xname);
135 1.1.2.2 nathanw return;
136 1.1.2.2 nathanw }
137 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
138 1.1.2.2 nathanw if ((v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD)) !=
139 1.1.2.2 nathanw OS_RET_PONG) {
140 1.1.2.2 nathanw printf("%s: unexpected PING response from Weasel: 0x%02x\n",
141 1.1.2.2 nathanw sc->sc_dev.dv_xname, v);
142 1.1.2.2 nathanw return;
143 1.1.2.2 nathanw }
144 1.1.2.2 nathanw
145 1.1.2.2 nathanw /* Read the config block. */
146 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_SHOW_CONFIG)) {
147 1.1.2.2 nathanw printf("%s: Weasel didn't respond to SHOW_CONFIG\n",
148 1.1.2.2 nathanw sc->sc_dev.dv_xname);
149 1.1.2.2 nathanw return;
150 1.1.2.2 nathanw }
151 1.1.2.2 nathanw cfg_size = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
152 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
153 1.1.2.2 nathanw
154 1.1.2.2 nathanw if (++cfg_size != sizeof(cfg)) {
155 1.1.2.2 nathanw printf("%s: weird config block size from Weasel: 0x%03x\n",
156 1.1.2.2 nathanw sc->sc_dev.dv_xname, cfg_size);
157 1.1.2.2 nathanw return;
158 1.1.2.2 nathanw }
159 1.1.2.2 nathanw
160 1.1.2.2 nathanw for (cp = (uint8_t *) &cfg; cfg_size != 0; cfg_size--) {
161 1.1.2.2 nathanw if (weasel_wait_response(sc)) {
162 1.1.2.2 nathanw printf("%s: Weasel stopped providing config block(%d)\n",
163 1.1.2.2 nathanw sc->sc_dev.dv_xname, cfg_size);
164 1.1.2.2 nathanw return;
165 1.1.2.2 nathanw }
166 1.1.2.2 nathanw *cp++ = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
167 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
168 1.1.2.2 nathanw }
169 1.1.2.2 nathanw
170 1.1.2.2 nathanw switch (cfg.cfg_version) {
171 1.1.2.2 nathanw case CFG_VERSION_2:
172 1.1.2.2 nathanw vers="2";
173 1.1.2.2 nathanw switch (cfg.enable_duart_switching) {
174 1.1.2.2 nathanw case 0:
175 1.1.2.2 nathanw mode = "emulation";
176 1.1.2.2 nathanw break;
177 1.1.2.2 nathanw case 1:
178 1.1.2.2 nathanw mode = "serial";
179 1.1.2.2 nathanw break;
180 1.1.2.2 nathanw case 2:
181 1.1.2.2 nathanw mode = "autoswitch";
182 1.1.2.2 nathanw break;
183 1.1.2.2 nathanw default:
184 1.1.2.2 nathanw mode = "unknown";
185 1.1.2.2 nathanw }
186 1.1.2.2 nathanw break;
187 1.1.2.2 nathanw
188 1.1.2.2 nathanw default:
189 1.1.2.2 nathanw vers = mode = NULL;
190 1.1.2.2 nathanw }
191 1.1.2.2 nathanw
192 1.1.2.2 nathanw if (vers != NULL)
193 1.1.2.2 nathanw printf("%s: %s mode\n", sc->sc_dev.dv_xname,
194 1.1.2.2 nathanw mode);
195 1.1.2.2 nathanw else
196 1.1.2.2 nathanw printf("%s: unknown config version 0x%02x\n", sc->sc_dev.dv_xname,
197 1.1.2.2 nathanw cfg.cfg_version);
198 1.1.2.2 nathanw
199 1.1.2.2 nathanw /*
200 1.1.2.2 nathanw * Fetch sw version.
201 1.1.2.2 nathanw */
202 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_QUERY_SW_VER)) {
203 1.1.2.2 nathanw printf("%s: didn't reply to software version query.\n",
204 1.1.2.2 nathanw sc->sc_dev.dv_xname);
205 1.1.2.2 nathanw }
206 1.1.2.2 nathanw else {
207 1.1.2.2 nathanw v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
208 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
209 1.1.2.2 nathanw if (v>7)
210 1.1.2.2 nathanw printf("%s: weird length for version string(%d).\n",
211 1.1.2.2 nathanw sc->sc_dev.dv_xname, v);
212 1.1.2.2 nathanw bzero(buf, sizeof(buf));
213 1.1.2.2 nathanw for (cp = buf; v != 0; v--) {
214 1.1.2.2 nathanw if (weasel_wait_response(sc)) {
215 1.1.2.2 nathanw printf("%s: Weasel stopped providing version\n",
216 1.1.2.2 nathanw sc->sc_dev.dv_xname);
217 1.1.2.2 nathanw }
218 1.1.2.2 nathanw *cp++ = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
219 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
220 1.1.2.2 nathanw }
221 1.1.2.2 nathanw printf("%s: sw: %s", sc->sc_dev.dv_xname, buf);
222 1.1.2.2 nathanw }
223 1.1.2.2 nathanw /*
224 1.1.2.2 nathanw * Fetch logic version.
225 1.1.2.2 nathanw */
226 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_QUERY_L_VER)) {
227 1.1.2.2 nathanw printf("\n%s: didn't reply to logic version query.\n",
228 1.1.2.2 nathanw sc->sc_dev.dv_xname);
229 1.1.2.2 nathanw }
230 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
231 1.1.2.2 nathanw v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
232 1.1.2.2 nathanw printf(" logic: %03d", v);
233 1.1.2.2 nathanw /*
234 1.1.2.2 nathanw * Fetch vga bios version.
235 1.1.2.2 nathanw */
236 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_QUERY_VB_VER)) {
237 1.1.2.2 nathanw printf("\n%s: didn't reply to vga bios version query.\n",
238 1.1.2.2 nathanw sc->sc_dev.dv_xname);
239 1.1.2.2 nathanw }
240 1.1.2.2 nathanw v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
241 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
242 1.1.2.2 nathanw printf(" vga bios: %d.%d", (v>>4), (v&0x0f));
243 1.1.2.2 nathanw /*
244 1.1.2.2 nathanw * Fetch hw version.
245 1.1.2.2 nathanw */
246 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_QUERY_HW_VER)) {
247 1.1.2.2 nathanw printf("\n%s: didn't reply to hardware version query.\n",
248 1.1.2.2 nathanw sc->sc_dev.dv_xname);
249 1.1.2.2 nathanw }
250 1.1.2.2 nathanw v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
251 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
252 1.1.2.2 nathanw printf(" hw: %d.%d", (v>>4), (v&0x0f));
253 1.1.2.2 nathanw
254 1.1.2.2 nathanw printf("\n%s: break passthrough %s", sc->sc_dev.dv_xname,
255 1.1.2.2 nathanw cfg.break_passthru ? "enabled" : "disabled");
256 1.1.2.2 nathanw
257 1.1.2.2 nathanw if ((sc->sc_wdog_armed = weasel_pci_wdog_query_state(sc)) == -1)
258 1.1.2.2 nathanw sc->sc_wdog_armed = 0;
259 1.1.2.2 nathanw
260 1.1.2.2 nathanw /* Weasel is big-endian */
261 1.1.2.2 nathanw sc->sc_wdog_period = be16toh(cfg.wdt_msec) / 1000;
262 1.1.2.2 nathanw
263 1.1.2.2 nathanw printf(", watchdog timer %d sec.\n", sc->sc_wdog_period);
264 1.1.2.2 nathanw sc->sc_smw.smw_name = "weasel";
265 1.1.2.2 nathanw sc->sc_smw.smw_cookie = sc;
266 1.1.2.2 nathanw sc->sc_smw.smw_setmode = weasel_pci_wdog_setmode;
267 1.1.2.2 nathanw sc->sc_smw.smw_tickle = weasel_pci_wdog_tickle;
268 1.1.2.2 nathanw sc->sc_smw.smw_period = sc->sc_wdog_period;
269 1.1.2.2 nathanw
270 1.1.2.2 nathanw if (sysmon_wdog_register(&sc->sc_smw) != 0)
271 1.1.2.2 nathanw printf("%s: unable to register PC-Weasel watchdog "
272 1.1.2.2 nathanw "with sysmon\n", sc->sc_dev.dv_xname);
273 1.1.2.2 nathanw }
274 1.1.2.2 nathanw
275 1.1.2.2 nathanw int
276 1.1.2.2 nathanw weasel_wait_response(struct weasel_softc *sc)
277 1.1.2.2 nathanw {
278 1.1.2.2 nathanw int i;
279 1.1.2.2 nathanw
280 1.1.2.2 nathanw for (i = 10000; i ; i--) {
281 1.1.2.2 nathanw delay(100);
282 1.1.2.2 nathanw if (bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS) ==
283 1.1.2.2 nathanw OS_WS_HOST_READ)
284 1.1.2.2 nathanw return(0);
285 1.1.2.2 nathanw }
286 1.1.2.2 nathanw return (1);
287 1.1.2.2 nathanw }
288 1.1.2.2 nathanw
289 1.1.2.2 nathanw int
290 1.1.2.2 nathanw weasel_issue_command(struct weasel_softc *sc, uint8_t cmd)
291 1.1.2.2 nathanw {
292 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_WR, cmd);
293 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_HOST_STATUS, OS_HS_WEASEL_READ);
294 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
295 1.1.2.2 nathanw return (weasel_wait_response(sc));
296 1.1.2.2 nathanw }
297 1.1.2.2 nathanw
298 1.1.2.2 nathanw int
299 1.1.2.2 nathanw weasel_pci_wdog_setmode(struct sysmon_wdog *smw)
300 1.1.2.2 nathanw {
301 1.1.2.2 nathanw struct weasel_softc *sc = smw->smw_cookie;
302 1.1.2.2 nathanw int error = 0;
303 1.1.2.2 nathanw
304 1.1.2.2 nathanw if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
305 1.1.2.2 nathanw error = weasel_pci_wdog_disarm(sc);
306 1.1.2.2 nathanw } else {
307 1.1.2.2 nathanw if (smw->smw_period == WDOG_PERIOD_DEFAULT)
308 1.1.2.2 nathanw smw->smw_period = sc->sc_wdog_period;
309 1.1.2.2 nathanw else if (smw->smw_period != sc->sc_wdog_period) {
310 1.1.2.2 nathanw /* Can't change the period on the Weasel. */
311 1.1.2.2 nathanw return (EINVAL);
312 1.1.2.2 nathanw }
313 1.1.2.2 nathanw error = weasel_pci_wdog_arm(sc);
314 1.1.2.2 nathanw weasel_pci_wdog_tickle(smw);
315 1.1.2.2 nathanw }
316 1.1.2.2 nathanw
317 1.1.2.2 nathanw return (error);
318 1.1.2.2 nathanw }
319 1.1.2.2 nathanw
320 1.1.2.2 nathanw int
321 1.1.2.2 nathanw weasel_pci_wdog_tickle(struct sysmon_wdog *smw)
322 1.1.2.2 nathanw {
323 1.1.2.2 nathanw struct weasel_softc *sc = smw->smw_cookie;
324 1.1.2.2 nathanw u_int8_t reg;
325 1.1.2.2 nathanw int x;
326 1.1.2.2 nathanw int s;
327 1.1.2.2 nathanw int error = 0;
328 1.1.2.2 nathanw
329 1.1.2.2 nathanw s = splhigh();
330 1.1.2.2 nathanw /*
331 1.1.2.2 nathanw * first we tickle the watchdog
332 1.1.2.2 nathanw */
333 1.1.2.2 nathanw reg = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_CHALLENGE);
334 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_RESPONSE, ~reg);
335 1.1.2.2 nathanw
336 1.1.2.2 nathanw /*
337 1.1.2.2 nathanw * then we check to make sure the weasel is still armed. If someone
338 1.1.2.2 nathanw * has rebooted the weasel for whatever reason (firmware update),
339 1.1.2.2 nathanw * then the watchdog timer would no longer be armed and we'd be
340 1.1.2.2 nathanw * servicing nothing. Let the user know that the machine is no
341 1.1.2.2 nathanw * longer being monitored by the weasel.
342 1.1.2.2 nathanw */
343 1.1.2.2 nathanw if((x = weasel_pci_wdog_query_state(sc)) == -1)
344 1.1.2.2 nathanw error = EIO;
345 1.1.2.2 nathanw if (x == 1) {
346 1.1.2.2 nathanw error = 0;
347 1.1.2.2 nathanw } else {
348 1.1.2.2 nathanw printf("%s: Watchdog timer disabled on PC/Weasel! Disarming wdog.\n",
349 1.1.2.2 nathanw sc->sc_dev.dv_xname);
350 1.1.2.2 nathanw sc->sc_wdog_armed = 0;
351 1.1.2.2 nathanw sysmon_wdog_setmode(smw, WDOG_MODE_DISARMED, 0);
352 1.1.2.2 nathanw error = 1;
353 1.1.2.2 nathanw }
354 1.1.2.2 nathanw splx(s);
355 1.1.2.2 nathanw
356 1.1.2.2 nathanw return (error);
357 1.1.2.2 nathanw }
358 1.1.2.2 nathanw
359 1.1.2.2 nathanw int
360 1.1.2.2 nathanw weasel_pci_wdog_arm(struct weasel_softc *sc)
361 1.1.2.2 nathanw {
362 1.1.2.2 nathanw u_int8_t reg;
363 1.1.2.2 nathanw int x;
364 1.1.2.2 nathanw int s;
365 1.1.2.2 nathanw int error = 0;
366 1.1.2.2 nathanw
367 1.1.2.2 nathanw s = splhigh();
368 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_WDT_ENABLE)) {
369 1.1.2.2 nathanw printf("%s: no reply to watchdog enable. Check Weasel \"Allow Watchdog\" setting.\n",
370 1.1.2.2 nathanw sc->sc_dev.dv_xname);
371 1.1.2.2 nathanw error = EIO;
372 1.1.2.2 nathanw }
373 1.1.2.2 nathanw reg = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
374 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
375 1.1.2.2 nathanw
376 1.1.2.2 nathanw /*
377 1.1.2.2 nathanw * Ensure that the Weasel thinks it's in the same mode we want it to
378 1.1.2.2 nathanw * be in. EIO if not.
379 1.1.2.2 nathanw */
380 1.1.2.2 nathanw x = weasel_pci_wdog_query_state(sc);
381 1.1.2.2 nathanw switch (x) {
382 1.1.2.2 nathanw case -1:
383 1.1.2.2 nathanw error = EIO;
384 1.1.2.2 nathanw break;
385 1.1.2.2 nathanw case 0:
386 1.1.2.2 nathanw sc->sc_wdog_armed = 0;
387 1.1.2.2 nathanw error = EIO;
388 1.1.2.2 nathanw break;
389 1.1.2.2 nathanw case 1:
390 1.1.2.2 nathanw sc->sc_wdog_armed = 1;
391 1.1.2.2 nathanw error = 0;
392 1.1.2.2 nathanw break;
393 1.1.2.2 nathanw }
394 1.1.2.2 nathanw
395 1.1.2.2 nathanw splx(s);
396 1.1.2.2 nathanw return(error);
397 1.1.2.2 nathanw }
398 1.1.2.2 nathanw
399 1.1.2.2 nathanw
400 1.1.2.2 nathanw int
401 1.1.2.2 nathanw weasel_pci_wdog_disarm(struct weasel_softc *sc)
402 1.1.2.2 nathanw {
403 1.1.2.2 nathanw u_int8_t reg;
404 1.1.2.2 nathanw int x;
405 1.1.2.2 nathanw int s;
406 1.1.2.2 nathanw int error = 0;
407 1.1.2.2 nathanw
408 1.1.2.2 nathanw s = splhigh();
409 1.1.2.2 nathanw
410 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_WDT_DISABLE)) {
411 1.1.2.2 nathanw printf("%s: didn't reply to watchdog disable.\n",
412 1.1.2.2 nathanw sc->sc_dev.dv_xname);
413 1.1.2.2 nathanw error = EIO;
414 1.1.2.2 nathanw }
415 1.1.2.2 nathanw reg = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
416 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
417 1.1.2.2 nathanw
418 1.1.2.2 nathanw /*
419 1.1.2.2 nathanw * Ensure that the Weasel thinks it's in the same mode we want it to
420 1.1.2.2 nathanw * be in. EIO if not.
421 1.1.2.2 nathanw */
422 1.1.2.2 nathanw x = weasel_pci_wdog_query_state(sc);
423 1.1.2.2 nathanw switch (x) {
424 1.1.2.2 nathanw case -1:
425 1.1.2.2 nathanw error = EIO;
426 1.1.2.2 nathanw break;
427 1.1.2.2 nathanw case 0:
428 1.1.2.2 nathanw sc->sc_wdog_armed = 0;
429 1.1.2.2 nathanw error = 0;
430 1.1.2.2 nathanw break;
431 1.1.2.2 nathanw case 1:
432 1.1.2.2 nathanw sc->sc_wdog_armed = 1;
433 1.1.2.2 nathanw error = EIO;
434 1.1.2.2 nathanw break;
435 1.1.2.2 nathanw }
436 1.1.2.2 nathanw
437 1.1.2.2 nathanw splx(s);
438 1.1.2.2 nathanw return(error);
439 1.1.2.2 nathanw }
440 1.1.2.2 nathanw
441 1.1.2.2 nathanw int
442 1.1.2.2 nathanw weasel_pci_wdog_query_state(struct weasel_softc *sc)
443 1.1.2.2 nathanw {
444 1.1.2.2 nathanw
445 1.1.2.2 nathanw u_int8_t v;
446 1.1.2.2 nathanw
447 1.1.2.2 nathanw if (weasel_issue_command(sc, OS_CMD_WDT_QUERY)) {
448 1.1.2.2 nathanw printf("%s: didn't reply to watchdog state query.\n",
449 1.1.2.2 nathanw sc->sc_dev.dv_xname);
450 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
451 1.1.2.2 nathanw return(-1);
452 1.1.2.2 nathanw }
453 1.1.2.2 nathanw v = bus_space_read_1(sc->sc_st, sc->sc_sh, WEASEL_DATA_RD);
454 1.1.2.2 nathanw bus_space_write_1(sc->sc_st, sc->sc_sh, WEASEL_STATUS, 0);
455 1.1.2.2 nathanw return(v);
456 1.1.2.2 nathanw }
457