From owner-acpi-jp@jp.freebsd.org  Sat Nov  3 21:53:11 2001
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id VAA77958;
	Sat, 3 Nov 2001 21:53:11 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (root@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id VAA77953
	for <acpi-jp@jp.freebsd.org>; Sat, 3 Nov 2001 21:53:11 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (iwasaki.imasy.or.jp [202.227.24.92])
	(authenticated as iwa with CRAM-MD5)
	by tasogare.imasy.or.jp (8.11.6+3.4W/8.11.6/tasogare) with ESMTP/inet id fA3Cr4W41726;
	Sat, 3 Nov 2001 21:53:04 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Date: Sat, 03 Nov 2001 21:53:01 +0900 (JST)
Message-Id: <20011103.215301.41626711.iwasaki@jp.FreeBSD.org>
To: andrew.grover@intel.com, robert.moore@intel.com
Cc: acpi-jp@jp.freebsd.org
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Mailer: Mew version 2.0 on Emacs 20.7 / Mule 4.0 (HANANOEN)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+010328
X-Sequence: acpi-jp 1423
Subject: [acpi-jp 1423] ACPICA: revised S4BIOS and DSDT overriding support
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

Hi, Intel folks.  I revised the paches and additional code for ACPI CA
on S4BIOS and DSDT overriding support (first 3 files).  Could you
consider our proposal?

To FreeBSD folks: I'll commit this coming Wednesday.  The paches
contains new files; acpica_support.c and its header.  We can add our
proposed additional code into these files temporary, then remove them
when similar code is added officially.

I'd like to ask you one thing.  Should we have more local patches?
We are trying to keep our local patches as minimum, but so many
people ask about the same problems.  Had we better have more local
fixes frequently until newer snapshot is imported and the problem is
solved?

Thanks

Index: contrib/dev/acpica/tbget.c
===================================================================
RCS file: /home/ncvs/src/sys/contrib/dev/acpica/tbget.c,v
retrieving revision 1.1.1.11
diff -u -r1.1.1.11 tbget.c
--- contrib/dev/acpica/tbget.c	31 Oct 2001 02:32:28 -0000	1.1.1.11
+++ contrib/dev/acpica/tbget.c	3 Nov 2001 07:19:22 -0000
@@ -439,7 +439,9 @@
      * Get the DSDT (We know that the FADT is valid now)
      */
     Status = AcpiTbGetTable ((ACPI_PHYSICAL_ADDRESS) ACPI_GET_ADDRESS (AcpiGbl_FADT->XDsdt),
-                                TablePtr, &TableInfo);
+                                ((AcpiGbl_DSDT) ?
+                                 AcpiGbl_DSDT: TablePtr), &TableInfo);
+
     if (ACPI_FAILURE (Status))
     {
         return_ACPI_STATUS (Status);
--- /dev/null	Sat Nov  3 19:15:56 2001
+++ dev/acpica/acpica_support.c	Sat Nov  3 17:43:59 2001
@@ -0,0 +1,105 @@
+#include "acpi.h"
+#include <dev/acpica/acpica_support.h>
+
+/*
+ * Implement support code temporary here until officially merged into
+ * Intel ACPI CA release.
+ */
+
+/******************************************************************************
+ *
+ * FUNCTION:    AcpiEnterSleepStateS4Bios
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Enter a system sleep state S4BIOS
+ *
+ ******************************************************************************/
+        
+ACPI_STATUS
+AcpiEnterSleepStateS4Bios (
+    void)
+{
+    ACPI_OBJECT_LIST    ArgList;
+    ACPI_OBJECT         Arg;
+
+
+    FUNCTION_TRACE ("AcpiEnterSleepStateS4Bios");
+
+    /* run the _PTS and _GTS methods */
+
+    MEMSET(&ArgList, 0, sizeof(ArgList));
+    ArgList.Count = 1;
+    ArgList.Pointer = &Arg;
+
+    MEMSET(&Arg, 0, sizeof(Arg));
+    Arg.Type = ACPI_TYPE_INTEGER;
+    Arg.Integer.Value = ACPI_STATE_S4;
+
+    AcpiEvaluateObject (NULL, "\\_PTS", &ArgList, NULL);
+    AcpiEvaluateObject (NULL, "\\_GTS", &ArgList, NULL);
+
+    /* clear wake status */
+
+    AcpiHwRegisterBitAccess (ACPI_WRITE, ACPI_MTX_LOCK, WAK_STS, 1);
+
+    disable ();
+
+    AcpiHwDisableNonWakeupGpes();
+
+    /* flush caches */
+
+    wbinvd();
+
+    /* write the value to command port and wait until we enter sleep state */
+    do
+    {
+        AcpiOsStall(1000000);
+        AcpiOsWritePort (AcpiGbl_FADT->SmiCmd, AcpiGbl_FADT->S4BiosReq, 8);
+    }
+    while (!AcpiHwRegisterBitAccess (ACPI_READ, ACPI_MTX_LOCK, WAK_STS));
+
+    AcpiHwEnableNonWakeupGpes();
+
+    enable ();
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiSetDsdtTablePtr
+ *
+ * PARAMETERS:  TablePtr        - pointer to a buffer containing the entire
+ *                                DSDT table to override
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Set DSDT table ptr for DSDT overriding.  This function should
+ *              be called perior than AcpiLoadTables(). 
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiSetDsdtTablePtr(
+    ACPI_TABLE_HEADER   *TablePtr)
+{
+    FUNCTION_TRACE ("AcpiSetDsdtTablePtr");
+
+    if (!TablePtr)
+    {
+        return_ACPI_STATUS (AE_BAD_PARAMETER);
+    }
+
+    if (AcpiGbl_AcpiTables[ACPI_TABLE_DSDT].LoadedIntoNamespace)
+    {
+        return_ACPI_STATUS (AE_EXIST);
+    }
+
+    AcpiGbl_DSDT = TablePtr;
+
+    return_ACPI_STATUS (AE_OK);
+}
+
--- /dev/null	Sat Nov  3 19:15:56 2001
+++ dev/acpica/acpica_support.h	Sat Nov  3 15:19:13 2001
@@ -0,0 +1,10 @@
+#include "acpi.h"
+
+ACPI_STATUS
+AcpiEnterSleepStateS4Bios (
+    void);
+
+ACPI_STATUS
+AcpiSetDsdtTablePtr(
+    ACPI_TABLE_HEADER   *Ptr);
+
Index: boot/forth/loader.conf
===================================================================
RCS file: /home/ncvs/src/sys/boot/forth/loader.conf,v
retrieving revision 1.49
diff -u -r1.49 loader.conf
--- boot/forth/loader.conf	1 Jun 2001 10:07:23 -0000	1.49
+++ boot/forth/loader.conf	3 Nov 2001 09:00:53 -0000
@@ -242,6 +242,15 @@
 atspeaker_load="NO"		# AT speaker module
 
 ##############################################################
+###  ACPI settings  ##########################################
+##############################################################
+
+acpi_dsdt_load="NO"		# DSDT Overriding
+acpi_dsdt_type="acpi_dsdt"	# Don't change this
+acpi_dsdt_name="/boot/acpi_dsdt.aml"
+				# Override DSDT in BIOS by this file
+
+##############################################################
 ###  Module loading syntax example  ##########################
 ##############################################################
 
Index: conf/files
===================================================================
RCS file: /home/ncvs/src/sys/conf/files,v
retrieving revision 1.578
diff -u -r1.578 files
--- conf/files	1 Nov 2001 16:33:11 -0000	1.578
+++ conf/files	2 Nov 2001 21:45:09 -0000
@@ -197,6 +197,7 @@
 dev/aac/aac_disk.c	optional aac
 dev/aac/aac_pci.c	optional aac pci
 dev/acpica/acpi.c		optional acpica
+dev/acpica/acpica_support.c	optional acpica
 dev/acpica/acpi_acad.c		optional acpica
 dev/acpica/acpi_battery.c	optional acpica
 dev/acpica/acpi_button.c	optional acpica
Index: dev/acpica/acpi.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/acpica/acpi.c,v
retrieving revision 1.45
diff -u -r1.45 acpi.c
--- dev/acpica/acpi.c	1 Nov 2001 16:33:17 -0000	1.45
+++ dev/acpica/acpi.c	3 Nov 2001 09:52:49 -0000
@@ -42,6 +42,7 @@
 #include <sys/reboot.h>
 #include <sys/sysctl.h>
 #include <sys/ctype.h>
+#include <sys/linker.h>
 #include <sys/power.h>
 
 #include <machine/clock.h>
@@ -51,6 +52,8 @@
 
 #include "acpi.h"
 
+#include <dev/acpica/acpica_support.h>
+
 #include <dev/acpica/acpivar.h>
 #include <dev/acpica/acpiio.h>
 
@@ -205,6 +208,7 @@
 {
     device_t			child;
     int				error;
+    caddr_t			acpi_dsdt, p;
 #ifdef ENABLE_DEBUGGER
     char			*debugpoint = getenv("debug.acpi.debugger");
 #endif
@@ -247,6 +251,19 @@
     if (debugpoint && !strcmp(debugpoint, "tables"))
 	acpi_EnterDebugger();
 #endif
+
+    if ((acpi_dsdt = preload_search_by_type("acpi_dsdt")) != NULL) {
+        if ((p = preload_search_info(acpi_dsdt, MODINFO_ADDR)) != NULL) {
+	    error = AcpiSetDsdtTablePtr(*(void **)p);
+            if (error != AE_OK) {
+		printf("ACPI: DSDT overriding failed: %s\n",
+		       AcpiFormatException(error));
+	    } else {
+		printf("ACPI: DSDT was overridden.\n");
+	    }
+        }
+    }
+
     if ((error = AcpiLoadTables()) != AE_OK) {
 	printf("ACPI: table load failed: %s\n", AcpiFormatException(error));
 	return_VOID;
@@ -392,6 +409,9 @@
 	OID_AUTO, "suspend_state", CTLTYPE_STRING | CTLFLAG_RW,
 	&sc->acpi_suspend_sx, 0, acpi_sleep_state_sysctl, "A", "");
     SYSCTL_ADD_INT(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
+	OID_AUTO, "s4bios", CTLFLAG_RD | CTLFLAG_RW,
+	&sc->acpi_s4bios, 0, "S4BIOS mode");
+    SYSCTL_ADD_INT(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
 	OID_AUTO, "verbose", CTLFLAG_RD | CTLFLAG_RW,
 	&sc->acpi_verbose, 0, "verbose mode");
     if (bootverbose)
Index: dev/acpica/acpivar.h
===================================================================
RCS file: /home/ncvs/src/sys/dev/acpica/acpivar.h,v
retrieving revision 1.21
diff -u -r1.21 acpivar.h
--- dev/acpica/acpivar.h	30 Oct 2001 14:24:26 -0000	1.21
+++ dev/acpica/acpivar.h	2 Nov 2001 13:35:24 -0000
@@ -60,6 +60,8 @@
     int			acpi_standby_sx;
     int			acpi_suspend_sx;
 
+    int			acpi_s4bios;
+
     int			acpi_verbose;
 
     bus_dma_tag_t	acpi_waketag;
Index: i386/acpica/acpi_wakeup.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/acpica/acpi_wakeup.c,v
retrieving revision 1.3
diff -u -r1.3 acpi_wakeup.c
--- i386/acpica/acpi_wakeup.c	22 Jul 2001 19:13:54 -0000	1.3
+++ i386/acpica/acpi_wakeup.c	3 Nov 2001 09:04:35 -0000
@@ -52,6 +53,8 @@
 
 #include "acpi.h"
 
+#include <dev/acpica/acpica_support.h>
+
 #include <dev/acpica/acpivar.h>
 
 #include "acpi_wakecode.h"
@@ -236,7 +243,13 @@
 			acpi_printcpu();
 		}
 
-		if ((status = AcpiEnterSleepState(state)) != AE_OK) {
+		if (state == ACPI_STATE_S4 && sc->acpi_s4bios) {
+			status = AcpiEnterSleepStateS4Bios();
+		} else {
+			status = AcpiEnterSleepState(state);
+		}
+
+		if (status != AE_OK) {
 			device_printf(sc->acpi_dev,
 				"AcpiEnterSleepState failed - %s\n",
 				AcpiFormatException(status));
Index: modules/acpi/Makefile
===================================================================
RCS file: /home/ncvs/src/sys/modules/acpi/Makefile,v
retrieving revision 1.16
diff -u -r1.16 Makefile
--- modules/acpi/Makefile	31 Oct 2001 02:35:43 -0000	1.16
+++ modules/acpi/Makefile	2 Nov 2001 14:43:30 -0000
@@ -30,6 +30,7 @@
 SRCS+=	acpi.c acpi_acad.c acpi_battery.c acpi_button.c acpi_cmbat.c acpi_cpu.c
 SRCS+=	acpi_ec.c acpi_lid.c acpi_pcib.c acpi_powerprofile.c
 SRCS+=	acpi_powerres.c acpi_resource.c acpi_thermal.c acpi_timer.c
+SRCS+=	acpica_support.c
 SRCS+=  OsdDebug.c 
 SRCS+=	OsdHardware.c OsdInterrupt.c OsdMemory.c OsdSchedule.c
 SRCS+=	OsdStream.c OsdSynch.c OsdEnvironment.c 
