From owner-acpi-jp@jp.FreeBSD.org Mon Dec 24 13:18:19 2001
Received: (from daemon@localhost)
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) id fBO4IJ291734;
	Mon, 24 Dec 2001 13:18:19 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [192.108.102.143])
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) with ESMTP/inet id fBO4IIT91729
	for <acpi-jp@jp.FreeBSD.org>; Mon, 24 Dec 2001 13:18:18 +0900 (JST)
	(envelope-from qhwt@myrealbox.com)
Received: from localhost qhwt@smtp-send.myrealbox.com [211.18.233.194]
	by smtp-send.myrealbox.com with Novell NIMS $Revision:   2.88  $ on Novell NetWare;
	Sun, 23 Dec 2001 21:18:09 -0700
Date: Mon, 24 Dec 2001 13:18:47 +0900
From: qhwt@myrealbox.com
To: acpi-jp@jp.FreeBSD.org
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="OXfL5xGRrasGEqWY"
Content-Disposition: inline
User-Agent: Mutt/1.3.23i-ja0
Message-Id: <20011224131851D.qhwt@myrealbox.com>
X-Dispatcher: imput version 20000228(IM140)
Lines: 149
Reply-To: acpi-jp@jp.FreeBSD.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+011218
X-Sequence: acpi-jp 1551
Subject: [acpi-jp 1551] workaround(again) for PCG-C1XE not waking up from sleep state
Errors-To: owner-acpi-jp@jp.FreeBSD.org
Sender: owner-acpi-jp@jp.FreeBSD.org
X-Originator: qhwt@myrealbox.com


--OXfL5xGRrasGEqWY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi.
Being tired after tweaking some acpi code for VAIO to work, I'm asking
for a help: where should I set WakeEnable field in AcpiGbl_GpeRegisters[]
so that my VAIO wakes up happily?

My VAIO, PCG-C1XE, has been unable to wake up from sleep state since several
months ago. At first I thought it was a bug in hwgpe.c in the Intel code,
based on the fact that inserting a call to AcpiHwEnableGpeWakeup() at
the end of AcpiHwEnableGpe() seemed to fix my problem. This was wrong.
The "fix" locked other person's machine on shutdown.

The next thing I tried was to change ACPI_OS_NAME to "Microsoft Windows"
as there were a few lines comparing \_OS_ against "Microsoft Windows",
especially the following _WAK method:
----------------------------------------------------------------
Method(_WAK, 1) {
    Store(0x0, \_SB_.PCI0.CRST)
    If(LEqual(Arg0, 0x1)) {
        PHS_(0xe0)
    }
    If(LEqual(Arg0, 0x4)) {
        \_SB_.PCI0.ISA_.SPIC._SRS(\_SB_.PCI0.ISA_.SPIC.SSRC)
    }
    If(LEqual(SCMP(\_OS_, "Microsoft Windows"), Zero)) {
        Notify(\_SB_.PWRB, 0x2)
    }
    Else {
        Noop
    }
    Return(Zero)
}
----------------------------------------------------------------
But this didn't help.

Recently, while reading ASL output from acpidump, I found there are lines
in the asl code which looked like this:

----------------------------------------------------------------
scope(\_GPE) {
    Method(_L0B) {
        Notify(\_SB_.PWRB, 0x2)
    }
    Method(_L0A) {
        Notify(\_SB_.PCI0, 0x2)
    }
    Method(_L08) {
        Notify(\_SB_.PCI0.USB0, 0x2)
    }
    Name(_PRW, Package(0x2) {
        0xb,
        0x4,
    })
}
----------------------------------------------------------------

Index: evevent.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/contrib/dev/acpica/evevent.c,v
retrieving revision 1.1.1.13
diff -u -u -r1.1.1.13 evevent.c
--- evevent.c	28 Nov 2001 04:29:37 -0000	1.1.1.13
+++ evevent.c	24 Dec 2001 03:35:01 -0000
@@ -644,6 +644,7 @@
      * Enable the GPE (SCIs should be disabled at this point)
      */
     AcpiHwEnableGpe (GpeNumber);
+    AcpiHwEnableGpeForWakeup (GpeNumber);
 
     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Registered GPE method %s as GPE number %X\n",
         Name, GpeNumber));

With this change it actually woke up, but only once, because the WakeEnable
field is cleared in AcpiHwDisableGpeForWakeup() called from AcpiHwDisableGpe().
The Gpe number needed to be set to wake up from sleep state was 11.

Attached are the current workaround for my VAIO. The second workaround is
needed when waking up from S1 state after any other sleep state(S3);
(misdev & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE)) is true after waking up from S1,
but scp->dev_param[SLAVE] is NULL, which leads to a panic. The real problem
may be in the acpi code handling S3 state, but I haven't investigated it yet.

By the way, I'm someone formerly called myself neckpain@nettaxi.com,
although I can't prove it.

Regards.

--OXfL5xGRrasGEqWY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="acpi.c.diff"

Index: sys/dev/acpica/acpi.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/dev/acpica/acpi.c,v
retrieving revision 1.53
diff -u -u -r1.53 acpi.c
--- sys/dev/acpica/acpi.c	9 Dec 2001 18:02:36 -0000	1.53
+++ sys/dev/acpica/acpi.c	24 Dec 2001 03:00:38 -0000
@@ -1338,6 +1338,7 @@
     case ACPI_STATE_S2:
     case ACPI_STATE_S3:
     case ACPI_STATE_S4:
+	AcpiEnableEvent(11, ACPI_EVENT_GPE, ACPI_EVENT_WAKE_ENABLE);
 	status = AcpiHwObtainSleepTypeRegisterData((UINT8)state, &TypeA, &TypeB);
 	if (status != AE_OK) {
 	    device_printf(sc->acpi_dev, "AcpiHwObtainSleepTypeRegisterData failed - %s\n", AcpiFormatException(status));

--OXfL5xGRrasGEqWY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ata-all.c.diff"

Index: sys/dev/ata/ata-all.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/dev/ata/ata-all.c,v
retrieving revision 1.125
diff -u -u -r1.125 ata-all.c
--- sys/dev/ata/ata-all.c	14 Dec 2001 21:23:19 -0000	1.125
+++ sys/dev/ata/ata-all.c	23 Dec 2001 15:39:48 -0000
@@ -834,12 +834,20 @@
 	    atapi_detach(scp->dev_softc[SLAVE]);
 #endif
 	if (misdev & ATA_ATA_MASTER || misdev & ATA_ATAPI_MASTER) {
-	    free(scp->dev_param[MASTER], M_ATA);
-	    scp->dev_param[MASTER] = NULL;
+	    if (scp->dev_param[MASTER] == NULL)
+		ata_printf(scp, -1, "scp->dev_param[MASTER] already freed.");
+	    else {
+		free(scp->dev_param[MASTER], M_ATA);
+		scp->dev_param[MASTER] = NULL;
+	    }
 	}
 	if (misdev & ATA_ATA_SLAVE || misdev & ATA_ATAPI_SLAVE) {
-	    free(scp->dev_param[SLAVE], M_ATA);
-	    scp->dev_param[SLAVE] = NULL;
+	    if (scp->dev_param[SLAVE] == NULL)
+		ata_printf(scp, -1, "scp->dev_param[SLAVE] already freed.");
+	    else {
+		free(scp->dev_param[SLAVE], M_ATA);
+		scp->dev_param[SLAVE] = NULL;
+	    }
 	}
     }
     if ((newdev = ~devices & scp->devices)) {

--OXfL5xGRrasGEqWY--
