Rework the attachement to probe directly on isab(4).
Depend on r228496. Requested by: jhb MFC after: 1 month
This commit is contained in:
parent
93b09a6b44
commit
17652e9b65
@ -42,10 +42,9 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include "viawd.h"
|
#include "viawd.h"
|
||||||
|
|
||||||
#define viawd_read_wd_4(sc, off) \
|
#define viawd_read_4(sc, off) bus_read_4((sc)->wd_res, (off))
|
||||||
bus_space_read_4((sc)->wd_bst, (sc)->wd_bsh, (off))
|
#define viawd_write_4(sc, off, val) \
|
||||||
#define viawd_write_wd_4(sc, off, val) \
|
bus_write_4((sc)->wd_res, (off), (val))
|
||||||
bus_space_write_4((sc)->wd_bst, (sc)->wd_bsh, (off), (val))
|
|
||||||
|
|
||||||
static struct viawd_device viawd_devices[] = {
|
static struct viawd_device viawd_devices[] = {
|
||||||
{ DEVICEID_VT8251, "VIA VT8251 watchdog timer" },
|
{ DEVICEID_VT8251, "VIA VT8251 watchdog timer" },
|
||||||
@ -58,37 +57,17 @@ static struct viawd_device viawd_devices[] = {
|
|||||||
|
|
||||||
static devclass_t viawd_devclass;
|
static devclass_t viawd_devclass;
|
||||||
|
|
||||||
static device_t
|
|
||||||
viawd_find(struct viawd_device **id_p)
|
|
||||||
{
|
|
||||||
struct viawd_device *id;
|
|
||||||
device_t sb_dev = NULL;
|
|
||||||
|
|
||||||
/* Look for a supported VIA south bridge. */
|
|
||||||
for (id = viawd_devices; id->desc != NULL; ++id)
|
|
||||||
if ((sb_dev = pci_find_device(VENDORID_VIA, id->device)) != NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (sb_dev == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
if (id_p != NULL)
|
|
||||||
*id_p = id;
|
|
||||||
|
|
||||||
return (sb_dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
viawd_tmr_state(struct viawd_softc *sc, int enable)
|
viawd_tmr_state(struct viawd_softc *sc, int enable)
|
||||||
{
|
{
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
|
|
||||||
reg = viawd_read_wd_4(sc, VIAWD_MEM_CTRL);
|
reg = viawd_read_4(sc, VIAWD_MEM_CTRL);
|
||||||
if (enable)
|
if (enable)
|
||||||
reg |= VIAWD_MEM_CTRL_TRIGGER | VIAWD_MEM_CTRL_ENABLE;
|
reg |= VIAWD_MEM_CTRL_TRIGGER | VIAWD_MEM_CTRL_ENABLE;
|
||||||
else
|
else
|
||||||
reg &= ~VIAWD_MEM_CTRL_ENABLE;
|
reg &= ~VIAWD_MEM_CTRL_ENABLE;
|
||||||
viawd_write_wd_4(sc, VIAWD_MEM_CTRL, reg);
|
viawd_write_4(sc, VIAWD_MEM_CTRL, reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -101,7 +80,7 @@ viawd_tmr_set(struct viawd_softc *sc, unsigned int timeout)
|
|||||||
else if (timeout > VIAWD_MEM_COUNT_MAX)
|
else if (timeout > VIAWD_MEM_COUNT_MAX)
|
||||||
timeout = VIAWD_MEM_COUNT_MAX;
|
timeout = VIAWD_MEM_COUNT_MAX;
|
||||||
|
|
||||||
viawd_write_wd_4(sc, VIAWD_MEM_COUNT, timeout);
|
viawd_write_4(sc, VIAWD_MEM_COUNT, timeout);
|
||||||
sc->timeout = timeout;
|
sc->timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,35 +106,40 @@ viawd_event(void *arg, unsigned int cmd, int *error)
|
|||||||
viawd_tmr_state(sc, 0);
|
viawd_tmr_state(sc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Look for a supported VIA south bridge. */
|
||||||
|
static struct viawd_device *
|
||||||
|
viawd_find(device_t dev)
|
||||||
|
{
|
||||||
|
struct viawd_device *id;
|
||||||
|
|
||||||
|
if (pci_get_vendor(dev) != VENDORID_VIA)
|
||||||
|
return (NULL);
|
||||||
|
for (id = viawd_devices; id->desc != NULL; id++)
|
||||||
|
if (pci_get_device(dev) == id->device)
|
||||||
|
return (id);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
viawd_identify(driver_t *driver, device_t parent)
|
viawd_identify(driver_t *driver, device_t parent)
|
||||||
{
|
{
|
||||||
device_t dev;
|
|
||||||
device_t sb_dev;
|
|
||||||
struct viawd_device *id_p;
|
|
||||||
|
|
||||||
sb_dev = viawd_find(&id_p);
|
if (viawd_find(parent) == NULL)
|
||||||
if (sb_dev == NULL)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Good, add child to bus. */
|
if (device_find_child(parent, driver->name, -1) == NULL)
|
||||||
if ((dev = device_find_child(parent, driver->name, 0)) == NULL)
|
BUS_ADD_CHILD(parent, 0, driver->name, 0);
|
||||||
dev = BUS_ADD_CHILD(parent, 0, driver->name, 0);
|
|
||||||
|
|
||||||
if (dev == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
device_set_desc_copy(dev, id_p->desc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
viawd_probe(device_t dev)
|
viawd_probe(device_t dev)
|
||||||
{
|
{
|
||||||
|
struct viawd_device *id;
|
||||||
|
|
||||||
/* Do not claim some ISA PnP device by accident. */
|
id = viawd_find(device_get_parent(dev));
|
||||||
if (isa_get_logicalid(dev) != 0)
|
KASSERT(id != NULL, ("parent should be a valid VIA SB"));
|
||||||
return (ENXIO);
|
device_set_desc(dev, id->desc);
|
||||||
return (0);
|
return (BUS_PROBE_GENERIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -163,13 +147,12 @@ viawd_attach(device_t dev)
|
|||||||
{
|
{
|
||||||
device_t sb_dev;
|
device_t sb_dev;
|
||||||
struct viawd_softc *sc;
|
struct viawd_softc *sc;
|
||||||
struct viawd_device *id_p;
|
|
||||||
uint32_t pmbase, reg;
|
uint32_t pmbase, reg;
|
||||||
|
|
||||||
sc = device_get_softc(dev);
|
sc = device_get_softc(dev);
|
||||||
sc->dev = dev;
|
sc->dev = dev;
|
||||||
|
|
||||||
sb_dev = viawd_find(&id_p);
|
sb_dev = device_get_parent(dev);
|
||||||
if (sb_dev == NULL) {
|
if (sb_dev == NULL) {
|
||||||
device_printf(dev, "Can not find watchdog device.\n");
|
device_printf(dev, "Can not find watchdog device.\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -193,16 +176,14 @@ viawd_attach(device_t dev)
|
|||||||
device_printf(dev, "Unable to map watchdog memory\n");
|
device_printf(dev, "Unable to map watchdog memory\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
sc->wd_bst = rman_get_bustag(sc->wd_res);
|
|
||||||
sc->wd_bsh = rman_get_bushandle(sc->wd_res);
|
|
||||||
|
|
||||||
/* Check if watchdog fired last boot. */
|
/* Check if watchdog fired last boot. */
|
||||||
reg = viawd_read_wd_4(sc, VIAWD_MEM_CTRL);
|
reg = viawd_read_4(sc, VIAWD_MEM_CTRL);
|
||||||
if (reg & VIAWD_MEM_CTRL_FIRED) {
|
if (reg & VIAWD_MEM_CTRL_FIRED) {
|
||||||
device_printf(dev,
|
device_printf(dev,
|
||||||
"ERROR: watchdog rebooted the system\n");
|
"ERROR: watchdog rebooted the system\n");
|
||||||
/* Reset bit state. */
|
/* Reset bit state. */
|
||||||
viawd_write_wd_4(sc, VIAWD_MEM_CTRL, reg);
|
viawd_write_4(sc, VIAWD_MEM_CTRL, reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register the watchdog event handler. */
|
/* Register the watchdog event handler. */
|
||||||
@ -233,7 +214,7 @@ viawd_detach(device_t dev)
|
|||||||
* Do not stop the watchdog on shutdown if active but bump the
|
* Do not stop the watchdog on shutdown if active but bump the
|
||||||
* timer to avoid spurious reset.
|
* timer to avoid spurious reset.
|
||||||
*/
|
*/
|
||||||
reg = viawd_read_wd_4(sc, VIAWD_MEM_CTRL);
|
reg = viawd_read_4(sc, VIAWD_MEM_CTRL);
|
||||||
if (reg & VIAWD_MEM_CTRL_ENABLE) {
|
if (reg & VIAWD_MEM_CTRL_ENABLE) {
|
||||||
viawd_tmr_set(sc, VIAWD_TIMEOUT_SHUTDOWN);
|
viawd_tmr_set(sc, VIAWD_TIMEOUT_SHUTDOWN);
|
||||||
viawd_tmr_state(sc, 1);
|
viawd_tmr_state(sc, 1);
|
||||||
@ -264,23 +245,4 @@ static driver_t viawd_driver = {
|
|||||||
sizeof(struct viawd_softc),
|
sizeof(struct viawd_softc),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
DRIVER_MODULE(viawd, isab, viawd_driver, viawd_devclass, NULL, NULL);
|
||||||
viawd_modevent(module_t mode, int type, void *data)
|
|
||||||
{
|
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case MOD_LOAD:
|
|
||||||
printf("viawd module loaded\n");
|
|
||||||
break;
|
|
||||||
case MOD_UNLOAD:
|
|
||||||
printf("viawd module unloaded\n");
|
|
||||||
break;
|
|
||||||
case MOD_SHUTDOWN:
|
|
||||||
printf("viawd module shutting down\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return (error);
|
|
||||||
}
|
|
||||||
|
|
||||||
DRIVER_MODULE(viawd, isa, viawd_driver, viawd_devclass, viawd_modevent, NULL);
|
|
||||||
|
@ -40,8 +40,6 @@ struct viawd_softc {
|
|||||||
|
|
||||||
int wd_rid;
|
int wd_rid;
|
||||||
struct resource *wd_res;
|
struct resource *wd_res;
|
||||||
bus_space_tag_t wd_bst;
|
|
||||||
bus_space_handle_t wd_bsh;
|
|
||||||
|
|
||||||
eventhandler_tag ev_tag;
|
eventhandler_tag ev_tag;
|
||||||
unsigned int timeout;
|
unsigned int timeout;
|
||||||
|
Loading…
Reference in New Issue
Block a user