Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Feb 2012 22:10:49 +0000 (UTC)
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r232083 - in stable/9: etc sys/dev/acpica
Message-ID:  <201202232210.q1NMAn7a026317@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jkim
Date: Thu Feb 23 22:10:49 2012
New Revision: 232083
URL: http://svn.freebsd.org/changeset/base/232083

Log:
  MFC:	r231226, r231295
  
  Revert r211288 and move the logic to the acpi_timer itself.

Modified:
  stable/9/etc/rc.resume
  stable/9/etc/rc.suspend
  stable/9/sys/dev/acpica/acpi_timer.c
Directory Properties:
  stable/9/etc/   (props changed)
  stable/9/sys/   (props changed)

Modified: stable/9/etc/rc.resume
==============================================================================
--- stable/9/etc/rc.resume	Thu Feb 23 22:03:20 2012	(r232082)
+++ stable/9/etc/rc.resume	Thu Feb 23 22:10:49 2012	(r232083)
@@ -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
-
 # Turns on a power supply of a card in the slot inactivated.
 # See also contrib/pccardq.c (only for PAO users).
 # pccardq | awk -F '~' '$5 == "inactive" \

Modified: stable/9/etc/rc.suspend
==============================================================================
--- stable/9/etc/rc.suspend	Thu Feb 23 22:03:20 2012	(r232082)
+++ stable/9/etc/rc.suspend	Thu Feb 23 22:10:49 2012	(r232083)
@@ -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: stable/9/sys/dev/acpica/acpi_timer.c
==============================================================================
--- stable/9/sys/dev/acpica/acpi_timer.c	Thu Feb 23 22:03:20 2012	(r232082)
+++ stable/9/sys/dev/acpica/acpi_timer.c	Thu Feb 23 22:10:49 2012	(r232083)
@@ -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 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);
@@ -244,9 +248,60 @@ 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);
 }
 
+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 void
+acpi_timer_suspend_handler(struct timecounter *newtc)
+{
+	struct timecounter *tc;
+
+	/* 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;
+	if (tc != newtc) {
+		if (bootverbose)
+			device_printf(acpi_timer_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);
+	}
+}
+
 /*
  * Fetch current time value from reliable hardware.
  */



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