Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Feb 2012 17:38:08 +0000 (UTC)
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r231295 - head/sys/dev/acpica
Message-ID:  <201202091738.q19Hc8Iv015085@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jkim
Date: Thu Feb  9 17:38:08 2012
New Revision: 231295
URL: http://svn.freebsd.org/changeset/base/231295

Log:
  Refine r231226.  Swap timecounters before suspending any device drivers.

Modified:
  head/sys/dev/acpica/acpi_timer.c

Modified: head/sys/dev/acpica/acpi_timer.c
==============================================================================
--- head/sys/dev/acpica/acpi_timer.c	Thu Feb  9 16:58:06 2012	(r231294)
+++ head/sys/dev/acpica/acpi_timer.c	Thu Feb  9 17:38:08 2012	(r231295)
@@ -68,8 +68,8 @@ static u_int	acpi_timer_frequency = 1431
 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_method
     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 timecou
 	}
 }
 
-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);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202091738.q19Hc8Iv015085>