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