From owner-acpi-jp@jp.freebsd.org  Fri Jul 21 14:45:52 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id OAA57084;
	Fri, 21 Jul 2000 14:45:52 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from kbtfw.kubota.co.jp (firewall-user@kbtfw.kubota.co.jp [133.253.102.202])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id OAA57079
	for <acpi-jp@jp.freebsd.org>; Fri, 21 Jul 2000 14:45:51 +0900 (JST)
	(envelope-from haro@tk.kubota.co.jp)
Received: by kbtfw.kubota.co.jp; id OAA09056; Fri, 21 Jul 2000 14:45:49 +0900 (JST)
Received: from unknown(133.253.122.1) by kbtfw.kubota.co.jp via smap (V4.2)
	id xma008755; Fri, 21 Jul 00 14:45:04 +0900
Received: from jkpc15.tk.kubota.co.jp ([192.168.7.250])
	by kbtmx.eto.kubota.co.jp (8.9.3+3.2W/3.7W) with ESMTP id OAA02275
	for <acpi-jp@jp.freebsd.org>; Fri, 21 Jul 2000 14:45:01 +0900 (JST)
Received: from localhost (localhost.ttr.kubota.co.jp [127.0.0.1])
	by jkpc15.tk.kubota.co.jp (8.9.3/3.7W-02/21/99) with ESMTP id OAA00603
	for <acpi-jp@jp.freebsd.org>; Fri, 21 Jul 2000 14:42:44 +0900 (JST)
To: acpi-jp@jp.freebsd.org
X-Mailer: Mew version 1.94.1 on Emacs 20.6 / Mule 4.0 (HANANOEN)
Mime-Version: 1.0
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Fri_Jul_21_14:41:15_2000_809)--"
Content-Transfer-Encoding: 7bit
Message-Id: <20000721144244Q.haro@tk.kubota.co.jp>
Date: Fri, 21 Jul 2000 14:42:44 +0900
From: haro@tk.kubota.co.jp (Munehiro Matsuda)
X-Dispatcher: imput version 990905(IM130)
Lines: 483
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: acpi-jp 482
Subject: [acpi-jp 482] PCI_Config space support for aml_region_*()
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: haro@tk.kubota.co.jp

----Next_Part(Fri_Jul_21_14:41:15_2000_809)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

$B>>ED!w%/%\%?$G$9!#(B
$B$3$s$A$O!#(B

