viawd.c (8fa0b743820f61c661ba5f3ea0e3be0dc137910e) | viawd.c (940853dd8413fb787d3dac21e79821e3067c0fa4) |
---|---|
1/*- 2 * Copyright (c) 2011 Fabien Thomas <fabient@FreeBSD.org> 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 --- 154 unchanged lines hidden (view full) --- 163 pmbase = pci_read_config(sb_dev, VIAWD_CONFIG_BASE, 4); 164 if (pmbase == 0) { 165 device_printf(dev, 166 "Watchdog disabled in BIOS or hardware\n"); 167 goto fail; 168 } 169 170 /* Allocate I/O register space. */ | 1/*- 2 * Copyright (c) 2011 Fabien Thomas <fabient@FreeBSD.org> 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 --- 154 unchanged lines hidden (view full) --- 163 pmbase = pci_read_config(sb_dev, VIAWD_CONFIG_BASE, 4); 164 if (pmbase == 0) { 165 device_printf(dev, 166 "Watchdog disabled in BIOS or hardware\n"); 167 goto fail; 168 } 169 170 /* Allocate I/O register space. */ |
171 sc->wd_rid = 0; 172 sc->wd_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->wd_rid, 173 pmbase, pmbase + VIAWD_MEM_LEN - 1, VIAWD_MEM_LEN, | 171 sc->wd_rid = VIAWD_CONFIG_BASE; 172 sc->wd_res = bus_alloc_resource_any(sb_dev, SYS_RES_MEMORY, &sc->wd_rid, |
174 RF_ACTIVE | RF_SHAREABLE); 175 if (sc->wd_res == NULL) { 176 device_printf(dev, "Unable to map watchdog memory\n"); 177 goto fail; 178 } | 173 RF_ACTIVE | RF_SHAREABLE); 174 if (sc->wd_res == NULL) { 175 device_printf(dev, "Unable to map watchdog memory\n"); 176 goto fail; 177 } |
178 if (rman_get_size(sc->wd_res) < VIAWD_MEM_LEN) { 179 device_printf(dev, "Bad size for watchdog memory: %#x\n", 180 (unsigned)rman_get_size(sc->wd_res)); 181 goto fail; 182 } |
|
179 180 /* Check if watchdog fired last boot. */ 181 reg = viawd_read_4(sc, VIAWD_MEM_CTRL); 182 if (reg & VIAWD_MEM_CTRL_FIRED) { 183 device_printf(dev, 184 "ERROR: watchdog rebooted the system\n"); 185 /* Reset bit state. */ 186 viawd_write_4(sc, VIAWD_MEM_CTRL, reg); 187 } 188 189 /* Register the watchdog event handler. */ 190 sc->ev_tag = EVENTHANDLER_REGISTER(watchdog_list, viawd_event, sc, 0); 191 192 return (0); 193fail: 194 if (sc->wd_res != NULL) | 183 184 /* Check if watchdog fired last boot. */ 185 reg = viawd_read_4(sc, VIAWD_MEM_CTRL); 186 if (reg & VIAWD_MEM_CTRL_FIRED) { 187 device_printf(dev, 188 "ERROR: watchdog rebooted the system\n"); 189 /* Reset bit state. */ 190 viawd_write_4(sc, VIAWD_MEM_CTRL, reg); 191 } 192 193 /* Register the watchdog event handler. */ 194 sc->ev_tag = EVENTHANDLER_REGISTER(watchdog_list, viawd_event, sc, 0); 195 196 return (0); 197fail: 198 if (sc->wd_res != NULL) |
195 bus_release_resource(dev, SYS_RES_MEMORY, | 199 bus_release_resource(sb_dev, SYS_RES_MEMORY, |
196 sc->wd_rid, sc->wd_res); 197 return (ENXIO); 198} 199 200static int 201viawd_detach(device_t dev) 202{ 203 struct viawd_softc *sc; --- 15 unchanged lines hidden (view full) --- 219 viawd_tmr_set(sc, VIAWD_TIMEOUT_SHUTDOWN); 220 viawd_tmr_state(sc, 1); 221 device_printf(dev, 222 "Keeping watchog alive during shutdown for %d seconds\n", 223 VIAWD_TIMEOUT_SHUTDOWN); 224 } 225 226 if (sc->wd_res != NULL) | 200 sc->wd_rid, sc->wd_res); 201 return (ENXIO); 202} 203 204static int 205viawd_detach(device_t dev) 206{ 207 struct viawd_softc *sc; --- 15 unchanged lines hidden (view full) --- 223 viawd_tmr_set(sc, VIAWD_TIMEOUT_SHUTDOWN); 224 viawd_tmr_state(sc, 1); 225 device_printf(dev, 226 "Keeping watchog alive during shutdown for %d seconds\n", 227 VIAWD_TIMEOUT_SHUTDOWN); 228 } 229 230 if (sc->wd_res != NULL) |
227 bus_release_resource(sc->dev, SYS_RES_MEMORY, | 231 bus_release_resource(sc->sb_dev, SYS_RES_MEMORY, |
228 sc->wd_rid, sc->wd_res); 229 230 return (0); 231} 232 233static device_method_t viawd_methods[] = { 234 DEVMETHOD(device_identify, viawd_identify), 235 DEVMETHOD(device_probe, viawd_probe), --- 13 unchanged lines hidden --- | 232 sc->wd_rid, sc->wd_res); 233 234 return (0); 235} 236 237static device_method_t viawd_methods[] = { 238 DEVMETHOD(device_identify, viawd_identify), 239 DEVMETHOD(device_probe, viawd_probe), --- 13 unchanged lines hidden --- |