Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Feb 2012 20:31:42 +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: r231226 - in head: etc sys/dev/acpica
Message-ID:  <201202082031.q18KVgdC062099@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jkim
Date: Wed Feb  8 20:31:42 2012
New Revision: 231226
URL: http://svn.freebsd.org/changeset/base/231226

Log:
  Revert r211288 and move the logic to the acpi_timer itself.

Modified:
  head/etc/rc.resume
  head/etc/rc.suspend
  head/sys/dev/acpica/acpi_timer.c

Modified: head/etc/rc.resume
==============================================================================
--- head/etc/rc.resume	Wed Feb  8 19:31:32 2012	(r231225)
+++ head/etc/rc.resume	Wed Feb  8 20:31:42 2012	(r231226)
@@ -43,12 +43,6 @@ if [ -r /var/run/rc.suspend.pid ]; then
 	echo 'rc.resume: killed rc.suspend that was still around'
 fi
 
-if [ -r /var/run/rc.suspend.tch ]; then
-	_t=`cat /var/run/rc.suspend.tch`
-	/sbin/sysctl -n kern.timecounter.hardware=$_t > /dev/null 2>&1
-	/bin/rm -f /var/run/rc.suspend.tch
-fi
-
 if [ -r /var/run/moused.pid ]; then
 	pkill -HUP -F /var/run/moused.pid
 fi

Modified: head/etc/rc.suspend
==============================================================================
--- head/etc/rc.suspend	Wed Feb  8 19:31:32 2012	(r231225)
+++ head/etc/rc.suspend	Wed Feb  8 20:31:42 2012	(r231226)
@@ -43,18 +43,6 @@ fi
 
 echo $$ 2> /dev/null > /var/run/rc.suspend.pid
 
-_t=`/sbin/sysctl -n kern.timecounter.hardware 2> /dev/null`
-case ${_t#ACPI-} in
-fast|safe)
-	/bin/rm -f /var/run/rc.suspend.tch
-	;;
-*)
-	{ /sbin/sysctl -n kern.timecounter.hardware=ACPI-fast || \
-	    /sbin/sysctl -n kern.timecounter.hardware=ACPI-safe; } \
-	    > /dev/null 2>&1 && echo $_t > /var/run/rc.suspend.tch
-	;;
-esac
-
 # If you have troubles on suspending with PC-CARD modem, try this.
 # See also contrib/pccardq.c (Only for PAO users).
 # pccardq | awk -F '~' '$5 == "filled" && $4 ~ /uart/ \

Modified: head/sys/dev/acpica/acpi_timer.c
==============================================================================
--- head/sys/dev/acpica/acpi_timer.c	Wed Feb  8 19:31:32 2012	(r231225)
+++ head/sys/dev/acpica/acpi_timer.c	Wed Feb  8 20:31:42 2012	(r231226)
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
 #include "opt_acpi.h"
 #include <sys/param.h>
 #include <sys/bus.h>
+#include <sys/eventhandler.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
 #include <sys/sysctl.h>
@@ -60,12 +61,15 @@ static device_t			acpi_timer_dev;
 static struct resource		*acpi_timer_reg;
 static bus_space_handle_t	acpi_timer_bsh;
 static bus_space_tag_t		acpi_timer_bst;
+static eventhandler_tag		acpi_timer_eh;
 
 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 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);
@@ -77,6 +81,7 @@ 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}
 };
@@ -247,6 +252,49 @@ acpi_timer_attach(device_t dev)
     return (0);
 }
 
+static void
+acpi_timer_resume_handler(struct timecounter *newtc)
+{
+	struct timecounter *tc;
+
+	tc = timecounter;
+	if (tc != newtc) {
+		if (bootverbose)
+			device_printf(acpi_timer_dev,
+			    "restoring timecounter, %s -> %s\n",
+			    tc->tc_name, newtc->tc_name);
+		(void)newtc->tc_get_timecount(newtc);
+		(void)newtc->tc_get_timecount(newtc);
+		timecounter = newtc;
+	}
+}
+
+static int
+acpi_timer_suspend(device_t dev)
+{
+	struct timecounter *newtc, *tc;
+	int error;
+
+	error = bus_generic_suspend(dev);
+	if (acpi_timer_eh != NULL) {
+		EVENTHANDLER_DEREGISTER(power_resume, acpi_timer_eh);
+		acpi_timer_eh = NULL;
+	}
+	tc = timecounter;
+	newtc = &acpi_timer_timecounter;
+	if (tc != newtc) {
+		if (bootverbose)
+			device_printf(dev, "switching timecounter, %s -> %s\n",
+			    tc->tc_name, newtc->tc_name);
+		(void)acpi_timer_read();
+		(void)acpi_timer_read();
+		timecounter = newtc;
+		acpi_timer_eh = EVENTHANDLER_REGISTER(power_resume,
+		    acpi_timer_resume_handler, tc, EVENTHANDLER_PRI_LAST);
+	}
+	return (error);
+}
+
 /*
  * Fetch current time value from reliable hardware.
  */



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