Subject: pci_configure_bus(9) for sgimips O2
To: None <port-sgimips@NetBSD.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-sgimips
Date: 04/17/2006 00:00:08
Is there any reason why pci_mace.c uses its own PCI fixup code
rather than MI pci_configure_bus(9)?

The attached patch (with options PCI_NETBSD_CONFIGURE enabled)
seems to work on my R5k O2.
---
Izumi Tsutsui


Index: conf/GENERIC32_IP3x
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/conf/GENERIC32_IP3x,v
retrieving revision 1.48
diff -u -r1.48 GENERIC32_IP3x
--- conf/GENERIC32_IP3x	28 Mar 2006 20:58:41 -0000	1.48
+++ conf/GENERIC32_IP3x	16 Apr 2006 14:49:16 -0000
@@ -185,6 +185,8 @@
 mace0 		at mainbus0 addr 0x1f000000
 macepci0 	at mace0 offset 0x080000 intr 7
 pci0 		at macepci0 bus 0
+#pci*		at ppb? bus ?
+#options 	PCI_NETBSD_CONFIGURE
 
 # MACE devices
 mec0 		at mace0 offset 0x280000 intr 3
@@ -194,6 +196,9 @@
 com1 		at mace0 offset 0x398000 intr 4 intrmask 0xfc000000
 mcclock0	at mace0 offset 0x3a0000
 
+# PCI bridges
+#ppb*	at pci? dev ? function ?	# PCI-PCI bridges
+
 # PCI cryptographic devices
 hifn*	at pci? dev ? function ?	# Hifn 7755/7811/795x
 ubsec*	at pci? dev ? function ?	# Broadcom 5501/5601/580x/582x
Index: include/pci_machdep.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/include/pci_machdep.h,v
retrieving revision 1.7
diff -u -r1.7 pci_machdep.h
--- include/pci_machdep.h	11 Dec 2005 12:18:53 -0000	1.7
+++ include/pci_machdep.h	16 Apr 2006 14:49:16 -0000
@@ -60,6 +60,9 @@
 
 	bus_space_tag_t iot;
 	bus_space_handle_t ioh;
+
+	struct extent *pc_memext;	/* PCI memory space extent */
+	struct extent *pc_ioext;	/* PCI I/O space extent */
 };
 
 extern struct sgimips_bus_dma_tag pci_bus_dma_tag;
@@ -82,3 +85,6 @@
 void		*pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
 			int, int (*)(void *), void *);
 void		pci_intr_disestablish(pci_chipset_tag_t, void *);
+
+void		pci_conf_interrupt(pci_chipset_tag_t, int, int, int, int,
+			int *);
Index: mace/pci_mace.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/mace/pci_mace.c,v
retrieving revision 1.6
diff -u -r1.6 pci_mace.c
--- mace/pci_mace.c	11 Dec 2005 12:18:54 -0000	1.6
+++ mace/pci_mace.c	16 Apr 2006 14:49:16 -0000
@@ -36,6 +36,9 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: pci_mace.c,v 1.6 2005/12/11 12:18:54 christos Exp $");
 
+#include "opt_pci.h"
+#include "pci.h"
+
 #include <sys/param.h>
 #include <sys/device.h>
 #include <sys/systm.h>
@@ -51,10 +54,17 @@
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcidevs.h>
 
+#ifdef PCI_NETBSD_CONFIGURE
+#include <sys/extent.h>
+#include <sys/malloc.h>
+#include <dev/pci/pciconf.h>
+#endif
+
 #include <sgimips/mace/macereg.h>
 #include <sgimips/mace/macevar.h>
 
 #include <sgimips/mace/pcireg_mace.h>
+#ifndef PCI_NETBSD_CONFIGURE
 #include <sgimips/pci/pci_addr_fixup.h>
 
 #define PCIBIOS_PRINTV(arg) \
@@ -69,8 +79,7 @@
 
 #define PAGE_ALIGN(x)	(((x) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
 #define MEG_ALIGN(x)	(((x) + 0x100000 - 1) & ~(0x100000 - 1))
