From owner-acpi-jp@jp.freebsd.org  Mon Sep  4 01:25:56 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id BAA32031;
	Mon, 4 Sep 2000 01:25:56 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (daemon@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id BAA32026
	for <acpi-jp@jp.freebsd.org>; Mon, 4 Sep 2000 01:25:55 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (iwasaki.imasy.or.jp [202.227.24.92])
	by tasogare.imasy.or.jp (8.10.2+3.3W/3.7W-tasogare/smtpfeed 1.07) with ESMTP id e83GPqr88583
	for <acpi-jp@jp.freebsd.org>; Mon, 4 Sep 2000 01:25:52 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
To: acpi-jp@jp.freebsd.org
In-Reply-To: <20000903233326T.iwasaki@jp.FreeBSD.org>
References: <20000903110017W.iwasaki@jp.FreeBSD.org>
	<200009030819.RAA05675@libr.scitec.kobe-u.ac.jp>
	<20000903233326T.iwasaki@jp.FreeBSD.org>
X-Mailer: Mew version 1.94.1 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Message-Id: <20000904012529C.iwasaki@jp.FreeBSD.org>
Date: Mon, 04 Sep 2000 01:25:29 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 20000228(IM140)
Lines: 183
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: acpi-jp 609
Subject: [acpi-jp 609] Re: acpi_send_pm_event() 
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

> > $B$s!"J#?t$J$N$O5$$K$7$J$/$FNI$$$G$9$1$I(B($B!)(B)$B!"L5$$>l9g$D$^$j(BPnPBIOS$B$,L5$$(B
> > $B>l9g$OLdBj$K$J$k$H;W$$$^$9!#(B
> 
> $B$=$&$+!"$G$O$3$NL\E*$N$?$a$@$1$K(B mandatory $B$J%G%P%$%9$H$7$F2>A[$J$d$D$r(B
> $B?7$?$K:n$j!"0l8D$@$1(B static wiring $B$9$k$h$&$K$9$l$P$$$$$+$b!#(B
> $B8e$G$A$g$C$H$d$C$F$_$^$9!#(B

$B$=$&$$$($P(B server $B$H$+$G$O(B mandatory $B$G$"$kI,MW$O$J$$$N$G!"(Boptional $B$G(B
$B$$$$$s$G$9$M!#L>A0$O(B pmtimer $B$K$7$^$7$?!#;XDj$5$l$?>l9g$K0l8D$@$1:n$j!"(B
$BJ#?t$O:n$i$J$$$h$&$K!"JQ$J??;w$7$F$$$^$9(B (^^;
$B$H$j$"$($:(B
 % dmesg | grep pmtimer
 pmtimer0 on isa0
 % dmesg | grep slept
 wakeup from sleeping state (slept 00:00:11)	# by apm
 wakeup from sleeping state (slept 00:00:19)	# by acpi
$B$&$^$/$$$C$F$$$k$h$&$G$9!#$40U8+;r$j$?$/!#(B

Index: conf/files.i386
===================================================================
RCS file: /home/ncvs/src/sys/conf/files.i386,v
retrieving revision 1.326
diff -u -r1.326 files.i386
--- conf/files.i386	2000/09/02 12:43:43	1.326
+++ conf/files.i386	2000/09/03 14:55:28
@@ -265,6 +265,7 @@
 i386/isa/pcvt/pcvt_out.c	optional	vt
 i386/isa/pcvt/pcvt_sup.c	optional	vt
 i386/isa/pcvt/pcvt_vtf.c	optional	vt
+i386/isa/pmtimer.c		optional	pmtimer
 i386/isa/prof_machdep.c		optional	profiling-routine
 i386/isa/rc.c			count		rc
 #i386/isa/rp.c			optional	rp


/*-
 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	$FreeBSD$
 */

/*
 * Timer device driver for power management events.
 * The code for suspend/resume is derived from APM device driver.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/syslog.h>
#include <machine/clock.h>

static void
pmtimer_identify(driver_t *driver, device_t parent)
{
	device_t child;

	child = BUS_ADD_CHILD(parent, 0, "pmtimer", 0);
	if (child == NULL)
		panic("pmtimer_identify");
}

static int
pmtimer_probe(device_t dev)
{

	/* only one instance always */
	return (device_get_unit(dev));
}

static int
pmtimer_attach(device_t dev)
{

	return (0);
}

static struct timeval suspend_time;
static struct timeval diff_time;

static int
pmtimer_suspend(device_t dev)
{
	int	pl;

	pl = splsoftclock();
	microtime(&diff_time);
	inittodr(0);
	microtime(&suspend_time);
	timevalsub(&diff_time, &suspend_time);
	splx(pl);
	return (0);
}

static int
pmtimer_resume(device_t dev)
{
	int pl;
	u_int second, minute, hour;
	struct timeval resume_time, tmp_time;

	/* modified for adjkerntz */
	pl = splsoftclock();
	i8254_restore();		/* restore timer_freq and hz */
	inittodr(0);			/* adjust time to RTC */
	microtime(&resume_time);
	getmicrotime(&tmp_time);
	timevaladd(&tmp_time, &diff_time);

#ifdef FIXME
	/* XXX THIS DOESN'T WORK!!! */
	time = tmp_time;
#endif

#ifdef PMTIMER_FIXUP_CALLTODO
	/* Calculate the delta time suspended */
	timevalsub(&resume_time, &suspend_time);
	/* Fixup the calltodo list with the delta time. */
	adjust_timeout_calltodo(&resume_time);
#endif /* PMTIMER_FIXUP_CALLTODOK */
	splx(pl);
#ifndef PMTIMER_FIXUP_CALLTODO
	second = resume_time.tv_sec - suspend_time.tv_sec; 
#else /* PMTIMER_FIXUP_CALLTODO */
	/* 
	 * We've already calculated resume_time to be the delta between 
	 * the suspend and the resume. 
	 */
	second = resume_time.tv_sec; 
#endif /* PMTIMER_FIXUP_CALLTODO */
	hour = second / 3600;
	second %= 3600;
	minute = second / 60;
	second %= 60;
	log(LOG_NOTICE, "wakeup from sleeping state (slept %02d:%02d:%02d)\n",
		hour, minute, second);
	return (0);
}

static device_method_t pmtimer_methods[] = {
	/* Device interface */
	DEVMETHOD(device_identify,	pmtimer_identify),
	DEVMETHOD(device_probe,		pmtimer_probe),
	DEVMETHOD(device_attach,	pmtimer_attach),
	DEVMETHOD(device_detach,	bus_generic_detach),
	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
	DEVMETHOD(device_suspend,	pmtimer_suspend),
	DEVMETHOD(device_resume,	pmtimer_resume),
	{ 0, 0 }
};

static driver_t pmtimer_driver = {
	"pmtimer",
	pmtimer_methods,
	1,		/* no softc */
};

static devclass_t pmtimer_devclass;

DRIVER_MODULE(pmtimer, isa, pmtimer_driver, pmtimer_devclass, 0, 0);
