From owner-FreeBSD-tech-jp@jp.freebsd.org  Sun Aug 24 13:11:20 1997
Received: by jaz.jp.freebsd.org (8.8.7+2.7Wbeta7/8.7.3) id NAA00402
	Sun, 24 Aug 1997 13:11:20 +0900 (JST)
Received: by jaz.jp.freebsd.org (8.8.7+2.7Wbeta7/8.7.3) with ESMTP id NAA00397
	for <FreeBSD-tech-jp@jp.freebsd.org>; Sun, 24 Aug 1997 13:11:15 +0900 (JST)
Received: (from hosokawa@localhost)
	by lenlen.ntc.keio.ac.jp (8.8.5/8.8.5) id NAA11290;
	Sun, 24 Aug 1997 13:12:49 +0900 (JST)
Date: Sun, 24 Aug 1997 13:12:49 +0900 (JST)
Message-Id: <199708240412.NAA11290@lenlen.ntc.keio.ac.jp>
To: FreeBSD-tech-jp@jp.freebsd.org
Cc: bsd-nomads@ai.cs.fujitsu.co.jp
In-Reply-To: Your message of Sun, 17 Aug 1997 02:08:49 +0900 (JST).
	<199708161708.CAA06486@pharaoh0.syslabo.co.jp>
From: hosokawa@ntc.keio.ac.jp (HOSOKAWA Tatsumi)
X-Mailer: mnews [version 1.19PL2] 1996-01/26(Fri)
Reply-To: FreeBSD-tech-jp@jp.freebsd.org
Precedence: bulk
X-Distribute: distribute [version 2.1 (Alpha) patchlevel=20]
X-Sequence: FreeBSD-tech-jp 497
Subject: [FreeBSD-tech-jp 497] Re: [bsd-nomads:05216] PC-card patch for 3.0-CURRENT
Errors-To: owner-FreeBSD-tech-jp@jp.freebsd.org
Sender: owner-FreeBSD-tech-jp@jp.freebsd.org

