From owner-acpi-jp@jp.freebsd.org  Sun Jun 18 06:18:57 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id GAA61135;
	Sun, 18 Jun 2000 06:18:57 +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 GAA61130
	for <acpi-jp@jp.freebsd.org>; Sun, 18 Jun 2000 06:18:56 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (isdn27.imasy.or.jp [202.227.24.219])
	by tasogare.imasy.or.jp (8.10.1+3.3W/3.7W-tasogare/smtpfeed 1.07) with ESMTP id e5HLIs280118
	for <acpi-jp@jp.freebsd.org>; Sun, 18 Jun 2000 06:18:54 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
To: acpi-jp@jp.freebsd.org
In-Reply-To: <20000617194259W.iwasaki@jp.FreeBSD.org>
References: <20000617194259W.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: <20000618061853F.iwasaki@jp.FreeBSD.org>
Date: Sun, 18 Jun 2000 06:18:53 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 20000228(IM140)
Lines: 390
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: acpi-jp 412
Subject: [acpi-jp 412] Re: driver update
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

$B$J$s$H$J$/(B P2B $B$G(B _PTS $B$H(B _WAK $B$r<B9T$G$-$k$h$&$K$7$F$_$^$7$?!#(B
aml_region.c $B$O(B simulator $B$r;29M$K(B ioport $B$@$1<BAu$7$F$$$^$9!#(B
$B$^$?!"(BACPICA $B$b$A$g$C$H$@$10U<1$7$F(B Osd $BItJ,$r0lIt<BAu$7!"$=$l$r(B
$BMxMQ$9$k$h$&$K$7$F$$$^$9!#(B
# $BE,Ev$K$d$C$?$N$G(B rewrite $B4?7^(B :-)

$B$"$HC/$+(B SystemMemory $B$NItJ,<BAu$7$^$;$s$+(B? $B$3$l$,$G$-$k$H(B
$BB?$/$N5!<o$G=c?h$K(B kernel space $B$G(B S1, S5 $B$G$-$k$h$&$K$J$C$F!"(B
$B%$%s%A%-$NAH$_9~$_(B method $B$r>C$9$3$H$,$G$-$k$s$G$9$,(B...

$B$H$j$"$($:!"$3$s$J46$8$G<B9T$G$-$F$$$^$9(B ($B%O%a%3%_9g@.$G$O$"$j$^$;$s(B)$B!#(B
[\\_PTS. START]
If(LNot(LEqual(Arg0, 0x5))){
    Store(0x0, FANM)[write(From1, 0x0, 0xe434)]	[1:0xff@0xe434]->[1:0x00@0xe434]
[read(From1 , 0xe434)]	[1:0x00@0xe434]
	[read(1, 0xe434)&mask:0x0]

    Store(0x0, PLED)[write(From1, 0x0, 0xe435)]	[1:0xbb@0xe435]->[1:0x00@0xe435]
[read(From1 , 0xe435)]	[1:0x00@0xe435]
	[read(1, 0xe435)&mask:0x0]

}
If(LEqual(Arg0, 0x1)){
    Store(One, TO12)[write(From1, 0x1, 0xe42f)]	[1:0x02@0xe42f]->[1:0x01@0xe42f]
[read(From1 , 0xe42f)]	[1:0x01@0xe42f]
	[read(1, 0xe42f)&mask:0x1]

}
If(LEqual(Arg0, 0x2))
Store(One, TO12)[write(From1, 0x1, 0xe42f)]	[1:0x01@0xe42f]->[1:0x01@0xe42f]
[read(From1 , 0xe42f)]	[1:0x01@0xe42f]
	[read(1, 0xe42f)&mask:0x1]

Or(Arg0, 0xf0, Local2)[Copy number 0xf1]
Store(Local2, DBG1)[write(From1, 0xf1, 0x80)]	[1:0xff@0x80]->[1:0xf1@0x80]
[read(From1 , 0x80)]	[1:0xf1@0x80]
	[read(1, 0x80)&mask:0xf1]

[\\_PTS. END]
_PTS  Method: Arg 1 From 0xc7adb1c7 To 0xc7adb1ff
acpi0: acpi_io_pm1_status(0) = (11, 0)
acpi0: acpi_io_pm1_status(1) = (8000, 8000)
acpi0: acpi_io_pm1_control(1) = (3c00, 3c00)
[\\_WAK. START]
Store(0x1, FANM)[write(From1, 0x1, 0xe434)]	[1:0x00@0xe434]->[1:0x01@0xe434]
[read(From1 , 0xe434)]	[1:0x01@0xe434]
	[read(1, 0xe434)&mask:0x1]

Store(One, PLED)[write(From1, 0x1, 0xe435)]	[1:0x00@0xe435]->[1:0x01@0xe435]
[read(From1 , 0xe435)]	[1:0x01@0xe435]
	[read(1, 0xe435)&mask:0x1]

Store(0xff, DBG1)[write(From1, 0xff, 0x80)]	[1:0xf1@0x80]->[1:0xff@0x80]
[read(From1 , 0x80)]	[1:0xff@0x80]
	[read(1, 0x80)&mask:0xff]

[\\_WAK. END]
_WAK  Method: Arg 1 From 0xc7adb207 To 0xc7adb21b
acpi0: ACPIIO_SETSLPSTATE = 1

Index: acpi.c
===================================================================
RCS file: /home/cvs/ACPI/sys/i386/acpi/acpi.c,v
retrieving revision 1.14
diff -u -r1.14 acpi.c
--- acpi.c	2000/06/17 16:35:34	1.14
+++ acpi.c	2000/06/17 21:14:09
@@ -324,10 +324,12 @@
 	}
 	sc->system_state_package = ssp;
 
+#if 0
 	while (name_group_list->id != AML_NAME_GROUP_ROOT)
 		aml_delete_name_group(name_group_list);
 	memman_statistics(aml_memman);
 	memman_freeall(aml_memman);
+#endif
 }
 
 static void
@@ -2179,11 +2181,31 @@
 static void
 acpi_execute_pts(acpi_softc_t *sc, u_int8_t state)
 {
+#if 0
 	acpi_execute_method(sc, state, ACPI_METHOD_PTS);
+#else
+	union	aml_object argv[1], *retval;
+
+	argv[0].type = aml_t_num;
+	argv[0].num.number = state;
+	aml_local_stack_push(aml_local_stack_create());
+	retval = aml_invoke_method_by_name("_PTS", 1, argv);
+	aml_local_stack_delete(aml_local_stack_pop());
+#endif
 }
 
 static void
 acpi_execute_wak(acpi_softc_t *sc, u_int8_t state)
 {
+#if 0
 	acpi_execute_method(sc, state, ACPI_METHOD_WAK);
+#else
+	union	aml_object argv[1], *retval;
+
+	argv[0].type = aml_t_num;
+	argv[0].num.number = state;
+	aml_local_stack_push(aml_local_stack_create());
+	retval = aml_invoke_method_by_name("_WAK", 1, argv);
+	aml_local_stack_delete(aml_local_stack_pop());
+#endif
 }
Index: aml/aml_region.c
===================================================================
RCS file: /home/cvs/ACPI/sys/i386/acpi/aml/aml_region.c,v
retrieving revision 1.3
diff -u -r1.3 aml_region.c
--- aml/aml_region.c	2000/06/15 14:34:52	1.3
+++ aml/aml_region.c	2000/06/17 20:55:15
@@ -31,14 +31,247 @@
  */
 
 #include <sys/param.h>
+#include <sys/systm.h>
+#include <machine/bus.h>
 
+#include <i386/acpi/aml/aml_common.h>
 #include <i386/acpi/aml/aml_region.h>
 
+/*
+ * ACPICA compatibility
+ */
+typedef unsigned char			UINT8;
+typedef unsigned short			UINT16;
+typedef unsigned int			UINT32;
+typedef UINT32				NATIVE_UINT;
+typedef NATIVE_UINT			ACPI_IO_ADDRESS;
+
+static UINT32	OsdInX(ACPI_IO_ADDRESS, int);
+static void	OsdOutX(ACPI_IO_ADDRESS, UINT32, int);
+
+UINT8		OsdIn8(ACPI_IO_ADDRESS);
+UINT16		OsdIn16(ACPI_IO_ADDRESS);
+UINT32		OsdIn32(ACPI_IO_ADDRESS);
+void		OsdOut8(ACPI_IO_ADDRESS, UINT8);
+void		OsdOut16(ACPI_IO_ADDRESS, UINT16);
+void		OsdOut32(ACPI_IO_ADDRESS, UINT32);
+
+/*
+ * Platform/Hardware independent I/O interfaces
+ */
+
+static UINT32
+OsdInX(ACPI_IO_ADDRESS InPort, int bytes)
+{
+	bus_space_tag_t		bst;
+	bus_space_handle_t	bsh;
+	UINT32			retval;
+
+	bst = I386_BUS_SPACE_IO;
+	bsh = InPort;
+	switch (bytes) {
+	case 1:
+		retval = bus_space_read_1(bst, bsh, 0);
+		break;
+	case 2:
+		retval = bus_space_read_2(bst, bsh, 0);
+		break;
+	case 4:
+		retval = bus_space_read_4(bst, bsh, 0);
+		break;
+	default:
+		printf("OsdInX: wrong length to read\n");
+		retval = 0;
+	}
+	return (retval);
+}
+
+UINT8
+OsdIn8(ACPI_IO_ADDRESS InPort)
+{
+	return (OsdInX(InPort, 1) & 0xff);
+}
+ 
+UINT16
+OsdIn16(ACPI_IO_ADDRESS InPort)
+{
+	return (OsdInX(InPort, 2) & 0xffff);
+}
+ 
+UINT32
+OsdIn32(ACPI_IO_ADDRESS InPort)
+{
+	return (OsdInX(InPort, 4));
+}
+
+static void
+OsdOutX(ACPI_IO_ADDRESS OutPort, UINT32 Value, int bytes)
+{
+	bus_space_tag_t		bst;
+	bus_space_handle_t	bsh;
+
+	bst = I386_BUS_SPACE_IO;
+	bsh = OutPort;
+	switch (bytes) {
+	case 1:
+		bus_space_write_1(bst, bsh, 0, Value & 0xff);
+		break;
+	case 2:
+		bus_space_write_2(bst, bsh, 0, Value & 0xffff);
+		break;
+	case 4:
+		bus_space_write_4(bst, bsh, 0, Value);
+		break;
+	default:
+		printf("OsdOutX: wrong length to write\n");
+	}
+}
+
+void
+OsdOut8(ACPI_IO_ADDRESS OutPort, UINT8 Value)
+{
+	OsdOutX(OutPort, Value, 1);
+}
+
+void    
+OsdOut16(ACPI_IO_ADDRESS OutPort, UINT16 Value)
+{
+	OsdOutX(OutPort, Value, 2);
+}
+
+void
+OsdOut32(ACPI_IO_ADDRESS OutPort, UINT32 Value)
+{
+	OsdOutX(OutPort, Value, 4);
+}
+
+/*
+ * region I/O
+ */
+
+static int	aml_region_io_systemio(int, int, u_int32_t, u_int32_t *,
+				       u_int32_t, u_int32_t, u_int32_t);
+
+#define ACPI_REGION_INPUT	0
+#define ACPI_REGION_OUTPUT	1
+
+static int
+aml_region_io_systemio(int io, int regtype, u_int32_t flags, u_int32_t *valuep,
+    u_int32_t baseaddr, u_int32_t bitoffset, u_int32_t bitlen)
+{
+	u_int8_t	val, tmp, masklow, maskhigh;
+	u_int8_t	offsetlow, offsethigh;
+	u_int32_t	addr, byteoffset, bytelen;
+	int		value, readval;
+	int		state, i;
+
+	value = *valuep;
+	val = readval = 0;
+	masklow = maskhigh = 0xff;
+	state = 0;
+
+	byteoffset = bitoffset / 8;
+	bytelen = bitlen / 8 + ((bitlen % 8) ? 1 : 0);
+	addr = baseaddr + byteoffset;
+	offsetlow = bitoffset % 8;
+	if (bytelen > 1) {
+		offsethigh = (bitlen - (8 - offsetlow)) % 8;
+	} else {
+		offsethigh = 0;
+	}
+
+	if (offsetlow) {
+		masklow = (~((1 << bitlen) - 1) << offsetlow) | \
+		    ~(0xff << offsetlow);
+		AML_PRINTF("\t[offsetlow = 0x%x, masklow = 0x%x, ~masklow = 0x%x]\n",
+		    offsetlow, masklow, ~masklow & 0xff);
+	}
+	if (offsethigh) {
+		maskhigh = 0xff << offsethigh;
+		AML_PRINTF("\t[offsethigh = 0x%x, maskhigh = 0x%x, ~maskhigh = 0x%x]\n",
+		    offsethigh, maskhigh, ~maskhigh & 0xff);
+	}
+	for (i = bytelen; i > 0; i--, addr++) {
+		val = OsdIn8(addr);
+		AML_PRINTF("\t[%d:0x%02x@0x%x]", regtype, val, addr);
+
+		switch (io) {
+		case ACPI_REGION_INPUT:
+			tmp = val;
+			/* the lowest byte? */
+			if (i == bytelen) {
+				if (offsetlow) {
+					readval = tmp & ~masklow;
+				} else {
+					readval = tmp;
+				}
+			} else {
+				if (i == 1 && offsethigh) {
+					tmp = tmp & ~maskhigh;
+				}
+				readval = (tmp << (8 * (bytelen - i))) | readval;
+			}
+
+			AML_PRINTF("\n");
+			/* goto to next byte... */
+			if (i > 1) {
+				continue;
+			}
+			/* final adjustment before finishing region access */
+			if (offsetlow) {
+				readval = readval >> offsetlow;
+			}
+			AML_PRINTF("\t[read(%d, 0x%x)&mask:0x%x]\n",
+			    regtype, addr, readval);
+			value = readval;
+			*valuep = value;
+
+			break;
+		case ACPI_REGION_OUTPUT:
+			tmp = value & 0xff;
+			/* the lowest byte? */
+			if (i == bytelen) {
+				if (offsetlow) {
+					tmp = (val & masklow) | tmp << offsetlow;
+				}
+				value = value >> (8 - offsetlow);
+			} else {
+				if (i == 1 && offsethigh) {
+					tmp = (val & maskhigh) | tmp;
+				}
+				value = value >> 8;
+			}
+
+			AML_PRINTF("->[%d:0x%02x@0x%x]\n",
+				    regtype, tmp, addr);
+			val = tmp;
+			OsdOut8(addr, val);
+			break;
+		}
+	}
+
+	return (state);
+}
+
 u_int32_t
 aml_region_read(int regtype, u_int32_t flags, u_int32_t addr,
     u_int32_t bitoffset, u_int32_t bitlen)
 {
-	return (0);
+	int	value;
+	int	state;
+
+	value = 0;
+	switch (regtype) {
+	case 1:
+		state = aml_region_io_systemio(ACPI_REGION_INPUT, regtype,
+		    flags, &value, addr, bitoffset, bitlen);
+		AML_SYSASSERT(state != -1);
+		break;
+	default:
+		printf("aml_region_read: not supported yet\n");
+	}
+
+        return (value);
 }
 
 int
@@ -52,7 +285,20 @@
 aml_region_write(int regtype, u_int32_t flags, u_int32_t value,
     u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
 {
-	return (0);
+	int	state;
+
+	state = 0;
+	switch (regtype) {
+	case 1:
+		state = aml_region_io_systemio(ACPI_REGION_OUTPUT, regtype,
+		    flags, &value, addr, bitoffset, bitlen);
+		AML_SYSASSERT(state != -1);
+		break;
+	default:
+		printf("aml_region_write: not supported yet\n");
+	}
+
+        return (state);
 }
 
 int
