Index: c/src/lib/libbsp/powerpc/shared/pci/pci.c
===================================================================
--- c/src/lib/libbsp/powerpc/shared/pci/pci.c	(revision acc25eec35e186abc118b9ca4f097e22fc6b4846)
+++ c/src/lib/libbsp/powerpc/shared/pci/pci.c	(revision 69ed59f083a083fd96d08b5f6d54f2c80f267f03)
@@ -15,24 +15,25 @@
  *
  *  $Id$
+ *
+ *  Till Straumann, <strauman@slac.stanford.edu>, 1/2002
+ *   - separated bridge detection code out of this file
  */
 
-#include <bsp/consoleIo.h>
 #include <libcpu/io.h>
 #include <bsp/pci.h>
-#include <bsp/residual.h>
-#include <bsp/openpic.h>
-#include <bsp.h>
-
+
+/* allow for overriding these definitions */
+#ifndef PCI_CONFIG_ADDR
 #define PCI_CONFIG_ADDR			0xcf8
+#endif
+#ifndef PCI_CONFIG_DATA
 #define PCI_CONFIG_DATA			0xcfc
+#endif
+
 #define PCI_INVALID_VENDORDEVICEID	0xffffffff
 #define PCI_MULTI_FUNCTION		0x80
-#define RAVEN_MPIC_IOSPACE_ENABLE	0x1
-#define RAVEN_MPIC_MEMSPACE_ENABLE	0x2
-#define RAVEN_MASTER_ENABLE		0x4
-#define RAVEN_PARITY_CHECK_ENABLE	0x40
-#define RAVEN_SYSTEM_ERROR_ENABLE	0x100
-#define RAVEN_CLEAR_EVENTS_MASK		0xf9000000
-
+
+/* define a shortcut */
+#define pci	BSP_pci_configuration
 
 /*
@@ -107,5 +108,5 @@
 }
 
-static const pci_config_access_functions indirect_functions = {
+const pci_config_access_functions pci_indirect_functions = {
   	indirect_pci_read_config_byte,
   	indirect_pci_read_config_word,
@@ -116,7 +117,7 @@
 };
 
-pci_config pci = {(volatile unsigned char*)PCI_CONFIG_ADDR,
+pci_config BSP_pci_configuration = {(volatile unsigned char*)PCI_CONFIG_ADDR,
 			 (volatile unsigned char*)PCI_CONFIG_DATA,
-			 &indirect_functions};
+			 &pci_indirect_functions};
 
 static int
@@ -206,5 +207,5 @@
 }
 
-static const pci_config_access_functions direct_functions = {
+const pci_config_access_functions pci_direct_functions = {
   	direct_pci_read_config_byte,
   	direct_pci_read_config_word,
@@ -216,92 +217,4 @@
 
 
-void detect_host_bridge()
-{
-  PPC_DEVICE *hostbridge;
-  unsigned int id0;
-  unsigned int tmp;
-  
-  /*
-   * This code assumes that the host bridge is located at
-   * bus 0, dev 0, func 0 AND that the old pre PCI 2.1
-   * standart devices detection mecahnism that was used on PC
-   * (still used in BSD source code) works.
-   */
-  hostbridge=residual_find_device(&residualCopy, PROCESSORDEVICE, NULL, 
-				  BridgeController,
-				  PCIBridge, -1, 0);
-  if (hostbridge) {
-    if (hostbridge->DeviceId.Interface==PCIBridgeIndirect) {
-      pci.pci_functions=&indirect_functions;
-      /* Should be extracted from residual data, 
-       * indeed MPC106 in CHRP mode is different,
-       * but we should not use residual data in
-       * this case anyway. 
-       */
-      pci.pci_config_addr = ((volatile unsigned char *) 
-			      (ptr_mem_map->io_base+0xcf8));
-      pci.pci_config_data = ptr_mem_map->io_base+0xcfc;
-    } else if(hostbridge->DeviceId.Interface==PCIBridgeDirect) {
-      pci.pci_functions=&direct_functions;
-      pci.pci_config_data=(unsigned char *) 0x80800000;
-    } else {
-    }
-  } else {
-    /* Let us try by experimentation at our own risk! */
-    pci.pci_functions = &direct_functions;
-    /* On all direct bridges I know the host bridge itself
-     * appears as device 0 function 0. 
-		 */
-    pci_read_config_dword(0, 0, 0, PCI_VENDOR_ID, &id0);
-    if (id0==~0U) {
-      pci.pci_functions = &indirect_functions;
-      pci.pci_config_addr = ((volatile unsigned char*)
-			      (ptr_mem_map->io_base+0xcf8));
-      pci.pci_config_data = ((volatile unsigned char*)ptr_mem_map->io_base+0xcfc);
-    }
-    /* Here we should check that the host bridge is actually
-     * present, but if it not, we are in such a desperate
-     * situation, that we probably can't even tell it.
-     */
-  }
-  pci_read_config_dword(0, 0, 0, 0, &id0);
-  if(id0 == PCI_VENDOR_ID_MOTOROLA +
-     (PCI_DEVICE_ID_MOTOROLA_RAVEN<<16)) {
-    /*
-     * We have a Raven bridge. We will get information about its settings
-     */
-    pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
-#ifdef SHOW_RAVEN_SETTING    
-    printk("RAVEN PCI command register = %x\n",id0);
-#endif    
-    id0 |= RAVEN_CLEAR_EVENTS_MASK;
-    pci_write_config_dword(0, 0, 0, PCI_COMMAND, id0);
-    pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
-#ifdef SHOW_RAVEN_SETTING    
-    printk("After error clearing RAVEN PCI command register = %x\n",id0);
-#endif    
-    
-    if (id0 & RAVEN_MPIC_IOSPACE_ENABLE) {
-      pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_0, &tmp);
-#ifdef SHOW_RAVEN_SETTING    
-      printk("Raven MPIC is accessed via IO Space Access at address : %x\n",(tmp & ~0x1));
-#endif    
-    }
-    if (id0 & RAVEN_MPIC_MEMSPACE_ENABLE) {
-      pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_1, &tmp);
-#ifdef SHOW_RAVEN_SETTING    
-      printk("Raven MPIC is accessed via memory Space Access at address : %x\n", tmp);
-#endif    
-      OpenPIC=(volatile struct OpenPIC *) (tmp + PREP_ISA_MEM_BASE);
-      printk("OpenPIC found at %p.\n",
-	     OpenPIC);
-    }
-  }
-  if (OpenPIC == (volatile struct OpenPIC *)0) {
-    BSP_panic("OpenPic Not found\n");
-  }
-
-}
-
 /*
  * This routine determines the maximum bus number in the system
@@ -309,4 +222,5 @@
 void InitializePCI()
 {
+  extern void detect_host_bridge();
   unsigned char ucSlotNumber, ucFnNumber, ucNumFuncs;
   unsigned char ucHeader;