<199708161708.CAA06486@pharaoh0.syslabo.co.jp>$B$N5-;v$K$*$$$F(B
hanada@syslabo.co.jp$B$5$s$O=q$-$^$7$?!#(B

>> 2.2.2-RELEASE $B$G$NBP1~$rBT$C$F$^$7$?$,CY$/$J$j$=$&$J$N$G(B
>> 3.0$B$r$$$l$F(BCLPD-6832$B$N%F%9%H$7$^$7$?!#(B
>> 3.0-970807-SNAP $B$G%F%9%H$7$^$7$?$,Bg>fIW$J$s$G$7$g$&$+!#!#!#(B
>> $B$H$j$"$($:!"(B2.2.2-RELESE $B$N;~$HF1$8>uBV$^$G$OF0$/$h$&$K$J$j$^$7$?!#(B
>> $B$G$b!"$d$C$Q$j#3$DL\$N%9%m%C%H$,G'<1$7$^$;$s!#(B
>> $B%+!<%I$O%b%G%`%+!<%I$O;H$($^$9!##L#A#N%+!<%I$O:##L#A#N4D6-$,(B
>> $B$J$$$N$G;n$;$^$;$s!#!#!#!#(B

$B0J2<$N%Q%C%A$r$*;n$72<$5$$!#(B

$B!tCY$/$J$C$F$9$_$^$;$s!#(B

$B$[$=$+$o(B

diff -urN sys.prev/i386/conf/PCCARD-GENERIC sys/i386/conf/PCCARD-GENERIC
--- sys.prev/i386/conf/PCCARD-GENERIC	Sun Aug 24 11:58:15 1997
+++ sys/i386/conf/PCCARD-GENERIC	Wed Aug 13 15:22:56 1997
@@ -145,6 +145,7 @@
 
 pseudo-device	loop
 pseudo-device	ether
+pseudo-device	bpfilter	4
 pseudo-device	log
 pseudo-device	sl	1
 # ijppp uses tun instead of ppp device
diff -urN sys.prev/pccard/pcic.c sys/pccard/pcic.c
--- sys.prev/pccard/pcic.c	Sun Aug 24 11:58:16 1997
+++ sys/pccard/pcic.c	Sun Aug 24 11:50:18 1997
@@ -69,11 +69,19 @@
 #include <pci/pcivar.h>
 
 static u_long pcic_pci_count;
-static u_long pcic_pci_ioaddr = 0;
 static u_int pcic_pci_id = 0;	/* XXX: it does not used for important purpose */
 static char *pcic_pci_probe(pcici_t, pcidi_t);
 static void pcic_pci_attach(pcici_t, int);
-static u_long	pcic_pci_legacy16[NPCIC] = {0};
+
+/* information about PCI PC-card bridges */
+struct pci_pcic {
+	u_int8_t	bus;
+	u_int8_t	slot;
+	u_long		legacy16;
+	u_int		pci_id;
+};
+
+static struct pci_pcic pci_pcics[NPCIC];
 
 static struct pci_device pcic_pci_device = {
 	"pcic",
@@ -88,6 +96,14 @@
 static char *
 pcic_pci_probe(pcici_t tag, pcidi_t type)
 {
+	static int initialized = 0;
+	int	i;
+
+	if (!initialized) {
+		for (i = 0; i < NPCIC; i++) 
+			pci_pcics[i].bus = pci_pcics[i].slot = 0xff; /* N/A */
+		initialized = 1;
+	}
 	switch (type) {
 	/* 32bit CardBus bridges */
 	case PCI_DEVICE_ID_PCIC_CLPD6832_CARDBUS:
@@ -154,30 +170,65 @@
 	int	i;
 	u_long	legacy16;
 	u_long	devcntl;
+	static int x_pcic_unit = 0;
+	static int pcic_unit = 0;
+	int	reinit_legacy16;
+
+	/* Assign PCIC unit number (support for multiple PCIC's on PCI bus) */
+	for (i = 0; i < x_pcic_unit; i++) {
+		if (tag->bus == pci_pcics[i].bus && 
+		    tag->slot == pci_pcics[i].slot)
+			goto matched;
+	}
+	pci_pcics[x_pcic_unit].bus = tag->bus;
+	pci_pcics[x_pcic_unit].slot = tag->slot;
+	pcic_unit = x_pcic_unit;
+	x_pcic_unit++;
+matched:
+	if (!pci_pcics[pcic_unit].pci_id)
+		pci_pcics[pcic_unit].pci_id = pcic_pci_id;
 
+	/* Init. CardBus/PC-card controllers as 16-bit PC-card controllers */
 	switch (pcic_pci_id) {
 	/* CardBus Bridges */
 	case PCI_DEVICE_ID_PCIC_TI1130_CARDBUS:
 	case PCI_DEVICE_ID_PCIC_TI1131_CARDBUS:
 		legacy16 = pci_cfgread(tag, CB_PCI_LEGACY16_IOADDR, 2)
 					 & ~PCI_MAP_IO;
-		if (!legacy16) {
-			/*
-			 * if BIOS does not set PCIC legacy 16bit I/O address,
-			 * set it to 0x3e0.
-			 * XXX - this code does *NOT* support multiple 
-			 * PCI-1130 on PCI bus.
-			 */
-			legacy16 = PCIC_INDEX_0 | PCI_MAP_IO;
-			pci_cfgwrite(tag, 
-				CB_PCI_LEGACY16_IOADDR, legacy16, 2);
-			pcic_pci_ioaddr = 
-				pci_cfgread(tag, CB_PCI_LEGACY16_IOADDR, 2)
+		/*
+		 * if BIOS does not set PCIC legacy 16bit I/O address,
+		 * or the second CardBus contorller's I/O address 
+		 * set by BIOS conflicts with it of the first one :-<, 
+		 * set it to 0x3e0 (for 1st unit) or 0x3e2 (for 2nd 
+		 * unit).
+		 * XXX - this code does not support MORE THAN TWO
+		 * PCI-1130 on the same machine.  (but most CardBus 
+		 * laptops have only one or two CardBus controllers)
+		 */
+		reinit_legacy16 = 0;
+		if (!legacy16)
+			reinit_legacy16 = 1;
+		else
+			for (i = 0; i < pcic_unit; i++)
+				if (pci_pcics[i].legacy16 == legacy16)
+					reinit_legacy16 = 1;
+		if (reinit_legacy16) {
+			switch (pcic_unit) {
+			case 0:
+				legacy16 = PCIC_INDEX_0 | PCI_MAP_IO;
+				break;
+			case 1:
+			default:	/* XXX */
+				legacy16 = PCIC_INDEX_1 | PCI_MAP_IO;
+				break;
+			}
+			pci_cfgwrite(tag, CB_PCI_LEGACY16_IOADDR, legacy16, 2);
+			legacy16 = pci_cfgread(tag, CB_PCI_LEGACY16_IOADDR, 2)
 						 & ~PCI_MAP_IO;
 			if (bootverbose)
-				printf("TI PCI-113X: Legacy PC-card "
+				printf("TI PCI-113X: unit %d, Legacy PC-card "
 					"16bit I/O address is set to 0x%x\n", 
-					pcic_pci_ioaddr);
+					pcic_unit, legacy16);
 		}
 		else {
 			/* 
@@ -187,20 +238,12 @@
 			 * bus)
 			 * pcic_pci_legacy16 is used in pcic_probe().
 			 */
-			pcic_pci_ioaddr = legacy16;
 			if (bootverbose)
-				printf("TI PCI-113X: Legacy PC-card "
+				printf("TI PCI-113X: unit %d, Legacy PC-card "
 					"16bit I/O address [0x%x]\n", 
-					pcic_pci_ioaddr);
-			for (i = 0; i < NPCIC; i++) {
-				if (!pcic_pci_legacy16[i]) {
-					pcic_pci_legacy16[i] = legacy16;
-					break;
-				}
-				if (pcic_pci_legacy16[i] == legacy16)
-					break;
-			}
+					pcic_unit, legacy16);
 		}
+		pci_pcics[pcic_unit].legacy16 = legacy16;
 		devcntl = pci_cfgread(tag, TI113X_PCI_DEVICE_CONTROL, 1);
 		if (bootverbose)
 			printf("TI PCI-113X: device control register [0x%02x]\n",
@@ -215,33 +258,48 @@
 	case PCI_DEVICE_ID_PCIC_CLPD6832_CARDBUS:
 		legacy16 = pci_cfgread(tag, CB_PCI_LEGACY16_IOADDR, 2)
 					 & ~PCI_MAP_IO;
-		/* If legacy 16bit address is not set, set it to 0x3e0 */
-		if (!legacy16) {
-			legacy16 = PCIC_IO | PCI_MAP_IO;
-			pci_cfgwrite(tag, 
-				CB_PCI_LEGACY16_IOADDR, legacy16, 2);
-			pcic_pci_ioaddr = 
-				pci_cfgread(tag, CB_PCI_LEGACY16_IOADDR, 2)
+		/*
+		 * same as TI-1130
+		 * (XXX - but I haven't tested it on CL-6832 machines)
+		 */
+		reinit_legacy16 = 0;
+		if (!legacy16)
+			reinit_legacy16 = 1;
+		else
+			for (i = 0; i < pcic_unit; i++)
+				if (pci_pcics[i].legacy16 == legacy16)
+					reinit_legacy16 = 1;
+		if (reinit_legacy16) {
+			switch (pcic_unit) {
+			case 0:
+				legacy16 = PCIC_INDEX_0 | PCI_MAP_IO;
+				break;
+			case 1:
+			default:	/* XXX */
+				legacy16 = PCIC_INDEX_1 | PCI_MAP_IO;
+				break;
+			}
+			pci_cfgwrite(tag, CB_PCI_LEGACY16_IOADDR, legacy16, 2);
+			legacy16 = pci_cfgread(tag, CB_PCI_LEGACY16_IOADDR, 2)
 						 & ~PCI_MAP_IO;
 			if (bootverbose)
-				printf("CLPD-6832: Legacy PC-card 16bit I/O "
-					"address is set to 0x%x\n", 
-					pcic_pci_ioaddr);
+				printf("CLPD-6832: unit %d, Legacy PC-card "
+					"16bit I/O address is set to 0x%x\n", 
+					pcic_unit, legacy16);
 		}
-		else {
-			pcic_pci_ioaddr = legacy16;
+		else
 			if (bootverbose)
-				printf("CLPD-6832: Legacy PC-card 16bit I/O "
-					"address [0x%x]\n", pcic_pci_ioaddr);
-		}
+				printf("CLPD-6832: unit %d, Legacy PC-card "
+					"16bit I/O address [0x%x]\n",
+					pcic_unit, legacy16);
+		pci_pcics[pcic_unit].legacy16 = legacy16;
 		break;
 
 	/* Legacy PC-card Bridges */
 	case PCI_DEVICE_ID_PCIC_CLPD6729:
 	case PCI_DEVICE_ID_PCIC_O2MICRO:
-		pcic_pci_ioaddr = 
-			pci_conf_read(tag, PCI_MAP_REG_START)
-					 & ~PCI_MAP_IO;
+		pci_pcics[pcic_unit].legacy16 = 
+			pci_conf_read(tag, PCI_MAP_REG_START) & ~PCI_MAP_IO;
 		pci_conf_write(tag, PCI_COMMAND_STATUS_REG, 0x00ff00ff);
 		break;
 	default:
@@ -751,6 +809,7 @@
 	struct pcic_slot *sp;
 	unsigned char c;
 	static int maybe_vlsi = 0;
+	int pcic_unit;
 
 	/* Determine the list of free interrupts */
 	free_irqs = build_freelist(PCIC_INT_MASK_ALLOWED);
@@ -784,10 +843,11 @@
 		sp->getb = getb1;
 		sp->putb = putb1;
 		if (slot < 4) {
+			pcic_unit = 0;
 #if NPCI > 0
-			if (pcic_pci_legacy16[0]) {
-				sp->index = pcic_pci_legacy16[0];
-				sp->data = pcic_pci_legacy16[0] + 1;
+			if (pci_pcics[0].legacy16) {
+				sp->index = pci_pcics[0].legacy16;
+				sp->data = sp->index + 1;
 			}
 			else {
 				sp->index = PCIC_INDEX_0;
@@ -799,10 +859,11 @@
 #endif
 			sp->offset = slot * PCIC_SLOT_SIZE;
 		} else {
+			pcic_unit = 1;
 #if NPCI > 0
-			if (pcic_pci_legacy16[1]) {
-				sp->index = pcic_pci_legacy16[1];
-				sp->data = pcic_pci_legacy16[1] + 1;
+			if (pci_pcics[1].legacy16) {
+				sp->index = pci_pcics[1].legacy16;
+				sp->data = sp->index + 1;
 			}
 			else {
 				sp->index = PCIC_INDEX_1;
@@ -812,8 +873,6 @@
 			sp->index = PCIC_INDEX_1;
 			sp->data = PCIC_DATA_1;
 #endif
-			sp->index = PCIC_INDEX_1;
-			sp->data = PCIC_DATA_1;
 			sp->offset = (slot - 4) * PCIC_SLOT_SIZE;
 
 			if (NPCIC >= 2) {
@@ -912,50 +971,33 @@
 			}
 		}
 #if NPCI > 0
-		/*
-		 * XXX - This code does not support multiple different 
-		 * PC-card bridges and CardBus bridges on the same PCI
-		 * bus. (e.g. a machine both with CLPD-6832 and TI 
-		 * PCI-1130, but I don't know such machines)
-		 * This code supports *single* CardBus bridge and 
-		 * multiple ISA PC-card controller on the same machine.
-		 * (e.g. Rios Chandra has TI PCI-1130 on PCI bus and 
-		 * i82365 compatible PC-card controller on ISA bus, but
-		 * I don't know other machines with such configuration)
-		 */
-		if (pcic_pci_legacy16[0]) {
-			for (i = 0; i < NPCIC; i++) {
-				if (!pcic_pci_legacy16[i])
-					break;
-				if (pcic_pci_legacy16[i] == sp->index)
-					goto pci_id_check;
+		if (pci_pcics[pcic_unit].bus != 0xffu) {
+			switch (pci_pcics[pcic_unit].pci_id) {
+			case PCI_DEVICE_ID_PCIC_CLPD6832_CARDBUS:
+				sp->controller = PCIC_PD6832;
+				cinfo->name = "Cirrus Logic PD-6832 "
+						"[i82365 compatible mode]";
+				goto skip_isa_id_check;
+			case PCI_DEVICE_ID_PCIC_TI1130_CARDBUS:
+				sp->controller = PCIC_TI1130;
+				cinfo->name = "TI PCI-1130 "
+						"[i82365 compatible mode]";
+				goto skip_isa_id_check;
+			case PCI_DEVICE_ID_PCIC_TI1131_CARDBUS:
+				sp->controller = PCIC_TI1131;
+				cinfo->name = "TI PCI-1131 "
+						"[i82365 compatible mode]";
+				goto skip_isa_id_check;
+			case PCI_DEVICE_ID_PCIC_O2MICRO:
+				sp->controller = PCIC_O2MICRO;
+				cinfo->name = "O2micro PCI/PC-Card bridge";
+				goto skip_isa_id_check;
+			case PCI_DEVICE_ID_PCIC_CLPD6729:
+				sp->controller = PCIC_PD6729;
+				cinfo->name = "Cirrus Logic PD-6729/6730";
+				goto skip_isa_id_check;
 			}
-			goto skip_pci_id_check;
-		}
-pci_id_check:
-		switch (pcic_pci_id) {
-		case PCI_DEVICE_ID_PCIC_CLPD6832_CARDBUS:
-			sp->controller = PCIC_PD6832;
-			cinfo->name = "Cirrus Logic PD-6832 [i82365 compatible mode]";
-			goto skip_isa_id_check;
-		case PCI_DEVICE_ID_PCIC_TI1130_CARDBUS:
-			sp->controller = PCIC_TI1130;
-			cinfo->name = "TI PCI-1130 [i82365 compatible mode]";
-			goto skip_isa_id_check;
-		case PCI_DEVICE_ID_PCIC_TI1131_CARDBUS:
-			sp->controller = PCIC_TI1131;
-			cinfo->name = "TI PCI-1131 [i82365 compatible mode]";
-			goto skip_isa_id_check;
-		case PCI_DEVICE_ID_PCIC_O2MICRO:
-			sp->controller = PCIC_O2MICRO;
-			cinfo->name = "O2micro PCI/PC-Card bridge";
-			goto skip_isa_id_check;
-		case PCI_DEVICE_ID_PCIC_CLPD6729:
-			sp->controller = PCIC_PD6729;
-			cinfo->name = "Cirrus Logic PD-6729/6730";
-			goto skip_isa_id_check;
 		}
-skip_pci_id_check:
 #endif
 		switch(sp->controller) {
 		case PCIC_I82365:
@@ -1283,7 +1325,7 @@
 		x = sp->getb(sp, CL6832_ExCA_EXTEND_DATA);
 #if 1
 printf("Experimental clpd-6832 support:\n");
-printf("please send the following message to hosokawa@jp.FreeBSD.org\n");
+printf("please send the following messages to hosokawa@jp.FreeBSD.org\n");
 printf("Misc 3 register is 0x%x\n", (u_int)x);
 #endif
 		x = ((x & ~0x3) | 0x1);	/* set "external hardware" bit */
--
HOSOKAWA, Tatsumi    
[Network Technology Center, Keio University]
hosokawa@ntc.keio.ac.jp
hosokawa@jp.FreeBSD.org