ACPI$B$N<B83Cf$K(B 'aml_region_io_system: not supported yet (2)'$B$H(B
$BI=<($5$l$k$N$,HQ$o$7$$$N$G!"(Bquick hack$B$G%5%]!<%H$7$F$_$^$7$?!#(B

$B7k9=6/0z$JJ}K!$r;H$C$F$^$9$N$G!"E,Ev$K$$$8$/$C$F2<$5$$!#(B

$B$J$*!"(BPCI_Config space$B%5%]!<%H$KEv$?$C$F!"0J2<$N=$@5Ey$r9T$J$C$F$$$^$9!#(B

1. aml_region_*()$B$N0z?t$rJQ99(B
  $B0J2<$N%k!<%A%s$NBh(B1$B0z?t$K!V(Bstruct aml_environ *env$B!W$rDI2C!#(B
  
	aml_region_read()
	aml_region_write()
	aml_region_read_into_buffer()
	aml_region_write_from_buffer()
	aml_region_bcopy()

2. aml_search_*()$B4XO"$rDI2C(B
  $B0J2<$N%k!<%A%s$rDI2C$7$^$7$?!#(B

	aml_search_name_partial()  :$BItJ,L>$G%5!<%A!#Nc(B:'PCI0'$B$r(B'PCI'$B$G%5!<%A!#(B
	aml_search_parent()	   :$B?F$X$N0lJ}8~%5!<%A!#(B
	aml_search_parent_partial():$B?F$X$NItJ,L>$G$N0lJ}8~%5!<%A!#(B

  $B$3$l$i$N%k!<%A%s$O!"8=:_$N(BPCI$B%P%9HV9f$N<hF@$K!"(B'PCI'$B$@$1$G(B'PCI0'$B$r(B
  $B8!:w2DG=$H$9$k$?$aDI2C$7$^$7$?!#(B
  $B$J$*:#2s$N(Bpatch$B$G$O!"(Baml_search_parent_partial()$B$7$+;H$C$F$^$;$s!#(B

3. PCI$B%P%9HV9f$N<hF@$K$D$$$F(B
  PCI$B%P%9HV9f$N<hF@$O!">e5-$N(Baml_search_parent_partial()$B$r;H$C$F$$$^$9!#(B
  $B0l1~;d$N(BNotePC$B!J(BPCI$B%P%9#1K\$N$_!K$G$O!"$=$l$J$j$KF0$$$F$$$^$9!#(B
  $B$7$+$7$J$,$i!"(BPCI$B%P%9$rJ#?t;}$D%7%9%F%`$G$N%F%9%H$O0l@Z=PMh$F$$$^$;$s!#(B
  $B$=$N$h$&$J%7%9%F%`$r;}$DJ}$N%F%9%H$r$*4j$$$7$^$9!#(B

4. pci_cfg*()$B$N8F=P$K$D$$$F(B  
  $B0l1~(BAlpha$B7O$G$bBg>fIW$JMM$K$7$?$D$b$j$G$9!#<1<T$NJ}!"%A%'%C%/$*4j$$$7$^$9!#(B

$B$G$O!#(B
=--------------------------------------------------------------------------
           _ _           $B3t<02q<R%/%\%?(B $BEl5~K\<R(B $B5;=Q3+H/K\It(B
 -|- /_\  |_|_|            $B>>ED(B  $B=!9@(B
 /|\ |_|  |_|_|          E-mail: haro@kubota.co.jp
                         Tel: 03-3245-3318  Fax: 03-3245-3315

----Next_Part(Fri_Jul_21_14:41:15_2000_809)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="pci_config.patch"

diff -u acpi/aml/aml_evalobj.c.org acpi/aml/aml_evalobj.c
--- acpi/aml/aml_evalobj.c.org	2000/07/14 09:49:43
+++ acpi/aml/aml_evalobj.c	2000/07/20 23:43:46
@@ -103,9 +103,9 @@
 			AML_PRINTF("[read(From%d, 0x%x)]",
 			    or->space, or->offset + field->bitoffset / 8);
 			env->tempobject.type = aml_t_num;
-			env->tempobject.num.number = aml_region_read(or->space,
-			    field->flags, or->offset, field->bitoffset,
-			    field->bitlen);
+			env->tempobject.num.number = aml_region_read(env,
+			    or->space, field->flags, or->offset,
+			    field->bitoffset, field->bitlen);
 		}
 	} else if (field->f.ftype == f_t_index) {
 		wname = aml_search_name(env, field->f.ifld.indexname);
diff -u acpi/aml/aml_name.c.org acpi/aml/aml_name.c
--- acpi/aml/aml_name.c.org	2000/07/14 09:49:43
+++ acpi/aml/aml_name.c	2000/07/21 05:00:41
@@ -79,6 +79,47 @@
 	return (result);
 }
 
+static struct aml_name *
+aml_find_name_partial(struct aml_name *parent, char *name)
+{
+	struct	aml_name *result;
+	int len = strlen(name);
+
+	if (len > 4)
+		len = 4;
+	if (!parent)
+		parent = &rootname;
+	for (result = parent->child; result; result = result->brother)
+		if (!strncmp(result->name, name, len))
+			break;
+	return (result);
+}
+
+static struct aml_name *
+aml_find_parent(struct aml_name *parent, char *name)
+{
+
+	if (!parent)
+		parent = &rootname;
+	if (!strncmp(parent->name, name, 4))
+		return(parent);
+	return (NULL);
+}
+
+static struct aml_name *
+aml_find_parent_partial(struct aml_name *parent, char *name)
+{
+	int len = strlen(name);
+
+	if (len > 4)
+		len = 4;
+	if (!parent)
+		parent = &rootname;
+	if (!strncmp(parent->name, name, len))
+		return(parent);
+	return (NULL);
+}
+
 struct aml_name *
 aml_find_from_namespace(struct aml_name *parent, char *name)
 {
@@ -209,8 +250,11 @@
 	}
 }
 
-#define AML_SEARCH_NAME 0
-#define AML_CREATE_NAME 1
+#define AML_SEARCH_NAME		0
+#define AML_CREATE_NAME		1
+#define AML_SEARCH_NAME_PART	2
+#define AML_SEARCH_PARENT	3
+#define AML_SEARCH_PARENT_PART	4
 static struct aml_name	*aml_nameman(struct aml_environ *, u_int8_t *, int);
 
 struct aml_name *
@@ -227,6 +271,27 @@
 	return (aml_nameman(env, dp, AML_CREATE_NAME));
 }
 
+struct aml_name *
+aml_search_name_partial(struct aml_environ *env, u_int8_t *dp)
+{
+
+	return (aml_nameman(env, dp, AML_SEARCH_NAME_PART));
+}
+
+struct aml_name *
+aml_search_parent(struct aml_environ *env, u_int8_t *dp)
+{
+
+	return (aml_nameman(env, dp, AML_SEARCH_PARENT));
+}
+
+struct aml_name *
+aml_search_parent_partial(struct aml_environ *env, u_int8_t *dp)
+{
+
+	return (aml_nameman(env, dp, AML_SEARCH_PARENT_PART));
+}
+
 static struct aml_name *
 aml_nameman(struct aml_environ *env, u_int8_t *dp, int flag)
 {
@@ -243,7 +308,23 @@
 	}								\
 } while(0)
 
-	searchfunc = (flag == AML_CREATE_NAME) ? aml_new_name : aml_find_name;
+	switch (flag) {
+	case AML_CREATE_NAME:
+		searchfunc = aml_new_name;
+		break;
+	case AML_SEARCH_NAME_PART:
+		searchfunc = aml_find_name_partial;
+		break;
+	case AML_SEARCH_PARENT:
+		searchfunc = aml_find_parent;
+		break;
+	case AML_SEARCH_PARENT_PART:
+		searchfunc = aml_find_parent_partial;
+		break;
+	default:
+		searchfunc = aml_find_name;
+		break;
+	}
 	newname = env->curname;
 	if (dp[0] == '\\') {
 		newname = &rootname;
@@ -274,7 +355,7 @@
 	} else {
 		curname = newname;
 		for (;;) {
-			newname = aml_find_name(curname, dp);
+			newname = (*searchfunc) (curname, dp);
 			if (newname != NULL)
 				break;
 			if (curname == &rootname)
diff -u acpi/aml/aml_name.h.org acpi/aml/aml_name.h
--- acpi/aml/aml_name.h.org	2000/07/14 09:49:43
+++ acpi/aml/aml_name.h	2000/07/21 04:57:52
@@ -68,6 +68,9 @@
 struct aml_name		*aml_find_from_namespace(struct aml_name *, char *);
 struct aml_name		*aml_search_name(struct aml_environ *, u_int8_t *);
 struct aml_name		*aml_create_name(struct aml_environ *, u_int8_t *);
+struct aml_name		*aml_search_name_partial(struct aml_environ *, u_int8_t *);
+struct aml_name		*aml_search_parent(struct aml_environ *, u_int8_t *);
+struct aml_name		*aml_search_parent_partial(struct aml_environ *, u_int8_t *);
 
 struct aml_local_stack	*aml_local_stack_create(void);
 void			 aml_local_stack_push(struct aml_local_stack *);
diff -u acpi/aml/aml_region.c.org acpi/aml/aml_region.c
--- acpi/aml/aml_region.c.org	2000/07/14 09:49:43
+++ acpi/aml/aml_region.c	2000/07/21 05:24:37
@@ -33,20 +33,24 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/acpi.h>
+#include <pci/pcivar.h>
 
 #include <dev/acpi/aml/aml_common.h>
 #include <dev/acpi/aml/aml_region.h>
+#include <dev/acpi/aml/aml_name.h>
 
 #define AML_REGION_INPUT	0
 #define AML_REGION_OUTPUT	1
 
 static int
-aml_region_io_system(int io, int regtype, u_int32_t flags, u_int32_t *valuep,
-    u_int32_t baseaddr, u_int32_t bitoffset, u_int32_t bitlen)
+aml_region_io_system(struct aml_environ *env, 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;
 	vm_offset_t	addr, vaddr, byteoffset, bytelen;
+	pcicfgregs	pcicfg;
 	int		value, readval;
 	int		state, i;
 	int		debug;
@@ -86,6 +90,46 @@
 	if (regtype == 0) {
 		OsdMapMemory((void *)addr, bytelen, (void **)&vaddr);
 	}
+	if (regtype == 2) {
+		/* Access to PCI Config space */
+		struct aml_name *pci_info;
+
+		/*
+		 * XXX Hack for Alpha(tsunami) systems.
+		 * pcicfg.hose is set to -1 in the hope that,
+		 * tsunami_cfgreadX() will set it up right.
+		 * Other Alpha systems (and i386's) don't seem to use hose.
+		 */
+		pcicfg.hose = -1;
+
+		/* Obtain PCI bus number from Device(PCIx) statement */
+		pci_info = aml_search_parent_partial(env, "PCI");
+		if (!pci_info) {
+			printf("Cannot locate: PCIx\n");
+			state = -1;
+			goto io_done;
+		}
+
+		pcicfg.bus = pci_info->name[3] - '0'; /* XXX */
+		if (pcicfg.bus > 9) {
+			printf("Only 10 PCI buses are supported\n");
+			state = -1;
+			goto io_done;
+		}
+
+		/* Obtain device & function number */
+		pci_info = aml_search_name(env, "_ADR");
+		if (!pci_info || pci_info->property->type != aml_t_num) {
+			printf("Cannot locate: _ADR\n");
+			state = -1;
+			goto io_done;
+		}
+		pcicfg.slot = (pci_info->property->num.number >> 16) & 0xffff;
+		pcicfg.func = pci_info->property->num.number & 0xffff;
+
+		AML_PRINTF("[pci%d.%d.%d]",
+			   pcicfg.bus, pcicfg.slot, pcicfg.func);
+	}
 
 	/* simple I/O ? */
 	if (offsetlow == 0 && offsethigh == 0 &&
@@ -124,6 +168,9 @@
 					break;
 				}
 				break;
+			case 2:
+				value = pci_cfgread(&pcicfg, addr, bitlen/8);
+				break;
 			default:
 				printf("aml_region_io_system: not supported yet (%d)\n",
 				    regtype);
@@ -165,6 +212,9 @@
 					break;
 				}
 				break;
+			case 2:
+				pci_cfgwrite(&pcicfg, addr, value, bitlen/8);
+				break;
 			default:
 				printf("aml_region_io_system: not supported yet (%d)\n",
 				    regtype);
@@ -184,6 +234,9 @@
 		case 1:
 			val = OsdIn8(addr + i);
 			break;
+		case 2:
+			val = pci_cfgread(&pcicfg, addr + i, 1);
+			break;
 		default:
 			printf("aml_region_io_system: not supported yet (%d)\n",
 			    regtype);
@@ -252,6 +305,9 @@
 			case 1:
 				OsdOut8(addr + i, val);
 				break;
+			case 2:
+				pci_cfgwrite(&pcicfg, addr + i, val, 1);
+				break;
 			default:
 				printf("aml_region_io_system: not supported yet (%d)\n",
 				    regtype);
@@ -273,13 +329,13 @@
 }
 
 u_int32_t
-aml_region_read(int regtype, u_int32_t flags, u_int32_t addr,
-    u_int32_t bitoffset, u_int32_t bitlen)
+aml_region_read(struct aml_environ *env, int regtype, u_int32_t flags,
+    u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
 {
 	int	value;
 	int	state;
 
-	state = aml_region_io_system(AML_REGION_INPUT, regtype,
+	state = aml_region_io_system(env, AML_REGION_INPUT, regtype,
 	    flags, &value, addr, bitoffset, bitlen);
 	AML_SYSASSERT(state != -1);
 
@@ -287,19 +343,20 @@
 }
 
 int
-aml_region_read_into_buffer(int regtype, u_int32_t flags, u_int32_t addr,
-    u_int32_t bitoffset, u_int32_t bitlen, u_int8_t *buffer)
+aml_region_read_into_buffer(struct aml_environ *env, int regtype,
+    u_int32_t flags, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen,
+    u_int8_t *buffer)
 {
 	return (0);
 }
 
 int
-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)
+aml_region_write(struct aml_environ *env, int regtype, u_int32_t flags,
+    u_int32_t value, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
 {
 	int	state;
 
-	state = aml_region_io_system(AML_REGION_OUTPUT, regtype,
+	state = aml_region_io_system(env, AML_REGION_OUTPUT, regtype,
 	    flags, &value, addr, bitoffset, bitlen);
 	AML_SYSASSERT(state != -1);
 
@@ -307,17 +364,17 @@
 }
 
 int
-aml_region_write_from_buffer(int regtype, u_int32_t flags, u_int8_t *buffer,
-    u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen)
+aml_region_write_from_buffer(struct aml_environ *env, int regtype,
+    u_int32_t flags, u_int8_t *buffer, u_int32_t addr, u_int32_t bitoffset,
+    u_int32_t bitlen)
 {
 	return (0);
 }
 
 int
-aml_region_bcopy(int regtype, u_int32_t flags, u_int32_t addr,
-    u_int32_t bitoffset, u_int32_t bitlen,
-    u_int32_t dflags, u_int32_t daddr,
-    u_int32_t dbitoffset, u_int32_t dbitlen)
+aml_region_bcopy(struct aml_environ *env, int regtype,
+    u_int32_t flags, u_int32_t addr, u_int32_t bitoffset, u_int32_t bitlen,
+    u_int32_t dflags, u_int32_t daddr, u_int32_t dbitoffset, u_int32_t dbitlen)
 {
 	return (0);
 }
diff -u acpi/aml/aml_region.h.org acpi/aml/aml_region.h
--- acpi/aml/aml_region.h.org	2000/07/14 09:49:43
+++ acpi/aml/aml_region.h	2000/07/20 23:55:52
@@ -32,18 +32,21 @@
 /*
  * Region I/O subroutine
  */
+struct aml_environ;
 
-u_int32_t	 aml_region_read(int, u_int32_t, u_int32_t,
-				 u_int32_t, u_int32_t);
-int		 aml_region_write(int, u_int32_t, u_int32_t,
-				  u_int32_t, u_int32_t, u_int32_t);
-int		 aml_region_read_into_buffer(int, u_int32_t, u_int32_t,
-					     u_int32_t, u_int32_t, u_int8_t *);
-int		 aml_region_write_from_buffer(int, u_int32_t, u_int8_t *,
-					      u_int32_t, u_int32_t, u_int32_t);
-int		 aml_region_bcopy(int, u_int32_t, u_int32_t,
-				  u_int32_t, u_int32_t, u_int32_t,
-				  u_int32_t, u_int32_t, u_int32_t);
+u_int32_t	 aml_region_read(struct aml_environ *, int, u_int32_t,
+				 u_int32_t, u_int32_t, u_int32_t);
+int		 aml_region_write(struct aml_environ *, int, u_int32_t,
+				  u_int32_t, u_int32_t, u_int32_t, u_int32_t);
+int		 aml_region_read_into_buffer(struct aml_environ *, int,
+					     u_int32_t, u_int32_t, u_int32_t,
+					     u_int32_t, u_int8_t *);
+int		 aml_region_write_from_buffer(struct aml_environ *, int,
+					      u_int32_t, u_int8_t *, u_int32_t,
+					      u_int32_t, u_int32_t);
+int		 aml_region_bcopy(struct aml_environ *, int,
+				  u_int32_t, u_int32_t, u_int32_t, u_int32_t,
+				  u_int32_t, u_int32_t, u_int32_t, u_int32_t);
 
 #ifndef _KERNEL
 void	aml_simulation_regdump(const char *);
diff -u acpi/aml/aml_store.c.org acpi/aml/aml_store.c
--- acpi/aml/aml_store.c.org	2000/07/14 09:49:44
+++ acpi/aml/aml_store.c	2000/07/20 23:42:23
@@ -77,7 +77,7 @@
 			AML_PRINTF("[write(From%d, 0x%x, 0x%x)]",
 			    or->space, obj->num.number,
 			    or->offset + field->bitoffset / 8);
-			aml_region_write(or->space, field->flags,
+			aml_region_write(env, or->space, field->flags,
 			    obj->num.number, or->offset,
 			    field->bitoffset, field->bitlen);
 			break;
@@ -89,8 +89,8 @@
 				buffer = obj->bfld.origin;
 				buffer += obj->bfld.bitoffset / 8;
 			}
-			aml_region_write_from_buffer(or->space, field->flags,
-			    buffer, or->offset, field->bitoffset,
+			aml_region_write_from_buffer(env, or->space,
+			    field->flags, buffer, or->offset, field->bitoffset,
 			    field->bitlen);
 			break;
 		case aml_t_regfield:
@@ -99,7 +99,7 @@
 					   "Different type of space\n");
 				break;
 			}
-			aml_region_bcopy(obj->regfield.space,
+			aml_region_bcopy(env, obj->regfield.space,
 			    obj->regfield.flags, obj->regfield.offset,
 			    obj->regfield.bitoffset, obj->regfield.bitlen,
 			    field->flags, or->offset, field->bitoffset,
@@ -161,7 +161,7 @@
 		if (bitlen > obj->regfield.bitlen) {
 			bitlen = obj->regfield.bitlen;
 		}
-		aml_region_read_into_buffer(obj->regfield.space,
+		aml_region_read_into_buffer(env, obj->regfield.space,
 		    obj->regfield.flags, obj->regfield.offset,
 		    obj->regfield.bitoffset, bitlen,
 		    buf->buffer.data + offset);
@@ -219,7 +219,7 @@
 			bcopy(srcbuf, buffer, bitlen / 8);
 			break;
 		case aml_t_regfield:
-			aml_region_read_into_buffer(src->regfield.space,
+			aml_region_read_into_buffer(env, src->regfield.space,
 			    src->regfield.flags, src->regfield.offset,
 			    src->regfield.bitoffset, src->regfield.bitlen,
 			    buffer);

----Next_Part(Fri_Jul_21_14:41:15_2000_809)----
