From owner-FreeBSD-tech-jp@jp.freebsd.org  Wed Sep 22 02:33:36 1999
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id CAA52107;
	Wed, 22 Sep 1999 02:33:36 +0900 (JST)
	(envelope-from owner-FreeBSD-tech-jp@jp.FreeBSD.org)
Received: from light.imasy.or.jp (root@light.imasy.or.jp [202.227.24.4])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id CAA52102
	for <FreeBSD-tech-jp@jp.freebsd.org>; Wed, 22 Sep 1999 02:33:35 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (daemon@tasogare.imasy.or.jp [202.227.24.5])
	by light.imasy.or.jp (8.9.3+3.2W/3.7W-light) with ESMTP id CAA03590
	for <FreeBSD-tech-jp@jp.freebsd.org>; Wed, 22 Sep 1999 02:33:32 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (isdnb52.imasy.or.jp [202.227.24.180])
	by tasogare.imasy.or.jp (8.9.3+3.2W/3.7W-tasogare/smtpfeed 1.01) with ESMTP id CAA14075;
	Wed, 22 Sep 1999 02:33:29 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Message-Id: <199909211733.CAA14075@tasogare.imasy.or.jp>
To: FreeBSD-tech-jp@jp.freebsd.org,
        takawata@shidahara1.planet.sci.kobe-u.ac.jp
In-Reply-To: Your message of "Tue, 21 Sep 1999 02:49:21 +0900"
	<199909201749.CAA26589@libr.scitec.kobe-u.ac.jp>
References: <199909201749.CAA26589@libr.scitec.kobe-u.ac.jp>
X-Mailer: Mew version 1.93 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Date: Wed, 22 Sep 1999 02:36:23 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 980905(IM100)
Lines: 338
Reply-To: FreeBSD-tech-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+990727
X-Sequence: FreeBSD-tech-jp 2538
Subject: [FreeBSD-tech-jp 2538] Re: FreeBSD ACPI support? 
Errors-To: owner-FreeBSD-tech-jp@jp.freebsd.org
Sender: owner-FreeBSD-tech-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