-
-#include "pci.h"
+#endif
 
 struct macepci_softc {
 	struct device sc_dev;
@@ -84,14 +93,14 @@
 void		macepci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
 int		macepci_intr(void *);
 
+#ifndef PCI_NETBSD_CONFIGURE
 struct pciaddr pciaddr;
 
-bus_addr_t pciaddr_ioaddr(u_int32_t val);
-
 int pciaddr_do_resource_allocate(pci_chipset_tag_t pc, pcitag_t tag, int mapreg, void *ctx, int type, bus_addr_t *addr, bus_size_t size);
 
 unsigned int ioaddr_base = 0x1000;
 unsigned int memaddr_base = 0x80100000;
+#endif
 
 CFATTACH_DECL(macepci, sizeof(struct macepci_softc),
     macepci_match, macepci_attach, NULL, NULL);
@@ -111,8 +120,11 @@
 	struct mace_attach_args *maa = aux;
 	struct pcibus_attach_args pba;
 	u_int32_t control;
+	int rev;
+#ifndef PCI_NETBSD_CONFIGURE
 	pcitag_t devtag;
-	int device, rev;
+	int device;
+#endif
 
 	if (bus_space_subregion(maa->maa_st, maa->maa_sh,
 	    maa->maa_offset, 0, &pc->ioh) )
@@ -145,6 +157,7 @@
 	    MACE_PCI_CONTROL_TAR_INT |
 	    MACE_PCI_CONTROL_MAR_INT);
 
+#ifndef PCI_NETBSD_CONFIGURE
 	/* Must fix up all PCI devices, ahc_pci expects proper i/o mapping */
 	for (device = 1; device < 4; device++) {
 		const struct pci_quirkdata *qd;
@@ -185,6 +198,7 @@
 			pciaddr_resource_manage(pc, devtag, NULL, NULL);
 		}
 	}
+#endif
 
 	/*
 	 * Enable all MACE PCI interrupts. They will be masked by
@@ -195,6 +209,14 @@
 	bus_space_write_4(pc->iot, pc->ioh, MACEPCI_CONTROL, control);
 
 #if NPCI > 0
+#ifdef PCI_NETBSD_CONFIGURE
+	pc->pc_ioext = extent_create("macepciio", 0x00001000, 0x01ffffff,
+	    M_DEVBUF, NULL, 0, EX_NOWAIT);
+	pc->pc_memext = extent_create("macepcimem", 0x80100000, 0x81ffffff,
+	    M_DEVBUF, NULL, 0, EX_NOWAIT);
+	pci_configure_bus(pc, pc->pc_ioext, pc->pc_memext, NULL, 0,
+	    mips_dcache_align);
+#endif
 	memset(&pba, 0, sizeof pba);
 /*XXX*/	pba.pba_iot = SGIMIPS_BUS_SPACE_IO;
 /*XXX*/	pba.pba_memt = SGIMIPS_BUS_SPACE_MEM;
@@ -333,6 +355,7 @@
 	return 0;
 }
 
+#ifndef PCI_NETBSD_CONFIGURE
 /* PCI Address fixup routines */
 
 void
@@ -531,3 +554,4 @@
 	printf("%03d:%02d:%d 0x%04x 0x%04x ", bus, device, function,
 	    PCI_VENDOR(id), PCI_PRODUCT(id));
 }
+#endif
Index: pci/pci_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/pci/pci_machdep.c,v
retrieving revision 1.16
diff -u -r1.16 pci_machdep.c
--- pci/pci_machdep.c	11 Dec 2005 12:18:58 -0000	1.16
+++ pci/pci_machdep.c	16 Apr 2006 14:49:16 -0000
@@ -35,6 +35,9 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.16 2005/12/11 12:18:58 christos Exp $");
 
+#include "opt_pci.h"
+#include "pci.h"
+
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/time.h>
@@ -88,7 +91,7 @@
 	if (busno == 0)
 		return 5;	/* 2 on-board SCSI chips, slots 0, 1 and 2 */
 	else
-		return 0;	/* XXX */
+		return 32;	/* XXX */
 }
 
 pcitag_t
@@ -197,3 +200,13 @@
 
 	(pc->intr_disestablish)(cookie);
 }
+
+#ifdef PCI_NETBSD_CONFIGURE
+void
+pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
+    int *iline)
+{
+
+	return;
+}
+#endif

---