Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi add MI part of ACPI sleep state transition code.



details:   https://anonhg.NetBSD.org/src/rev/85f978080a1d
branches:  trunk
changeset: 532953:85f978080a1d
user:      tshiozak <tshiozak%NetBSD.org@localhost>
date:      Tue Jun 18 08:09:21 2002 +0000

description:
add MI part of ACPI sleep state transition code.
However, we have no interface to use it, and we also need device driver
support. (e.g. D2/D3 support for PCI)

diffstat:

 sys/dev/acpi/acpi.c    |  80 ++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/acpi/acpivar.h |   7 +++-
 2 files changed, 84 insertions(+), 3 deletions(-)

diffs (123 lines):

diff -r 49236207e396 -r 85f978080a1d sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c       Tue Jun 18 08:01:30 2002 +0000
+++ b/sys/dev/acpi/acpi.c       Tue Jun 18 08:09:21 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi.c,v 1.9 2002/06/17 08:18:51 kanaoka Exp $ */
+/*     $NetBSD: acpi.c,v 1.10 2002/06/18 08:09:21 tshiozak Exp $       */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.9 2002/06/17 08:18:51 kanaoka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.10 2002/06/18 08:09:21 tshiozak Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -53,6 +53,8 @@
 #include <dev/acpi/acpivar.h>
 #include <dev/acpi/acpi_osd.h>
 
+#include <machine/acpi_machdep.h>
+
 #ifdef ENABLE_DEBUGGER
 #define        ACPI_DBGR_INIT          0x01
 #define        ACPI_DBGR_TABLES        0x02
@@ -713,3 +715,77 @@
 
        return ((*getit)(handle, buf));
 }
+
+
+/*****************************************************************************
+ * ACPI sleep support.
+ *****************************************************************************/
+
+static int
+is_available_state(struct acpi_softc *sc, int state)
+{
+       UINT8 type_a, type_b;
+
+       return (ACPI_SUCCESS(AcpiGetSleepTypeData((UINT8)state,
+                                                 &type_a, &type_b)));
+}
+
+/*
+ * acpi_enter_sleep_state:
+ *
+ *     enter to the specified sleep state.
+ */
+
+ACPI_STATUS
+acpi_enter_sleep_state(struct acpi_softc *sc, int state)
+{
+       int s;
+       ACPI_STATUS ret = AE_OK;
+
+       switch (state) {
+       case ACPI_STATE_S0:
+               break;
+       case ACPI_STATE_S1:
+       case ACPI_STATE_S2:
+       case ACPI_STATE_S3:
+       case ACPI_STATE_S4:
+               if (!is_available_state(sc, state)) {
+                       printf("acpi: cannot enter the sleep state (%d).\n",
+                              state);
+                       break;
+               }
+               ret = AcpiEnterSleepStatePrep(state);
+               if (ACPI_FAILURE(ret)) {
+                       printf("acpi: failed preparing to sleep (%s)\n",
+                              AcpiFormatException(ret));
+                       break;
+               }
+               if (state==ACPI_STATE_S1) {
+                       /* just enter the state */
+                       AcpiEnterSleepState((UINT8)state);
+                       AcpiUtReleaseMutex(ACPI_MTX_HARDWARE);
+               } else {
+                       /* XXX: powerhooks(9) framework is too poor to
+                        * support ACPI sleep state...
+                        */
+                       dopowerhooks(PWR_SOFTSUSPEND);
+                       s = splhigh();
+                       dopowerhooks(PWR_SUSPEND);
+                       acpi_md_sleep(state);
+                       dopowerhooks(PWR_RESUME);
+                       splx(s);
+                       dopowerhooks(PWR_SOFTRESUME);
+                       if (state==ACPI_STATE_S4)
+                               AcpiEnable();
+               }
+               AcpiLeaveSleepState((UINT8)state);
+               break;
+       case ACPI_STATE_S5:
+               AcpiEnterSleepStatePrep(ACPI_STATE_S5);
+               AcpiEnterSleepState(ACPI_STATE_S5);
+               printf("WARNING: powerdown failed!\n");
+               break;
+       }
+
+       return_ACPI_STATUS(ret);
+}
diff -r 49236207e396 -r 85f978080a1d sys/dev/acpi/acpivar.h
--- a/sys/dev/acpi/acpivar.h    Tue Jun 18 08:01:30 2002 +0000
+++ b/sys/dev/acpi/acpivar.h    Tue Jun 18 08:09:21 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpivar.h,v 1.4 2002/03/24 03:32:14 sommerfeld Exp $   */
+/*     $NetBSD: acpivar.h,v 1.5 2002/06/18 08:09:22 tshiozak Exp $     */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -261,3 +261,8 @@
 struct acpi_memrange   *acpi_res_memrange(struct acpi_resources *, int);
 struct acpi_irq                *acpi_res_irq(struct acpi_resources *, int);
 struct acpi_drq                *acpi_res_drq(struct acpi_resources *, int);
+
+/*
+ * power state transition
+ */
+extern ACPI_STATUS     acpi_enter_sleep_state(struct acpi_softc *, int state);



Home | Main Index | Thread Index | Old Index