$B$$$o$5$-$G$9(B

$BEOJU$5$s$N$d$D$r%Y!<%9$K(B pmap $B4X78$r$A$g$C$H@0M}$7$F(B
$B=q$-D>$7$F$_$^$7$?!#(B
ACPI Reclaim Memory $B$r%a%b%j8!=P;~$K3P$($F$*$$$F!"(B
attach $B$N:]$K$=$N(B address range $BA4BN$r0l5$$K(B map $B$7!"(B
physical -> virtual address $B$NJQ494X?t$r7PM3$7$F(B
address range $BFb$NG$0U$N>l=j$K%"%/%;%9$G$-$k$h$&$K$7$F$$$^$9!#(B
$B$G!"MW$i$J$/$J$C$?;~E@$G(B address range $BA4BN$r(B unmap $B$7$^$9!#(B

$B$^$@%(%i!<%A%'%C%/$J$I$O$[$H$s$IF~$C$F$$$^$;$s$,!"(B
$B$3$l$G$@$$$V8e$N:n6H$,3Z$K$J$k$N$G$O$J$$$+$H4|BT$7$F$$$^$9(B :-)
$B0l1~$3$l$G(B OK $B$]$$$s$G$9$,!"$I$J$?$+(B pmap $B$N0N$$?M!"(B
$B8+$F$/$l$k$H$&$l$7$$$G$9!#(B

CURRENT $B$N(B sys/i386/ $B$G0J2<$N%Q%C%A$r$"$F$F;H$$$^$9!#(B

Index: conf/LINT
===================================================================
RCS file: /home/ncvs/src/sys/i386/conf/LINT,v
retrieving revision 1.645
diff -u -r1.645 LINT
--- LINT	1999/09/13 09:45:06	1.645
+++ LINT	1999/09/20 18:23:23
@@ -986,6 +986,8 @@
 # are not used until later in the bootstrap when npx0 is attached).
 # Flag 0x08 automatically disables the i586 optimized routines.
 #
+# ACPI Experimental Driver 
+controller acpi0 
 
 #
 # Optional ISA and EISA devices:
Index: conf/files.i386
===================================================================
RCS file: /home/ncvs/src/sys/i386/conf/files.i386,v
retrieving revision 1.269
diff -u -r1.269 files.i386
--- files.i386	1999/09/20 07:52:32	1.269
+++ files.i386	1999/09/20 18:23:43
@@ -159,6 +159,7 @@
 i386/i386/userconfig.c		optional	userconfig
 i386/i386/vm86.c		standard
 i386/i386/vm_machdep.c		standard
+i386/i386/acpi.c		optional	acpi
 i386/ibcs2/ibcs2_errno.c	optional	ibcs2
 i386/ibcs2/ibcs2_fcntl.c	optional	ibcs2
 i386/ibcs2/ibcs2_ioctl.c	optional	ibcs2
Index: i386/bios.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/bios.c,v
retrieving revision 1.26
diff -u -r1.26 bios.c
--- bios.c	1999/09/12 06:58:33	1.26
+++ bios.c	1999/09/20 18:37:05
@@ -30,7 +30,7 @@
 /*
  * Code for dealing with the BIOS in x86 PC systems.
  */
-
+#include "acpi.h"
 #include <sys/param.h>
 #include <sys/proc.h>
 #include <sys/systm.h>
@@ -44,6 +44,9 @@
 #include <machine/tss.h>
 #include <machine/vmparam.h>
 #include <machine/pc/bios.h>
+#if NACPI>0
+#include <machine/pc/acpi.h>
+#endif
 #include <isa/pnpreg.h>
 
 #define BIOS_START	0xe0000
@@ -135,10 +138,29 @@
 	}
     }
 
+#if NACPI>0
+    /*
+     * ACPI BIOS
+     * acpi_rsdp is GLOBAL and holds RSD PTR signature
+     */
+    if ((sigaddr = bios_sigsearch(0, "RSD PTR ", 8, 16, 0)) != 0) {
+	/* get a virtual pointer to the structure */
+	acpi_rsdp = (struct ACPIrsdp *)(uintptr_t)BIOS_PADDRTOVADDR(sigaddr);
+	for (cv = (u_int8_t *)acpi_rsdp, ck = 0, i = 0; i < sizeof(struct ACPIrsdp); i++) {
+	    ck += cv[i];
+	}
+
+	/* If checksum is NG, disable it */
+	if (ck != 0) {
+	  printf("ACPI: Bad ACPI BIOS data checksum\n");
+	  acpi_rsdp=NULL;/* 0xa0000<=RSD_PTR<0x100000*/
+       }
+   }
+#endif
+
     if (bootverbose) {
 	    /* look for other know signatures */
 	    printf("Other BIOS signatures found:\n");
-	    printf("ACPI: %08x\n", bios_sigsearch(0, "RSD PTR ", 8, 16, 0));
     }
 }
 
Index: i386/machdep.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/machdep.c,v
retrieving revision 1.361
diff -u -r1.361 machdep.c
--- machdep.c	1999/09/07 20:02:24	1.361
+++ machdep.c	1999/09/21 16:44:09
@@ -38,6 +38,7 @@
  * $FreeBSD: src/sys/i386/i386/machdep.c,v 1.361 1999/09/07 20:02:24 luoqi Exp $
  */
 
+#include "acpi.h"
 #include "apm.h"
 #include "ether.h"
 #include "npx.h"
@@ -128,6 +129,10 @@
 #include <machine/random.h>
 #include <sys/ptrace.h>
 
+#if NACPI > 0
+#include <machine/pc/acpi.h>
+#endif
+
 extern void init386 __P((int first));
 extern void dblfault_handler __P((void));
 
@@ -1272,6 +1277,13 @@
 				(u_int32_t)smap->base,
 				*(u_int32_t *)((char *)&smap->length + 4),
 				(u_int32_t)smap->length);
+
+		/* Save ACPI Reclaim Memory Info. */
+		if (smap->type == 0x03) {
+			acpi_addr.pa_base = (vm_offset_t)smap->base;
+			acpi_addr.size = (vm_size_t)smap->length;
+			goto next_run;
+		}
 
 		if (smap->type != 0x01)
 			goto next_run;
--- /dev/null	Wed Sep 22 02:07:23 1999
+++ i386/acpi.c	Wed Sep 22 02:05:14 1999
@@ -0,0 +1,156 @@
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <vm/vm.h>
+#include <vm/vm_prot.h>
+#include <vm/pmap.h>
+#include <machine/md_var.h>
+#include <machine/segments.h>
+#include <machine/stdarg.h>
+#include <machine/tss.h>
+#include <machine/vmparam.h>
+#include <machine/pc/bios.h>
+#include <machine/pc/acpi.h>
+#include <isa/pnpreg.h>
+#include <machine/bus.h>
+#include <sys/resource.h>
+#include <sys/bus.h>
+
+struct ACPIaddr  acpi_addr;
+struct ACPIrsdp *acpi_rsdp;
+
+static void acpi_pmap_init __P((void));
+static void acpi_pmap_release __P((void));
+static vm_offset_t acpi_pmap_ptv __P((vm_offset_t pa));
+static vm_offset_t acpi_pmap_vtp __P((vm_offset_t va));
+
+static int acpi_sdt_checksum __P((struct ACPIsdt * sdt));
+
+static void
+acpi_pmap_init()
+{
+	acpi_addr.va_base = (vm_offset_t) pmap_mapdev(acpi_addr.pa_base,
+						acpi_addr.size);
+}
+
+static void
+acpi_pmap_release()
+{
+	pmap_unmapdev(acpi_addr.va_base, acpi_addr.size);
+}
+
+static vm_offset_t
+acpi_pmap_ptv(vm_offset_t pa)
+{
+	if (pa < acpi_addr.pa_base)
+		return 0;
+
+	return acpi_addr.va_base + pa - acpi_addr.pa_base;
+}
+
+static vm_offset_t
+acpi_pmap_vtp(vm_offset_t va)
+{
+	if (va < acpi_addr.va_base)
+		return 0;
+
+	return acpi_addr.pa_base + va - acpi_addr.va_base;
+}
+
+static int 
+acpi_sdt_checksum(struct ACPIsdt * sdt)
+{
+	int             i;
+	u_char          cksm = 0, *ckbf = (u_char *) sdt;
+
+	for (i = 0; i < sdt->len; i++)
+		cksm += ckbf[i];
+
+	return (cksm == 0) ? 0 : EINVAL;
+}
+
+static void
+acpi_identify(driver_t * driver, device_t parent)
+{
+	device_t        child;
+
+	child = BUS_ADD_CHILD(parent, 0, "acpi", 0);
+
+	if (child == NULL)
+		panic("acpi_identify");
+}
+
+static int 
+acpi_probe(device_t dev)
+{
+	char            oemstring[7];
+
+	printf("ACPI: Found ACPI BIOS data at %p (<%6s>, RSDT@%x)\n",
+	       acpi_rsdp, acpi_rsdp->oem, acpi_rsdp->addr);
+
+	if (acpi_rsdp == NULL) {
+		return ENXIO;
+	}
+
+	strncpy(oemstring, acpi_rsdp->oem, 6);
+	oemstring[6] = '\0';
+	device_set_desc(dev, acpi_rsdp->oem);
+	return 0;
+}
+
+static int 
+acpi_attach(device_t dev)
+{
+	struct ACPIsdt *rsdt;
+	int             entries;
+	int             i;
+	u_int32_t      *ptrs;
+
+	acpi_pmap_init();
+
+	rsdt = (struct ACPIsdt *) acpi_pmap_ptv(acpi_rsdp->addr);
+	if (rsdt == 0) {
+		device_printf(dev, "cannot map physical memory\n");
+		return ENXIO;
+	}
+
+	if (acpi_sdt_checksum(rsdt) != 0) {
+		device_printf(dev, "RSDT is broken\n");
+		acpi_pmap_release();
+		return ENXIO;
+	}
+
+	if (strncmp(rsdt->signature, "RSDT", 4) == 0) {
+		entries = (rsdt->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t);
+		device_printf(dev, "RSDT have %d entries\n", entries);
+		ptrs = (u_int32_t *) & rsdt->body;
+
+		for (i = 0; i < entries; i++) {
+			device_printf(dev, "RSDT entry%d %x\n", i, ptrs[i]);
+		}
+	}
+
+	acpi_pmap_release();
+	return 0;
+}
+
+static device_method_t acpi_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_identify,	acpi_identify),
+	DEVMETHOD(device_probe,		acpi_probe),
+	DEVMETHOD(device_attach,	acpi_attach),
+
+	{0, 0}
+};
+
+static driver_t acpi_driver = {
+	"acpi",
+	acpi_methods,
+	1,			/* no softc (XXX) */
+};
+
+static devclass_t acpi_devclass;
+
+DRIVER_MODULE(acpi, nexus, acpi_driver, acpi_devclass, 0, 0);
--- /dev/null	Wed Sep 22 02:07:23 1999
+++ include/pc/acpi.h	Wed Sep 22 01:37:30 1999
@@ -0,0 +1,31 @@
+struct ACPIaddr {
+  vm_offset_t	pa_base;
+  vm_offset_t	va_base;
+  vm_size_t	size;
+};
+
+struct ACPIrsdp {
+  u_char	signature[8];
+  u_char	sum;
+  u_char	oem[6];
+  u_char	res;
+  u_int32_t	addr;
+}__attribute__((packed));
+
+struct ACPIsdt {
+  u_char	signature[4];
+  u_int32_t	len;
+  u_char	rev;
+  u_char	check;
+  u_char	oemid[6];
+  u_char	oemtblid[8];
+  u_char	oemrev[4];
+  u_char	creator[4];
+  u_char	crerev[4];
+#define SIZEOF_SDT_HDR 36 /*struct size except body*/
+  u_char	body[1]; /*This member should be casted*/
+}__attribute__((packed));
+
+extern struct ACPIaddr  acpi_addr;	/* ACPI Reclaim Memory Address Range */
+extern struct ACPIrsdp *acpi_rsdp;	/* ACPI Root System Description Table */
+
