Refine r231226. Swap timecounters before suspending any device drivers.

This commit is contained in:
Jung-uk Kim 2012-02-09 17:38:08 +00:00
parent 870f517ed9
commit 6303ae4d5c

View File

@ -68,8 +68,8 @@ static u_int acpi_timer_frequency = 14318182 / 4;
static void acpi_timer_identify(driver_t *driver, device_t parent);
static int acpi_timer_probe(device_t dev);
static int acpi_timer_attach(device_t dev);
static int acpi_timer_suspend(device_t);
static void acpi_timer_resume_handler(struct timecounter *);
static void acpi_timer_suspend_handler(struct timecounter *);
static u_int acpi_timer_get_timecount(struct timecounter *tc);
static u_int acpi_timer_get_timecount_safe(struct timecounter *tc);
static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS);
@ -81,7 +81,6 @@ static device_method_t acpi_timer_methods[] = {
DEVMETHOD(device_identify, acpi_timer_identify),
DEVMETHOD(device_probe, acpi_timer_probe),
DEVMETHOD(device_attach, acpi_timer_attach),
DEVMETHOD(device_suspend, acpi_timer_suspend),
{0, 0}
};
@ -249,6 +248,12 @@ acpi_timer_attach(device_t dev)
return (ENXIO);
acpi_timer_bsh = rman_get_bushandle(acpi_timer_reg);
acpi_timer_bst = rman_get_bustag(acpi_timer_reg);
/* Register suspend event handler. */
if (EVENTHANDLER_REGISTER(power_suspend, acpi_timer_suspend_handler,
&acpi_timer_timecounter, EVENTHANDLER_PRI_LAST) == NULL)
device_printf(dev, "failed to register suspend event handler\n");
return (0);
}
@ -269,22 +274,25 @@ acpi_timer_resume_handler(struct timecounter *newtc)
}
}
static int
acpi_timer_suspend(device_t dev)
static void
acpi_timer_suspend_handler(struct timecounter *newtc)
{
struct timecounter *newtc, *tc;
int error;
struct timecounter *tc;
error = bus_generic_suspend(dev);
/* Deregister existing resume event handler. */
if (acpi_timer_eh != NULL) {
EVENTHANDLER_DEREGISTER(power_resume, acpi_timer_eh);
acpi_timer_eh = NULL;
}
KASSERT(newtc == &acpi_timer_timecounter,
("acpi_timer_suspend_handler: wrong timecounter"));
tc = timecounter;
newtc = &acpi_timer_timecounter;
if (tc != newtc) {
if (bootverbose)
device_printf(dev, "switching timecounter, %s -> %s\n",
device_printf(acpi_timer_dev,
"switching timecounter, %s -> %s\n",
tc->tc_name, newtc->tc_name);
(void)acpi_timer_read();
(void)acpi_timer_read();
@ -292,7 +300,6 @@ acpi_timer_suspend(device_t dev)
acpi_timer_eh = EVENTHANDLER_REGISTER(power_resume,
acpi_timer_resume_handler, tc, EVENTHANDLER_PRI_LAST);
}
return (error);
}
/*