Index: c/src/lib/libbsp/powerpc/mvme5500/ChangeLog
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/ChangeLog	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/ChangeLog	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,2 +1,38 @@
+2009-04-20	Kate Feng <feng1@bnl.gov>
+
+	1396/bsps
+	* pci/pci.c : Updated it to be consistent with the original pci.c
+	* written by Eric Valette.  There is no change in its function.
+	* irq/irq_init.c : set defaultIrq->next_handler to be 0 
+	* for BSP_SHARED_HANDLER_SUPPORT.
+	* network/if_1GHz/if_wm.c : fixed some bugs in the 1GHz driver.
+	* irq/BSP_irq.c : added supports for shared IRQ.
+	* pci/pci_interface.c : Enabled PCI "Read", "Read Line", and
+	"Read Multiple"
+	*  Agressive Prefetch to improve the performance of the PCI based
+	*  applications (e.g. 1GHz NIC).
+	* irq/BSP_irq.c : Replaced the irq/irq.c, and used GT_GPP_Value
+	* register to monitor the cause of the level sensitive interrupts.
+	* This unique solution solves various bugs in the 1GHz network drivers
+	* Fixed bugs in compute_pic_masks_from_prio()
+
+2009-04-20	Kate Feng <feng1@bnl.gov>
+
+	1396/bsps
+	* pci/pci.c : Updated it to be consistent with the original pci.c
+	* written by Eric Valette.  There is no change in its function.
+	* irq/irq_init.c : set defaultIrq->next_handler to be 0 
+	* for BSP_SHARED_HANDLER_SUPPORT.
+	* network/if_1GHz/if_wm.c : fixed some bugs in the 1GHz driver.
+	* irq/BSP_irq.c : added supports for shared IRQ.
+	* pci/pci_interface.c : Enabled PCI "Read", "Read Line", and
+	"Read Multiple"
+	*  Agressive Prefetch to improve the performance of the PCI based
+	*  applications (e.g. 1GHz NIC).
+	* irq/BSP_irq.c : Replaced the irq/irq.c, and used GT_GPP_Value
+	* register to monitor the cause of the level sensitive interrupts.
+	* This unique solution solves various bugs in the 1GHz network drivers
+	* Fixed bugs in compute_pic_masks_from_prio()
+	
 2007-11-30	Joel Sherrill <joel.sherrill@OARcorp.com>
 
@@ -7,5 +43,5 @@
 
 	* network/if_100MHz/GT64260eth.c: Add else.
-
+   
 2007-09-19	Kate Feng <feng1@bnl.gov>
 
Index: c/src/lib/libbsp/powerpc/mvme5500/GT64260/GT64260TWSI.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/GT64260/GT64260TWSI.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/GT64260/GT64260TWSI.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,6 +1,7 @@
 /* GT64260TWSI.c : Two-Wire Serial Interface (TWSI) support for the GT64260
  *
- * Copyright (c) 2004, Brookhaven National Laboratory and
- *                 Shuchen Kate Feng <feng1@bnl.gov>
+ * Copyright (c) 2004, Brookhaven National Laboratory
+ *               and Shuchen Kate Feng <feng1@bnl.gov>
+ *               under the Deaprtment of Energy contract DE-AC02-98CH10886
  * All rights reserved.
  *
Index: c/src/lib/libbsp/powerpc/mvme5500/GT64260/GT64260TWSI.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/GT64260/GT64260TWSI.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/GT64260/GT64260TWSI.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,4 +1,8 @@
 /*
  *  $Id$
+ * 
+ *  Copyright 2003  S. Kate Feng <feng1@bnl.gov>,
+ *            NSLS, Brookhaven National Laboratory. All rights reserved.
+ *            under the Deaprtment of Energy contract DE-AC02-98CH10886
  */
 
Index: c/src/lib/libbsp/powerpc/mvme5500/GT64260/MVME5500I2C.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/GT64260/MVME5500I2C.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/GT64260/MVME5500I2C.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -3,4 +3,5 @@
  * Copyright (c) 2003, 2004 Brookhaven National Laboratory
  * Author:    S. Kate Feng <feng1@bnl.gov>
+ *            under the Deaprtment of Energy contract DE-AC02-98CH10886
  * All rights reserved.
  *
@@ -30,7 +31,8 @@
 * I2Cread_eeprom - read EEPROM VPD from the I2C
 */
-int I2Cread_eeprom(unchar I2cBusAddr,u32 devA2A1A0,u32 AddrBytes,unchar *pBuff,u32 numBytes)
+int I2Cread_eeprom(unchar I2cBusAddr,u32 devA2A1A0,u32 AddrBytes,void *pBuff,u32 numBytes)
 {
   int status=0, lastByte=0;
+  unchar *ptr=(unchar *) pBuff;
 
   switch (AddrBytes) {
@@ -84,10 +86,13 @@
      for ( ; numBytes > 0; numBytes-- ) {      
        if ( numBytes == 1) lastByte=1;
-       if (GT64260TWSIread(pBuff,lastByte) == -1) return (-1);
+       if (GT64260TWSIread(ptr,lastByte) == -1) {
+	 printk("numBytes %d\n", numBytes);
+          return (-1);
+       }
 #ifdef I2C_DEBUG
-       printk("%2x ", *pBuff);
+       printk("%2x ", *ptr);
        if ( (numBytes % 20)==0 ) printk("\n");
 #endif
-       pBuff++;	
+       ptr++;	
      }
 #ifdef I2C_DEBUG
Index: c/src/lib/libbsp/powerpc/mvme5500/GT64260/VPD.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/GT64260/VPD.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/GT64260/VPD.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -3,9 +3,73 @@
  * (C) 2004, NSLS, Brookhaven National Laboratory,
  *           S. Kate Feng, <feng1@bnl.gov>
- *
+ *  under the Deaprtment of Energy contract DE-AC02-98CH10886
  */
 
 extern unsigned char ConfVPD_buff[200];
 
-#define VPD_ENET0_OFFSET  0x3c
-#define VPD_ENET1_OFFSET  0x45
+typedef struct ConfVpdRec {
+  char VendorId[8];
+  char pad0[4];
+  char BrdId[13];
+  char pad1[2];
+  char ManAssmNum[12];
+  char pad2[2];
+  char SerialNum[7];
+  char pad3[2];
+  /*  char IntClk[4];*/
+  uint32_t IntClk;
+  char pad4[3];
+  /*char ExtClk[4];*/
+  uint32_t ExtClk;
+  char pad5[3];
+  char EnetAddr0[7];
+  char pad6[2];
+  char EnetAddr1[7];
+  char pad7[20];
+} ConfVpdRec_t;
+
+#define VPD_BOARD_ID   8
+#define VPD_ENET0_OFFSET  0x40
+#define VPD_ENET1_OFFSET  0x49
+
+/*
+4D4F544F 524F4C41 0200010D 4D564D45  MOTOROLA....MVME
+35353030 2D303136 33020C30 312D5733  5500-0163..01-W3
+38323946 30314403 07373035 31383238  829F01D..7051828
+05053B9A CA000106 0507F281 55010807  ..;.........U...
+ethernet address
+xxxxxxxx xxxxxxxx xxxxxxxx xxxx3701  ................
+09043734 35350A04 87A6E98C 0B0C0089  ..7455..."=.....
+00181002 02101000 78070B0C FFFFFFFF  ........x.......
+10020210 10017805 0E0FFFFF FFFFFFFF  ......x.........
+FFFFFF01 FF01FFFF FF0F0400 03000019  ................
+0A010107 02030000 000100FF FFFFFFFF  ................
+FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  ................
+FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  ................
+00000000 00000000 00000000 00000000  ................
+00000000 00000000 00000000 00000000  ................
+00000000 00000000 00000000 00000000  ................
+00000000 00000000 00000000 00000000  ................
+
+For the MVME5500 :
+
+Product Identifier                 : MVME5500-0163
+Manufacturing Assembly Number      : 01-W3829F01D
+Serial Number                      : 7051828
+Internal Clock Speed (Hertz)       : 3B9ACA00 (&1000000000)
+External Clock Speed (Hertz)       : 07F28155 (&133333333)
+Ethernet Address                   : xx xx xx xx xx xx xx
+Ethernet Address                   : xx xx xx xx xx xx xx
+Microprocessor Type                : 7455
+SROM/EEPROM CRC                    : D3223DD0 (&-752730672)
+Flash0 Memory Configuration        : 00 89 00 18 10 02 02 10
+                                   : 10 00 78 07
+Flash1 Memory Configuration        : FF FF FF FF 10 02 02 10
+                                   : 10 01 78 05
+L2 Cache Configuration             : FF FF FF FF FF FF FF FF
+                                   : FF 01 FF 01 FF FF FF
+VPD Revision                       : 00 03 00 00
+L3 Cache Configuration             : 01 01 07 02 03 00 00 00
+                                   : 01 00
+                                                                               
+*/
Index: c/src/lib/libbsp/powerpc/mvme5500/GT64260/gtreg.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/GT64260/gtreg.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/GT64260/gtreg.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -191,5 +191,5 @@
 #define GT_MPP_Control3			0xf00c
 
-/* <skf> added */
+/* <skf> added for GT64260 */
 #define GT_MPP_SerialPortMultiplex      0xf010
 
@@ -791,11 +791,23 @@
 
 /* Interrupt Controller - Interrupt Controller Registers */
+/* <skf> added for GT64360 */
+
+#define GT64360_MAIN_INT_CAUSE_LO	0x004 /* read Only */
+#define GT64360_MAIN_INT_CAUSE_HI       0x00c /* read Only */
+#define GT64360_CPU0_INT_MASK_LO 	0x014
+#define GT64360_CPU0_INT_MASK_HI	0x01c
+#define GT64360_CPU0_SEL_CAUSE	        0x024 /* read Only */
+
+#define GT64360_CPU1_INT_MASK_LO 	0x034
+#define GT64360_CPU1_INT_MASK_HI	0x03c
+#define GT64360_CPU1_SEL_CAUSE	        0x044 /* read Only */
+
 /* Section 25.2 : Table 734 <skf> */
 
-#define GT_MAIN_INT_CAUSE_LO	0xc18 /* read Only */
-#define GT_MAIN_INT_CAUSE_HI   0xc68 /* read Only */
-#define GT_CPU_INT_MASK_LO 	0xc1c
-#define GT_CPU_INT_MASK_HI	0xc6c
-#define GT_CPU_SEL_CAUSE	0xc70 /* read Only */
+#define GT64260_MAIN_INT_CAUSE_LO	0xc18 /* read Only */
+#define GT64260_MAIN_INT_CAUSE_HI       0xc68 /* read Only */
+#define GT64260_CPU_INT_MASK_LO 	0xc1c
+#define GT64260_CPU_INT_MASK_HI	        0xc6c
+#define GT64260_CPU_SEL_CAUSE	0xc70 /* read Only */
 #define GT_PCI0_INT_MASK_LO	0xc24
 #define GT_PCI0_INT_MASK_HI	0xc64
Index: c/src/lib/libbsp/powerpc/mvme5500/Makefile.am
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/Makefile.am	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/Makefile.am	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -36,5 +36,6 @@
     ../../powerpc/shared/startup/sbrk.c ../../shared/bootcard.c \
     startup/bspclean.c ../../shared/bsplibc.c ../../shared/bsppost.c \
-    ../../shared/gnatinstallhandler.c startup/reboot.c
+    ../../shared/gnatinstallhandler.c startup/reboot.c \
+    ../../powerpc/shared/startup/probeMemEnd.c
 startup_rel_CPPFLAGS = $(AM_CPPFLAGS)
 startup_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
@@ -69,6 +70,6 @@
 
 noinst_PROGRAMS += irq.rel
-irq_rel_SOURCES = irq/irq_init.c irq/irq.c \
-    ../../powerpc/shared/irq/irq_asm.S
+irq_rel_SOURCES = irq/irq_init.c irq/BSP_irq.c \
+   ../../powerpc/shared/irq/irq.c ../../powerpc/shared/irq/irq_asm.S
 irq_rel_CPPFLAGS = $(AM_CPPFLAGS)
 irq_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
@@ -109,6 +110,7 @@
 network_CPPFLAGS = -D_KERNEL
 noinst_PROGRAMS += network.rel
-network_rel_SOURCES = network/if_100MHz/GT64260eth.c \
-    network/if_1GHz/if_wm.c network/if_1GHz/pci_map.c
+network_rel_SOURCES = network/if_100MHz/GT64260eth.c network/if_1GHz/if_wm.c \
+	network/if_1GHz/pci_map.c
+
 network_rel_CPPFLAGS = $(AM_CPPFLAGS) $(network_CPPFLAGS)
 network_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
@@ -124,6 +126,6 @@
 noinst_PROGRAMS += vme.rel
 vme_rel_SOURCES = ../../shared/vmeUniverse/vmeUniverse.c\
-	../shared/vme/vmeconfig.c ../../shared/vmeUniverse/bspVmeDmaList.c\
-	../shared/vme/vme_universe.c ../shared/vme/vme_universe_dma.c
+	vme/vmeconfig.c ../../shared/vmeUniverse/bspVmeDmaList.c\
+	../shared/vme/vme_universe_dma.c
 
 vme_rel_CPPFLAGS = $(AM_CPPFLAGS)
Index: c/src/lib/libbsp/powerpc/mvme5500/README
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/README	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/README	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,4 +1,4 @@
 #
-#  $Id: README,v 1.3.1  Shuchen Kate Feng, NSLS, BNL (08/27/07)
+#  $Id: README,v 1.4.1  Shuchen Kate Feng, NSLS, BNL (03/16/2009)
 #
 
@@ -8,5 +8,5 @@
 reference README.irq 
 
-The BSP is built and tested on the 4.7.1 and 4.7.99.2 CVS RTEMS release.
+The BSP is built and tested on the 4.8.0 RTEMS release.
 
 I believe in valuable real-time programming, where technical neatness,
Index: c/src/lib/libbsp/powerpc/mvme5500/README.booting
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/README.booting	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/README.booting	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,7 +1,5 @@
-README.booting: written by S. Kate Feng <feng1@bnl.gov>, Aug. 28, 2007
+README.booting: written by S. Kate Feng <feng1@bnl.gov>, March 16, 2009
 
-The bootloader is adapted from Till Straumann's Generic Mini-loader,
-which he wrote originally for the SVGM powerpc board. 
-The BSP is built and tested on the 4.7 CVS RTEMS release.
+The BSP is built and tested on the  RTEMS 4.8.0 release.
 
 Booting requirement :
@@ -12,10 +10,5 @@
    (Note : EPICS needs a NTP server).
  
-2) Please copy the prebuilt RTEMS binary (e.g. misc/rtems5500-cexp.bin)
-   and perhaps others (e.g. misc/st.sys) to the /tftpboot/epics/hostname/bin/
-   directory or the TFTPBOOT one you specified in the 'tftpGet'
-   command of the boot script (as shown in the following example).
-
-3) Example of the boot script setup carried out on the MOTLoad 
+2) Example of the boot script setup carried out on the MOTLoad 
    command line : 
 
@@ -33,21 +26,12 @@
         sxx.xx.xx.xx is the server IP address)
 
-4) Other reference web sites for mvme5500 BSP:
-http://lansce.lanl.gov/EPICS/presentations/KateFeng%20RTEMS-mvme55001.ppt
+3) Other reference web sites for mvme5500 BSP:
 http://www.nsls.bnl.gov/facility/expsys/software/EPICS/
-http://www.nsls.bnl.gov/facility/expsys/software/EPICS/FAQ.txt
 
-5) When generating code (especially C++) for this system, one should
-   use at least gcc-3.2 (preferrably a copy downloaded from the RTEMS
-   site [snapshot area] )
 
-6) To reboot the RTEMS-MVME5500 (board reset), one can invoke the
+4) To reboot the RTEMS-MVME5500 (board reset), one can invoke the
    rtemsReboot() command at Cexp> prompt.
  
-7) Please reference http://www.slac.stanford.edu/~strauman/rtems
-for the source code and installation guidance of cexp, GeSys and
-other useful utilities such as telnet, nfs, and so on. 
-
-8) To get started with RTEMS/EPICS and to build development
+5) To get started with RTEMS/EPICS and to build development
 tools and BSP, I would recommend one to reference
 http://www.aps.anl.gov/epics/base/RTEMS/tutorial/
Index: c/src/lib/libbsp/powerpc/mvme5500/include/bsp.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/include/bsp.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/include/bsp.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -8,5 +8,6 @@
  *  http://www.rtems.com/license/LICENSE.
  *
- *  S. Kate Feng 2003-2007 : Modified it to support the mvme5500 BSP.
+ *  (C) S. Kate Feng 2003-2007 : Modified it to support the mvme5500 BSP.
+ *
  *
  */
@@ -23,8 +24,55 @@
 #include <bsp/vectors.h>
 
-#include <bsp/bspMvme5500.h>
+/* Board type */
+typedef enum {
+	undefined = 0,
+	MVME5500,
+	MVME6100
+} BSP_BoardTypes;
+
+BSP_BoardTypes BSP_getBoardType();
+
+/* Board type */
+typedef enum {
+	Undefined,
+	UNIVERSE2,
+	TSI148,
+} BSP_VMEchipTypes;
+
+BSP_VMEchipTypes BSP_getVMEchipType();
+
+/* The version of Discovery system controller */
+
+typedef enum {
+	notdefined, 
+	GT64260A,
+	GT64260B,	    
+	MV64360,
+} DiscoveryChipVersion;
+
+DiscoveryChipVersion BSP_getDiscoveryChipVersion();
+
+#define _256M           0x10000000
+#define _512M           0x20000000
+
+#define GT64x60_REG_BASE	0xf1000000  /* Base of GT64260 Reg Space */
+#define GT64x60_REG_SPACE_SIZE	0x10000     /* 64Kb Internal Reg Space */
+
+#define GT64x60_DEV1_BASE       0xf1100000  /* Device bank1(chip select 1) base
+                                             */
+#define GT64260_DEV1_SIZE 	0x00100000 /* Device bank size */
 
 /* fundamental addresses for this BSP (PREPxxx are from libcpu/io.h) */
-#define _IO_BASE GT64260_REG_BASE
+#define _IO_BASE GT64x60_REG_BASE
+
+#define BSP_NVRAM_BASE_ADDR     0xf1110000
+
+#define BSP_RTC_INTA_REG        0x7ff0
+#define BSP_RTC_SECOND	        0x7ff2  
+#define BSP_RTC_MINUTE	        0x7ff3
+#define BSP_RTC_HOUR	        0x7ff4  
+#define BSP_RTC_DATE	        0x7ff5
+#define BSP_RTC_INTERRUPTS      0x7ff6
+#define BSP_RTC_WATCHDOG        0x7ff7
 
 /* PCI0 Domain I/O space */
@@ -73,13 +121,10 @@
 
 /* uart.c uses out_8 instead of outb  */
-#define BSP_UART_IOBASE_COM1	GT64260_DEV1_BASE + 0x20000
-#define BSP_UART_IOBASE_COM2	GT64260_DEV1_BASE + 0x21000
+#define BSP_UART_IOBASE_COM1	GT64x60_DEV1_BASE + 0x20000
+#define BSP_UART_IOBASE_COM2	GT64x60_DEV1_BASE + 0x21000
 
 #define BSP_CONSOLE_PORT		BSP_UART_COM1  /* console */
 #define BSP_UART_BAUD_BASE		115200
 
-/*
- * Vital Board data Start using DATA RESIDUAL
- */
 /*
  * Total memory using RESIDUAL DATA
@@ -121,17 +166,24 @@
 #endif
 
-extern int
-RTEMS_BSP_NETWORK_DRIVER_ATTACH(/* struct rtems_bsdnet_ifconfig * */);
+extern int RTEMS_BSP_NETWORK_DRIVER_ATTACH();
 
-/* As per Linux, This should be in the ppc/system.h */
+#define gccMemBar() RTEMS_COMPILER_MEMORY_BARRIER()
 
+static inline void lwmemBar()
+{
+    asm volatile("lwsync":::"memory");
+}
+
+static inline void io_flush()
+{
+    asm volatile("isync":::"memory");
+}
 static inline void memBar()
 {
     asm volatile("sync":::"memory");
 }
-
 static inline void ioBar()
 {
-    asm volatile("eieio");
+    asm volatile("eieio":::"memory");
 }
 
Index: c/src/lib/libbsp/powerpc/mvme5500/irq/BSP_irq.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/irq/BSP_irq.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
+++ c/src/lib/libbsp/powerpc/mvme5500/irq/BSP_irq.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -0,0 +1,514 @@
+/*  BSP_irq.c
+ *
+ *  This file contains the implementation of the function described in irq.h
+ *
+ *  Copyright (C) 1998, 1999 valette@crf.canon.fr
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.OARcorp.com/rtems/license.html.
+ *
+ *  Acknowledgement to Till Straumann <strauman@slac.stanford.edu>
+ *  for some inputs in May 2004.
+ *
+ *  Copyright 2003, 2004, 2005, 2007  Shuchen Kate Feng <feng1@bnl.gov>,
+ *            NSLS, Brookhaven National Laboratory. All rights reserved.
+ *
+ *  1) Used GT_GPP_Value register instead of the GT_GPP_Interrupt_Cause
+ *     register to monitor the cause of the level sensitive interrupts.
+ *     (Copyright : NDA item)
+ *  2) The implementation of picPrioTable[] is an original work by the
+ *     author to optimize the software IRQ priority scheduling because
+ *     Discovery controller does not provide H/W IRQ priority schedule. 
+ *     It ensures the fastest/faster interrupt service to the
+ *     highest/higher priority IRQ, if pendig.
+ *  3) _CPU_MSR_SET() needs RTEMS_COMPILER_MEMORY_BARRIER()
+ * 
+ */
+
+#include <stdio.h>  
+#include <rtems/system.h>
+#include <bsp.h>
+#include <bsp/irq.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apiext.h>
+#include <libcpu/raw_exception.h>
+#include <rtems/rtems/intr.h>
+#include <libcpu/io.h>
+#include <libcpu/byteorder.h>
+#include <bsp/vectors.h>
+
+#include <rtems/bspIo.h> /* for printk */
+#include "bsp/gtreg.h"
+
+#define HI_INT_CAUSE 0x40000000
+
+#define MAX_IRQ_LOOP 20
+
+#define _MSR_GET( _mask) \
+  do { \
+     RTEMS_COMPILER_MEMORY_BARRIER(); \
+     _CPU_MSR_GET( _mask); \
+     RTEMS_COMPILER_MEMORY_BARRIER(); \
+  } while (0);
+
+#define _MSR_SET( _mask) \
+  do { \
+     RTEMS_COMPILER_MEMORY_BARRIER(); \
+     _CPU_MSR_SET( _mask); \
+     RTEMS_COMPILER_MEMORY_BARRIER(); \
+  } while (0);
+
+/* #define DEBUG_IRQ*/
+
+/*
+ * pointer to the mask representing the additionnal irq vectors
+ * that must be disabled when a particular entry is activated.
+ * They will be dynamically computed from the table given
+ * in BSP_rtems_irq_mngt_set();
+ * CAUTION : this table is accessed directly by interrupt routine
+ * 	     prologue.
+ */
+static unsigned int BSP_irq_prio_mask_tbl[3][BSP_PIC_IRQ_NUMBER];
+
+/*
+ * default handler connected on each irq after bsp initialization
+ */
+static rtems_irq_connect_data	default_rtems_entry;
+
+/*
+ * location used to store initial tables used for interrupt
+ * management.BSP copy of the configuration 
+ */
+static rtems_irq_global_settings	BSP_config;
+
+static volatile unsigned  *BSP_irqMask_reg[3];
+static volatile unsigned  *BSP_irqCause_reg[3];
+static volatile unsigned  BSP_irqMask_cache[3]={0,0,0}; 
+static unsigned int BSP_GPP_mask[4]= { 1<<24, 1<<25, 1<<26, 1<<27};
+
+static int picPrioTblPtr=0;
+static unsigned int GPPIrqInTbl=0;
+static unsigned long long MainIrqInTbl=0;
+
+/* 
+ * The software developers are forbidden to setup picPrioTable[],
+ * as it is a powerful engine for the BSP to find the pending
+ * highest priority IRQ at run time.  It ensures the fastest/faster
+ * interrupt service to the highest/higher priority IRQ, if pendig.
+ *
+ * The picPrioTable[96] is updated dynamically at run time
+ * based on the priority levels set at BSPirqPrioTable[96],
+ * while the BSP_enable_irq_at_pic(), and BSP_disable_irq_at_pic()
+ * commands are invoked.
+ *
+ * The picPrioTable[96] lists the enabled CPU main and GPP external interrupt 
+ * numbers [0 (lowest)- 95 (highest)] starting from the highest priority
+ * one to the lowest priority one. The highest priority interrupt is
+ * located at picPrioTable[0], and the lowest priority interrupt is located
+ * at picPrioTable[picPrioTblPtr-1].
+ *
+ *
+ */
+#define DynamicIsrTable
+#ifdef DynamicIsrTable
+/* BitNums for Main Interrupt Lo/High Cause, -1 means invalid bit */ 
+static unsigned int picPrioTable[BSP_PIC_IRQ_NUMBER]={ 
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1 };
+#else
+static unsigned int picPrioTable[BSP_PIC_IRQ_NUMBER]={ 
+     80, 84, 76, 77, 32, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+     -1, -1, -1, -1, -1, -1 };
+#endif
+
+/*
+ * Check if IRQ is a MAIN CPU internal IRQ or GPP external IRQ
+ */
+static inline int is_pic_irq(const rtems_irq_number irqLine)
+{
+  return (((int) irqLine <= BSP_GPP_IRQ_MAX_OFFSET) &
+	  ((int) irqLine >= BSP_MICL_IRQ_LOWEST_OFFSET)
+	 );
+}
+
+/*
+ * Check if IRQ is a Porcessor IRQ
+ */
+static inline int is_processor_irq(const rtems_irq_number irqLine)
+{
+  return (((int) irqLine <= BSP_PROCESSOR_IRQ_MAX_OFFSET) &
+	  ((int) irqLine >= BSP_PROCESSOR_IRQ_LOWEST_OFFSET)
+	 );
+}
+
+/*
+ * ------------------------ RTEMS Irq helper functions ----------------
+ */
+ 
+/*
+ * Caution : this function assumes the variable "BSP_config"
+ * is already set and that the tables it contains are still valid
+ * and accessible.
+ */
+static void compute_pic_masks_from_prio()
+{
+  int i,j, k, isGppMain;
+  unsigned long long irq_prio_mask=0;
+
+  /*
+   * Always mask at least current interrupt to prevent re-entrance
+   */
+  for (i=0; i <BSP_PIC_IRQ_NUMBER; i++) {
+    switch(i) {
+      case BSP_MAIN_GPP7_0_IRQ:
+      case BSP_MAIN_GPP15_8_IRQ:
+      case BSP_MAIN_GPP23_16_IRQ:
+      case BSP_MAIN_GPP31_24_IRQ:
+	for (k=0; k< 3; k++)
+	    BSP_irq_prio_mask_tbl[k][i]=0;
+
+        irq_prio_mask =0;
+        isGppMain =1;
+        break;
+      default : 
+        isGppMain =0;
+        irq_prio_mask = (unsigned long long) (1LLU << i);
+	break;
+    }
+    if ( isGppMain) continue; 
+    for (j = 0; j <BSP_MAIN_IRQ_NUMBER; j++) {
+        /*
+         * Mask interrupts at PIC level that have a lower priority
+         * or <Till Straumann> a equal priority. 
+         */
+        if (BSP_config.irqPrioTbl [i] >= BSP_config.irqPrioTbl [j])
+	   irq_prio_mask |= (unsigned long long)(1LLU << j);
+    }
+    
+
+    BSP_irq_prio_mask_tbl[0][i] = irq_prio_mask & 0xffffffff;
+    BSP_irq_prio_mask_tbl[1][i] = (irq_prio_mask>>32) & 0xffffffff;
+#if 0
+    printk("irq_mask_prio_tbl[%d]:0x%8x%8x\n",i,BSP_irq_prio_mask_tbl[1][i],
+	   BSP_irq_prio_mask_tbl[0][i]);
+#endif 
+
+    BSP_irq_prio_mask_tbl[2][i] = 1<<i;
+    /* Compute for the GPP priority interrupt mask */
+    for (j=BSP_GPP_IRQ_LOWEST_OFFSET; j <BSP_PROCESSOR_IRQ_LOWEST_OFFSET; j++) {      
+      if (BSP_config.irqPrioTbl [i] >= BSP_config.irqPrioTbl [j])
+	   BSP_irq_prio_mask_tbl[2][i] |= 1 << (j-BSP_GPP_IRQ_LOWEST_OFFSET); 
+    }
+#if 0
+    printk("GPPirq_mask_prio_tbl[%d]:0x%8x\n",i,BSP_irq_prio_mask_tbl[2][i]);
+#endif 
+  }
+}
+
+static void UpdateMainIrqTbl(int irqNum)
+{
+  int i=0, j, k, shifted=0;
+
+  switch (irqNum) {
+    case BSP_MAIN_GPP7_0_IRQ:
+    case BSP_MAIN_GPP15_8_IRQ:
+    case BSP_MAIN_GPP23_16_IRQ:
+    case BSP_MAIN_GPP31_24_IRQ:  
+      return;  /* Do nothing, let GPP take care of it */
+      break;
+  }
+#ifdef SHOW_MORE_INIT_SETTINGS
+  unsigned long val2, val1;
+#endif
+
+  /* If entry not in table*/
+  if ( ((irqNum<BSP_GPP_IRQ_LOWEST_OFFSET) && 
+        (!((unsigned long long)(1LLU << irqNum) & MainIrqInTbl))) ||
+       ((irqNum>BSP_MICH_IRQ_MAX_OFFSET) && 
+        (!(( 1 << (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)) & GPPIrqInTbl))))
+  { 
+      while ( picPrioTable[i]!=-1) {
+        if (BSP_config.irqPrioTbl[irqNum]>BSP_config.irqPrioTbl[picPrioTable[i]]) {
+          /* all other lower priority entries shifted right */
+          for (j=picPrioTblPtr;j>i; j--) {
+              picPrioTable[j]=picPrioTable[j-1];
+          }
+          picPrioTable[i]=irqNum;
+          shifted=1;
+          break;
+       }
+       i++;
+     }
+     if (!shifted) picPrioTable[picPrioTblPtr] =irqNum;
+
+     if (irqNum >BSP_MICH_IRQ_MAX_OFFSET)
+        GPPIrqInTbl |= (1<< (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)); 
+     else      
+        MainIrqInTbl |= (unsigned long long)(1LLU << irqNum);
+     picPrioTblPtr++;
+  }
+#ifdef SHOW_MORE_INIT_SETTINGS
+  val2 = (MainIrqInTbl>>32) & 0xffffffff;
+  val1 = MainIrqInTbl&0xffffffff;
+  printk("irqNum %d, MainIrqInTbl 0x%x%x\n", irqNum, val2, val1); 
+  BSP_printPicIsrTbl();
+#endif
+
+}
+
+
+static void CleanMainIrqTbl(int irqNum)
+{
+  int i, j, k;
+
+  switch (irqNum) {
+    case BSP_MAIN_GPP7_0_IRQ:
+    case BSP_MAIN_GPP15_8_IRQ:
+    case BSP_MAIN_GPP23_16_IRQ:
+    case BSP_MAIN_GPP31_24_IRQ: 
+      return;  /* Do nothing, let GPP take care of it */
+      break;  
+  }
+  if ( ((irqNum<BSP_GPP_IRQ_LOWEST_OFFSET) && 
+        ((unsigned long long)(1LLU << irqNum) & MainIrqInTbl)) ||
+       ((irqNum>BSP_MICH_IRQ_MAX_OFFSET) && 
+        (( 1 << (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)) & GPPIrqInTbl)))
+  { /* If entry in table*/
+     for (i=0; i<64; i++) {
+       if (picPrioTable[i]==irqNum) {/*remove it from the entry */
+          /* all other lower priority entries shifted left */
+	  for (j=i;j<picPrioTblPtr; j++) {
+              picPrioTable[j]=picPrioTable[j+1];
+          }
+          if (irqNum >BSP_MICH_IRQ_MAX_OFFSET)
+            GPPIrqInTbl &= ~(1<< (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)); 
+          else      
+            MainIrqInTbl &= ~(1LLU << irqNum);
+          picPrioTblPtr--;
+          break;
+       }
+     }
+  }
+}
+
+void BSP_enable_irq_at_pic(const rtems_irq_number irqNum)
+{
+  unsigned bitNum, regNum;
+  unsigned int level;
+
+  bitNum = (((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET)%32;
+  regNum = (((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET)>>5;
+
+  rtems_interrupt_disable(level); 
+
+#ifdef DynamicIsrTable
+  UpdateMainIrqTbl((int) irqNum);
+#endif
+  BSP_irqMask_cache[regNum] |= (1 << bitNum);
+
+  out_le32(BSP_irqMask_reg[regNum], BSP_irqMask_cache[regNum]);
+  while (in_le32(BSP_irqMask_reg[regNum]) != BSP_irqMask_cache[regNum]);
+
+  memBar();
+  rtems_interrupt_enable(level);
+}
+
+void BSP_disable_irq_at_pic(const rtems_irq_number irqNum)
+{
+  unsigned bitNum, regNum;
+  unsigned int level;
+
+  bitNum = (((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET)%32;
+  regNum = (((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET)>>5;
+
+  rtems_interrupt_disable(level); 
+
+#ifdef DynamicIsrTable
+  CleanMainIrqTbl((int) irqNum);
+#endif
+  BSP_irqMask_cache[regNum] &=  ~(1 << bitNum);
+
+  out_le32(BSP_irqMask_reg[regNum], BSP_irqMask_cache[regNum]);
+  while (in_le32(BSP_irqMask_reg[regNum]) != BSP_irqMask_cache[regNum]);
+  memBar();
+  rtems_interrupt_enable(level);
+}
+
+/* Use shared/irq : 2008 */
+int BSP_setup_the_pic(rtems_irq_global_settings* config)  
+{
+    int i;
+
+    BSP_config = *config;
+
+    switch(BSP_getDiscoveryChipVersion()) {
+    case GT64260B:
+    case GT64260A:
+      /* Get ready for discovery BSP */
+      BSP_irqMask_reg[0]= (volatile unsigned int *) (GT64x60_REG_BASE + GT64260_CPU_INT_MASK_LO);
+      BSP_irqMask_reg[1]= (volatile unsigned int *) (GT64x60_REG_BASE + GT64260_CPU_INT_MASK_HI);
+      BSP_irqCause_reg[0]= (volatile unsigned int *) (GT64x60_REG_BASE + GT64260_MAIN_INT_CAUSE_LO);
+      BSP_irqCause_reg[1]= (volatile unsigned int *) (GT64x60_REG_BASE + GT64260_MAIN_INT_CAUSE_HI);
+      break;
+    default:
+      printk("Not supported by this BSP yet\n");
+      return(0);
+      break;
+    }
+
+    BSP_irqMask_reg[2]= (volatile unsigned int *) (GT64x60_REG_BASE + GT_GPP_Interrupt_Mask);
+    BSP_irqCause_reg[2]= (volatile unsigned int *) (GT64x60_REG_BASE + GT_GPP_Value);
+
+    /* Page 401, Table 598:
+     * Comm Unit Arbiter Control register :
+     * bit 10:GPP interrupts as level sensitive(1) or edge sensitive(0).
+     * MOTload default is set as level sensitive(1). Set it agin to make sure.
+     */
+    outl((inl(GT_CommUnitArb_Ctrl)| (1<<10)), GT_CommUnitArb_Ctrl);
+
+#if 0
+    printk("BSP_irqMask_reg[0] = 0x%x, BSP_irqCause_reg[0] 0x%x\n", 
+	   in_le32(BSP_irqMask_reg[0]),
+	   in_le32(BSP_irqCause_reg[0]));
+    printk("BSP_irqMask_reg[1] = 0x%x, BSP_irqCause_reg[1] 0x%x\n", 
+	   in_le32(BSP_irqMask_reg[1]),
+	   in_le32(BSP_irqCause_reg[1]));
+    printk("BSP_irqMask_reg[2] = 0x%x, BSP_irqCause_reg[2] 0x%x\n", 
+	   in_le32(BSP_irqMask_reg[2]),
+	   in_le32(BSP_irqCause_reg[2]));
+#endif
+
+    /* Initialize the interrupt related  registers */
+    for (i=0; i<3; i++) {
+      out_le32(BSP_irqCause_reg[i], 0);
+      out_le32(BSP_irqMask_reg[i], 0);
+    }         
+    in_le32(BSP_irqMask_reg[2]);
+    compute_pic_masks_from_prio();
+
+#if 0
+    printk("BSP_irqMask_reg[0] = 0x%x, BSP_irqCause_reg[0] 0x%x\n", 
+	   in_le32(BSP_irqMask_reg[0]),
+	   in_le32(BSP_irqCause_reg[0]));
+    printk("BSP_irqMask_reg[1] = 0x%x, BSP_irqCause_reg[1] 0x%x\n", 
+	   in_le32(BSP_irqMask_reg[1]),
+	   in_le32(BSP_irqCause_reg[1]));
+    printk("BSP_irqMask_reg[2] = 0x%x, BSP_irqCause_reg[2] 0x%x\n", 
+	   in_le32(BSP_irqMask_reg[2]),
+	   in_le32(BSP_irqCause_reg[2]));
+#endif
+
+    /*
+     * 
+     */
+    for (i=BSP_MICL_IRQ_LOWEST_OFFSET; i < BSP_PROCESSOR_IRQ_LOWEST_OFFSET ; i++) {
+      if ( BSP_config.irqHdlTbl[i].hdl != BSP_config.defaultEntry.hdl) {
+	BSP_enable_irq_at_pic(i);
+	BSP_config.irqHdlTbl[i].on(&BSP_config.irqHdlTbl[i]);
+      }
+      else {
+	BSP_config.irqHdlTbl[i].off(&BSP_config.irqHdlTbl[i]);
+	BSP_disable_irq_at_pic(i);
+      }
+    }
+    for (i= BSP_MAIN_GPP7_0_IRQ; i < BSP_MAIN_GPP31_24_IRQ; i++) 
+      BSP_enable_irq_at_pic(i);
+    
+    return(1);
+}
+
+/*
+ * High level IRQ handler called from shared_raw_irq_code_entry
+ */
+
+void C_dispatch_irq_handler (CPU_Interrupt_frame *frame, unsigned int excNum)
+{
+  register unsigned msr, new_msr;
+  unsigned long irqCause[3]={0, 0,0};
+  unsigned oldMask[3]={0,0,0};
+  int loop=0, wloop=0, i=0, j;
+  register irq=0, group=0;
+
+  if (excNum == ASM_DEC_VECTOR) {
+    _MSR_GET(msr);
+    new_msr = msr | MSR_EE;
+    _MSR_SET(new_msr);
+    
+    BSP_config.irqHdlTbl[BSP_DECREMENTER].hdl(BSP_config.irqHdlTbl[BSP_DECREMENTER].handle);
+    _MSR_SET(msr);
+    return;
+    
+  }
+
+  for (j=0; j<3; j++ ) oldMask[j] = BSP_irqMask_cache[j];
+  for (j=0; j<3; j++) irqCause[j] = in_le32(BSP_irqCause_reg[j]) & in_le32(BSP_irqMask_reg[j]);
+
+  while (((irq = picPrioTable[i++])!=-1)&& (loop++ < MAX_IRQ_LOOP))
+  {    
+    if (irqCause[group= irq/32] & ( 1<<(irq % 32))) {
+      for (j=0; j<3; j++)
+        BSP_irqMask_cache[j] &= (~ BSP_irq_prio_mask_tbl[j][irq]);
+
+      out_le32(BSP_irqMask_reg[0], BSP_irqMask_cache[0]);
+      out_le32(BSP_irqMask_reg[1], BSP_irqMask_cache[1]);
+      out_le32(BSP_irqMask_reg[2], BSP_irqMask_cache[2]);
+      in_le32(BSP_irqMask_reg[2]);
+      
+      _MSR_GET(msr);
+      new_msr = msr | MSR_EE;
+      _MSR_SET(new_msr); 
+      /* handler */
+#ifdef BSP_SHARED_HANDLER_SUPPORT
+      {
+	 rtems_irq_connect_data* vchain;
+	 for( vchain = &BSP_config.irqHdlTbl[irq];
+	    (vchain->hdl != BSP_config.defaultEntry.hdl && ((int)vchain != -1) );
+	    vchain = (rtems_irq_connect_data*)vchain->next_handler )
+	 {
+	    vchain->hdl(vchain->handle);
+	 }
+      }
+#else
+      BSP_config.irqHdlTbl[irq].hdl(BSP_config.irqHdlTbl[irq].handle);
+#endif
+      _MSR_SET(msr);
+
+      for (j=0; j<3; j++ ) BSP_irqMask_cache[j] = oldMask[j];
+ 
+      out_le32(BSP_irqMask_reg[0], oldMask[0]);
+      out_le32(BSP_irqMask_reg[1], oldMask[1]);
+      out_le32(BSP_irqMask_reg[2], oldMask[2]);
+      in_le32(BSP_irqMask_reg[2]);
+    }
+  }
+}
+
+/* Only print part of the entries for now */
+void BSP_printPicIsrTbl()
+{
+  int i;
+
+  printf("picPrioTable[12]={ irq# :");
+  for (i=0; i<12; i++)
+    printf("%d,", picPrioTable[i]);
+  printf("}\n");
+
+  printf("GPPIrqInTbl: 0x%x :\n", GPPIrqInTbl);
+}
Index: src/lib/libbsp/powerpc/mvme5500/irq/irq.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/irq/irq.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ 	(revision )
@@ -1,681 +1,0 @@
-/*  irq.c
- *
- *  This file contains the implementation of the function described in irq.h
- *
- *  Copyright (C) 1998, 1999 valette@crf.canon.fr
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.OARcorp.com/rtems/license.html.
- *
- *  Acknowledgement May 2004 : to Till Straumann <strauman@slac.stanford.edu>
- *  for some inputs.
- *
- *  Copyright 2003, 2004, 2005, 2007  Shuchen Kate Feng <feng1@bnl.gov>,
- *                  NSLS,Brookhaven National Laboratory
- *  1) Modified and added support for the MVME5500 board.
- *  2) The implementation of picIsrTable[] is an original work by the
- *     author to optimize the software IRQ priority scheduling because
- *     Discovery controller does not provide H/W IRQ priority schedule. 
- *     It ensures the fastest/faster interrupt service to the
- *     highest/higher priority IRQ, if pendig.
- *  3) _CPU_MSR_SET() needs RTEMS_COMPILER_MEMORY_BARRIER()
- *
- */
-  
-#include <rtems/system.h>
-#include <bsp.h>
-#include <bsp/irq.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/apiext.h>
-#include <libcpu/raw_exception.h>
-#include <rtems/rtems/intr.h>
-#include <libcpu/io.h>
-#include <libcpu/byteorder.h>
-#include <bsp/vectors.h>
-
-#include <rtems/bspIo.h> /* for printk */
-#include "bsp/gtreg.h"
-
-#define HI_INT_CAUSE 0x40000000
-
-#define MAX_IRQ_LOOP 30
-
-#define EDGE_TRIGGER
-
-#define _MSR_GET( _mask) \
-  do { \
-     RTEMS_COMPILER_MEMORY_BARRIER(); \
-     _CPU_MSR_GET( _mask); \
-     RTEMS_COMPILER_MEMORY_BARRIER(); \
-  } while (0);
-
-#define _MSR_SET( _mask) \
-  do { \
-     RTEMS_COMPILER_MEMORY_BARRIER(); \
-     _CPU_MSR_SET( _mask); \
-     RTEMS_COMPILER_MEMORY_BARRIER(); \
-  } while (0);
-
-/* #define DEBUG_IRQ*/
-
-/*
- * pointer to the mask representing the additionnal irq vectors
- * that must be disabled when a particular entry is activated.
- * They will be dynamically computed from the table given
- * in BSP_rtems_irq_mngt_set();
- * CAUTION : this table is accessed directly by interrupt routine
- * 	     prologue.
- */
-static unsigned int BSP_irq_prio_mask_tbl[3][BSP_PIC_IRQ_NUMBER];
-
-/*
- * default handler connected on each irq after bsp initialization
- */
-static rtems_irq_connect_data	default_rtems_entry;
-
-/*
- * location used to store initial tables used for interrupt
- * management.
- */
-static rtems_irq_global_settings* 	internal_config;
-static rtems_irq_connect_data*		rtems_hdl_tbl;
-
-static volatile unsigned  *BSP_irqMask_reg[3];
-static volatile unsigned  *BSP_irqCause_reg[3];
-static volatile unsigned  BSP_irqMask_cache[3]={0,0,0}; 
-
-
-static int picIsrTblPtr=0;
-static unsigned int GPPIrqInTbl=0;
-static unsigned long long MainIrqInTbl=0;
-
-/* 
- * The software developers are forbidden to setup picIsrTable[],
- * as it is a powerful engine for the BSP to find the pending
- * highest priority IRQ at run time.  It ensures the fastest/faster
- * interrupt service to the highest/higher priority IRQ, if pendig.
- *
- * The picIsrTable[96] is updated dynamically at run time
- * based on the priority levels set at BSPirqPrioTable[96],
- * while the BSP_enable_pic_irq(), and BSP_disable_pic_irq()
- * commands are invoked.
- *
- * The picIsrTable[96] lists the enabled CPU main and GPP external interrupt 
- * numbers [0 (lowest)- 95 (highest)] starting from the highest priority
- * one to the lowest priority one. The highest priority interrupt is
- * located at picIsrTable[0], and the lowest priority interrupt is located
- * at picIsrTable[picIsrTblPtr-1].
- *
- *
- */
-/* BitNums for Main Interrupt Lo/High Cause and GPP, -1 means invalid bit */ 
-static unsigned int picIsrTable[BSP_PIC_IRQ_NUMBER]={  
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-     -1, -1, -1, -1, -1, -1 };
-
-
-/*
- * Check if IRQ is a MAIN CPU internal IRQ or GPP external IRQ
- */
-static inline int is_pic_irq(const rtems_irq_number irqLine)
-{
-  return (((int) irqLine <= BSP_GPP_IRQ_MAX_OFFSET) &
-	  ((int) irqLine >= BSP_MICL_IRQ_LOWEST_OFFSET)
-	 );
-}
-
-/*
- * Check if IRQ is a Porcessor IRQ
- */
-static inline int is_processor_irq(const rtems_irq_number irqLine)
-{
-  return (((int) irqLine <= BSP_PROCESSOR_IRQ_MAX_OFFSET) &
-	  ((int) irqLine >= BSP_PROCESSOR_IRQ_LOWEST_OFFSET)
-	 );
-}
-
-static inline unsigned int divIrq32(unsigned irq)
-{
-  return(irq/32);
-}
-
-static inline unsigned int modIrq32(unsigned irq)
-{
-   return(irq%32);
-}
-
-/*
- * ------------------------ RTEMS Irq helper functions ----------------
- */
- 
-/*
- * Caution : this function assumes the variable "internal_config"
- * is already set and that the tables it contains are still valid
- * and accessible.
- */
-static void compute_pic_masks_from_prio()
-{
-  int i,j, k;
-  unsigned long long irq_prio_mask=0;
-
-  /*
-   * Always mask at least current interrupt to prevent re-entrance
-   */
-  for (i=0; i <BSP_PIC_IRQ_NUMBER; i++) {
-    switch(i) {
-      case BSP_MAIN_GPP7_0_IRQ:
-      case BSP_MAIN_GPP15_8_IRQ:
-      case BSP_MAIN_GPP23_16_IRQ:
-      case BSP_MAIN_GPP31_24_IRQ:
-	for (k=0; k< 3; k++)
-	    BSP_irq_prio_mask_tbl[k][i]=0;
-
-        irq_prio_mask =0;
-        break;
-      default : 
-        irq_prio_mask = (unsigned long long) (1LLU << i);
-	break;
-    }
-    
-    if (irq_prio_mask) {
-    for (j = 0; j <BSP_MAIN_IRQ_NUMBER; j++) {
-        /*
-         * Mask interrupts at PIC level that have a lower priority
-         * or <Till Straumann> a equal priority. 
-         */
-        if (internal_config->irqPrioTbl [i] >= internal_config->irqPrioTbl [j])
-	   irq_prio_mask |= (unsigned long long)(1LLU << j);
-    }
-    
-
-    BSP_irq_prio_mask_tbl[0][i] = irq_prio_mask & 0xffffffff;
-    BSP_irq_prio_mask_tbl[1][i] = (irq_prio_mask>>32) & 0xffffffff;
-#ifdef DEBUG
-    printk("irq_mask_prio_tbl[%d]:0x%8x%8x\n",i,BSP_irq_prio_mask_tbl[1][i],
-	   BSP_irq_prio_mask_tbl[0][i]);
-#endif 
-
-    BSP_irq_prio_mask_tbl[2][i] = 1<<i;
-    /* Compute for the GPP priority interrupt mask */
-    for (j=BSP_GPP_IRQ_LOWEST_OFFSET; j <BSP_PROCESSOR_IRQ_LOWEST_OFFSET; j++) {      
-      if (internal_config->irqPrioTbl [i] >= internal_config->irqPrioTbl [j])
-	   BSP_irq_prio_mask_tbl[2][i] |= 1 << (j-BSP_GPP_IRQ_LOWEST_OFFSET); 
-    }
-    }
-  }
-}
-
-
-static void UpdateMainIrqTbl(int irqNum)
-{
-  int i=0, j, shifted=0;
-
-  switch (irqNum) {
-    case BSP_MAIN_GPP7_0_IRQ:
-    case BSP_MAIN_GPP15_8_IRQ:
-    case BSP_MAIN_GPP23_16_IRQ:
-    case BSP_MAIN_GPP31_24_IRQ:  
-      return;  /* Do nothing, let GPP take care of it */
-      break;
-  }
-#ifdef SHOW_MORE_INIT_SETTINGS
-  unsigned long val2, val1;
-#endif
-
-  /* If entry not in table*/
-  if ( ((irqNum<BSP_GPP_IRQ_LOWEST_OFFSET) && 
-        (!((unsigned long long)(1LLU << irqNum) & MainIrqInTbl))) ||
-       ((irqNum>BSP_MICH_IRQ_MAX_OFFSET) && 
-        (!(( 1 << (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)) & GPPIrqInTbl))))
-  { 
-      while ( picIsrTable[i]!=-1) {
-        if (internal_config->irqPrioTbl[irqNum]>internal_config->irqPrioTbl[picIsrTable[i]]) {
-          /* all other lower priority entries shifted right */
-          for (j=picIsrTblPtr;j>i; j--) 
-              picIsrTable[j]=picIsrTable[j-1];
-          picIsrTable[i]=irqNum;
-          shifted=1;
-          break;
-       }
-       i++;
-     }
-     if (!shifted) picIsrTable[picIsrTblPtr]=irqNum;
-     if (irqNum >BSP_MICH_IRQ_MAX_OFFSET)
-        GPPIrqInTbl |= (1<< (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)); 
-     else      
-        MainIrqInTbl |= (unsigned long long)(1LLU << irqNum);
-     picIsrTblPtr++;
-  }
-#ifdef SHOW_MORE_INIT_SETTINGS
-  val2 = (MainIrqInTbl>>32) & 0xffffffff;
-  val1 = MainIrqInTbl&0xffffffff;
-  printk("irqNum %d, MainIrqInTbl 0x%x%x\n", irqNum, val2, val1); 
-  BSP_printPicIsrTbl();
-#endif
-
-}
-
-
-static void CleanMainIrqTbl(int irqNum)
-{
-  int i, j;
-
-  switch (irqNum) {
-    case BSP_MAIN_GPP7_0_IRQ:
-    case BSP_MAIN_GPP15_8_IRQ:
-    case BSP_MAIN_GPP23_16_IRQ:
-    case BSP_MAIN_GPP31_24_IRQ: 
-      return;  /* Do nothing, let GPP take care of it */
-      break;  
-  }
-  if ( ((irqNum<BSP_GPP_IRQ_LOWEST_OFFSET) && 
-        ((unsigned long long)(1LLU << irqNum) & MainIrqInTbl)) ||
-       ((irqNum>BSP_MICH_IRQ_MAX_OFFSET) && 
-        (( 1 << (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)) & GPPIrqInTbl)))
-  { /* If entry in table*/
-     for (i=0; i<64; i++) {
-       if (picIsrTable[i]==irqNum) {/*remove it from the entry */
-          /* all other lower priority entries shifted left */
-          for (j=i;j<picIsrTblPtr; j++) 
-              picIsrTable[j]=picIsrTable[j+1];
-          if (irqNum >BSP_MICH_IRQ_MAX_OFFSET)
-            GPPIrqInTbl &= ~(1<< (irqNum-BSP_GPP_IRQ_LOWEST_OFFSET)); 
-          else      
-            MainIrqInTbl &= ~(1LLU << irqNum);
-          picIsrTblPtr--;
-          break;
-       }
-     }
-  }
-}
-
-void BSP_enable_pic_irq(const rtems_irq_number irqNum)
-{
-  unsigned bitNum, regNum;
-  unsigned int level;
-
-  bitNum = modIrq32(((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET);
-  regNum = divIrq32(((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET);
-
-  rtems_interrupt_disable(level); 
-
-  UpdateMainIrqTbl((int) irqNum);
-  BSP_irqMask_cache[regNum] |= (1 << bitNum);
-
-  out_le32(BSP_irqMask_reg[regNum], BSP_irqMask_cache[regNum]);
-  while (in_le32(BSP_irqMask_reg[regNum]) != BSP_irqMask_cache[regNum]);
-
-  rtems_interrupt_enable(level);
-}
-
-void BSP_disable_pic_irq(const rtems_irq_number irqNum)
-{
-  unsigned bitNum, regNum;
-  unsigned int level;
-
-  bitNum = modIrq32(((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET);
-  regNum = divIrq32(((unsigned int)irqNum) - BSP_MICL_IRQ_LOWEST_OFFSET);
-
-  rtems_interrupt_disable(level); 
-
-  CleanMainIrqTbl((int) irqNum);
-  BSP_irqMask_cache[regNum] &=  ~(1 << bitNum);
-
-  out_le32(BSP_irqMask_reg[regNum], BSP_irqMask_cache[regNum]);
-  while (in_le32(BSP_irqMask_reg[regNum]) != BSP_irqMask_cache[regNum]);
-
-  rtems_interrupt_enable(level);
-}
-
-int BSP_setup_the_pic()  /* adapt the same name as shared/irq */
-{
-    int i;
-
-    /* Get ready for discovery BSP */
-    BSP_irqMask_reg[0]= (volatile unsigned int *) (GT64260_REG_BASE + GT_CPU_INT_MASK_LO);
-    BSP_irqMask_reg[1]= (volatile unsigned int *) (GT64260_REG_BASE + GT_CPU_INT_MASK_HI);
-    BSP_irqMask_reg[2]= (volatile unsigned int *) (GT64260_REG_BASE + GT_GPP_Interrupt_Mask);
-
-    BSP_irqCause_reg[0]= (volatile unsigned int *) (GT64260_REG_BASE + GT_MAIN_INT_CAUSE_LO);
-    BSP_irqCause_reg[1]= (volatile unsigned int *) (GT64260_REG_BASE + GT_MAIN_INT_CAUSE_HI);
-    BSP_irqCause_reg[2]= (volatile unsigned int *) (GT64260_REG_BASE + GT_GPP_Interrupt_Cause);
-
-#ifdef EDGE_TRIGGER
-
-    /* Page 401, Table 598:
-     * Comm Unit Arbiter Control register :
-     * bit 10:GPP interrupts as level sensitive(1) or edge sensitive(0).
-     * We set the GPP interrupts to be edge sensitive.
-     * MOTload default is set as level sensitive(1).
-     */
-    outl((inl(GT_CommUnitArb_Ctrl)& (~(1<<10))), GT_CommUnitArb_Ctrl);
-#else
-    outl((inl(GT_CommUnitArb_Ctrl)| (1<<10)), GT_CommUnitArb_Ctrl);
-#endif
-
-#if 0
-    printk("BSP_irqMask_reg[0] = 0x%x, BSP_irqCause_reg[0] 0x%x\n", 
-	   in_le32(BSP_irqMask_reg[0]),
-	   in_le32(BSP_irqCause_reg[0]));
-    printk("BSP_irqMask_reg[1] = 0x%x, BSP_irqCause_reg[1] 0x%x\n", 
-	   in_le32(BSP_irqMask_reg[1]),
-	   in_le32(BSP_irqCause_reg[1]));
-    printk("BSP_irqMask_reg[2] = 0x%x, BSP_irqCause_reg[2] 0x%x\n", 
-	   in_le32(BSP_irqMask_reg[2]),
-	   in_le32(BSP_irqCause_reg[2]));
-#endif
-
-    /* Initialize the interrupt related GT64260 registers */
-    for (i=0; i<3; i++) {
-      out_le32(BSP_irqCause_reg[i], 0);
-      out_le32(BSP_irqMask_reg[i], 0);
-    }         
-    in_le32(BSP_irqMask_reg[2]);
-    compute_pic_masks_from_prio();
-
-#if 0
-    printk("BSP_irqMask_reg[0] = 0x%x, BSP_irqCause_reg[0] 0x%x\n", 
-	   in_le32(BSP_irqMask_reg[0]),
-	   in_le32(BSP_irqCause_reg[0]));
-    printk("BSP_irqMask_reg[1] = 0x%x, BSP_irqCause_reg[1] 0x%x\n", 
-	   in_le32(BSP_irqMask_reg[1]),
-	   in_le32(BSP_irqCause_reg[1]));
-    printk("BSP_irqMask_reg[2] = 0x%x, BSP_irqCause_reg[2] 0x%x\n", 
-	   in_le32(BSP_irqMask_reg[2]),
-	   in_le32(BSP_irqCause_reg[2]));
-#endif
-
-    /*
-     * 
-     */
-    for (i=BSP_MICL_IRQ_LOWEST_OFFSET; i < BSP_PROCESSOR_IRQ_LOWEST_OFFSET ; i++) {
-      if (rtems_hdl_tbl[i].hdl != default_rtems_entry.hdl) {
-	BSP_enable_pic_irq(i);
-	rtems_hdl_tbl[i].on(&rtems_hdl_tbl[i]);
-      }
-      else {
-	rtems_hdl_tbl[i].off(&rtems_hdl_tbl[i]);
-	BSP_disable_pic_irq(i);
-      }
-    }
-
-    return(1);
-}
-
-/*
- * This function check that the value given for the irq line
- * is valid.
- */
-
-static int isValidInterrupt(int irq)
-{
-  if ( (irq < BSP_LOWEST_OFFSET) || (irq > BSP_MAX_OFFSET))
-    return 0;
-  return 1;
-}
-
-/*
- * ------------------------ RTEMS Single Irq Handler Mngt Routines ----------------
- */
-
-int BSP_install_rtems_irq_handler  (const rtems_irq_connect_data* irq)
-{
-    unsigned int level;
-  
-    if (!isValidInterrupt(irq->name)) {
-      printk("Invalid interrupt vector %d\n",irq->name);
-      return 0;
-    }
-    /*
-     * Check if default handler is actually connected. If not issue an error.
-     * You must first get the current handler via i386_get_current_idt_entry
-     * and then disconnect it using i386_delete_idt_entry.
-     * RATIONALE : to always have the same transition by forcing the user
-     * to get the previous handler before accepting to disconnect.
-     */
-    rtems_interrupt_disable(level);
-    if (rtems_hdl_tbl[irq->name].hdl != default_rtems_entry.hdl) {
-      rtems_interrupt_enable(level);
-      printk("IRQ vector %d already connected\n",irq->name);
-      return 0;
-    }
-
-    /*
-     * store the data provided by user
-     */
-    rtems_hdl_tbl[irq->name] = *irq;
-#ifdef BSP_SHARED_HANDLER_SUPPORT
-    rtems_hdl_tbl[irq->name].next_handler = (void *)-1;
-#endif
-
-    if (is_pic_irq(irq->name)) {
-      /*
-       * Enable PIC  irq : Main Interrupt Cause Low and High & GPP external
-       */
-#ifdef DEBUG_IRQ
-      printk("PIC irq %d\n",irq->name);
-#endif
-      BSP_enable_pic_irq(irq->name);
-    }
-    else {
-      if (is_processor_irq(irq->name)) {
-         /*
-          * Enable exception at processor level
-          */
-
-       }
-    }
-    /*
-     * Enable interrupt on device
-     */
-    irq->on(irq);
-    
-    rtems_interrupt_enable(level);
-
-    return 1;
-}
-
-
-int BSP_get_current_rtems_irq_handler	(rtems_irq_connect_data* irq)
-{
-     if (!isValidInterrupt(irq->name)) {
-      return 0;
-     }
-     *irq = rtems_hdl_tbl[irq->name];
-     return 1;
-}
-
-int BSP_remove_rtems_irq_handler  (const rtems_irq_connect_data* irq)
-{
-    unsigned int level;
-  
-    if (!isValidInterrupt(irq->name)) {
-      return 0;
-    }
-    /*
-     * Check if default handler is actually connected. If not issue an error.
-     * You must first get the current handler via i386_get_current_idt_entry
-     * and then disconnect it using i386_delete_idt_entry.
-     * RATIONALE : to always have the same transition by forcing the user
-     * to get the previous handler before accepting to disconnect.
-     */
-    if (rtems_hdl_tbl[irq->name].hdl != irq->hdl) {
-      return 0;
-    }
-    rtems_interrupt_disable(level);
-
-    /*
-     * disable PIC interrupt
-     */
-    if (is_pic_irq(irq->name))
-      BSP_disable_pic_irq(irq->name);
-    else {
-      if (is_processor_irq(irq->name)) {
-         /*
-          * disable exception at processor level
-          */
-       }
-    }    
-
-    /*
-     * Disable interrupt on device
-     */
-    irq->off(irq);
-
-    /*
-     * restore the default irq value
-     */
-    rtems_hdl_tbl[irq->name] = default_rtems_entry;
-
-
-    rtems_interrupt_enable(level);
-
-    return 1;
-}
-
-/*
- * ------------------------ RTEMS Global Irq Handler Mngt Routines ----------------
- */
-
-int BSP_rtems_irq_mngt_set(rtems_irq_global_settings* config)
-{
-    unsigned int level;
-    int i;
-
-   /*
-    * Store various code accelerators
-    */
-    internal_config 		= config;
-    default_rtems_entry 	= config->defaultEntry;
-    rtems_hdl_tbl 		= config->irqHdlTbl;
-
-    rtems_interrupt_disable(level);
-
-    if ( !BSP_setup_the_pic() ) {
-       printk("PIC setup failed; leaving IRQs OFF\n");
-       return 0;
-    }
-
-    for (i= BSP_MAIN_GPP7_0_IRQ; i <= BSP_MAIN_GPP31_24_IRQ; i++) 
-      BSP_enable_pic_irq(i);
-
-    rtems_interrupt_enable(level);
-    return 1;
-}
-
-int BSP_rtems_irq_mngt_get(rtems_irq_global_settings** config)
-{
-    *config = internal_config;
-    return 0;
-}    
-
-/*
- * High level IRQ handler called from shared_raw_irq_code_entry
- */
-
-void C_dispatch_irq_handler (CPU_Interrupt_frame *frame, unsigned int excNum)
-{
-  register unsigned msr, new_msr;
-  unsigned long irqCause[3]={0, 0,0};
-  register unsigned long selectCause;
-  unsigned oldMask[3]={0,0,0};
-  register unsigned i=0, j, irq=0, bitmask=0, group=0;
-
-  if (excNum == ASM_DEC_VECTOR) {
-    _MSR_GET(msr);
-    new_msr = msr | MSR_EE;
-    _MSR_SET(new_msr);
-    
-    rtems_hdl_tbl[BSP_DECREMENTER].hdl(rtems_hdl_tbl[BSP_DECREMENTER].handle);
-
-    _MSR_SET(msr);
-    return;
-    
-  }
-
-  for (j=0; j<3; j++ ) oldMask[j] = BSP_irqMask_cache[j];
-
-  if ((selectCause= in_le32((volatile unsigned *)0xf1000c70)) & HI_INT_CAUSE ){
-    irqCause[1] = (selectCause & BSP_irqMask_cache[1]);
-    irqCause[2] = in_le32(BSP_irqCause_reg[2]) & BSP_irqMask_cache[2];
-  }
-  else {
-    irqCause[0] = (selectCause & BSP_irqMask_cache[0]);
-    if ((irqCause[1] =(in_le32((volatile unsigned *)0xf1000c68)&BSP_irqMask_cache[1])))
-       irqCause[2] = in_le32(BSP_irqCause_reg[2]) & BSP_irqMask_cache[2];
-  }
-  
-  while ((irq = picIsrTable[i++])!=-1)
-  {
-    if (irqCause[group=(irq/32)] && (irqCause[group]&(bitmask=(1<<(irq % 32))))) {
-      for (j=0; j<3; j++)
-        BSP_irqMask_cache[j] &= (~ BSP_irq_prio_mask_tbl[j][irq]);
-
-      RTEMS_COMPILER_MEMORY_BARRIER();
-      out_le32((volatile unsigned *)0xf1000c1c, BSP_irqMask_cache[0]);
-      out_le32((volatile unsigned *)0xf1000c6c, BSP_irqMask_cache[1]);
-      out_le32((volatile unsigned *)0xf100f10c, BSP_irqMask_cache[2]);
-      in_le32((volatile unsigned *)0xf100f10c);
-
-#ifdef EDGE_TRIGGER
-      if (irq > BSP_MICH_IRQ_MAX_OFFSET)
-         out_le32(BSP_irqCause_reg[2], ~bitmask);/* Till Straumann: Ack the edge triggered GPP IRQ */
-#endif
-
-      _MSR_GET(msr);
-      new_msr = msr | MSR_EE;
-      _MSR_SET(new_msr); 
-      rtems_hdl_tbl[irq].hdl(rtems_hdl_tbl[irq].handle);
-      _MSR_SET(msr);
-      
-      for (j=0; j<3; j++ ) BSP_irqMask_cache[j] = oldMask[j];
-      break;
-    }
-  }
-
-  out_le32((volatile unsigned *)0xf1000c1c, oldMask[0]);
-  out_le32((volatile unsigned *)0xf1000c6c, oldMask[1]);
-  out_le32((volatile unsigned *)0xf100f10c, oldMask[2]);
-  in_le32((volatile unsigned *)0xf100f10c);
-}
-
-void _ThreadProcessSignalsFromIrq (BSP_Exception_frame* ctx)
-{
-  /*
-   * Process pending signals that have not already been
-   * processed by _Thread_Displatch. This happens quite
-   * unfrequently : the ISR must have posted an action
-   * to the current running thread.
-   */
-  if ( _Thread_Do_post_task_switch_extension ||
-       _Thread_Executing->do_post_task_switch_extension ) {
-    _Thread_Executing->do_post_task_switch_extension = FALSE;
-    _API_extensions_Run_postswitch();
-  }
-  /*
-   * I plan to process other thread related events here.
-   * This will include DEBUG session requested from keyboard...
-   */
-}
-
-/* Only print part of the entries for now */
-void BSP_printPicIsrTbl()
-{
-  int i;
-
-  printk("picIsrTable[12]={");
-  for (i=0; i<12; i++)
-    printk("%d,", picIsrTable[i]);
-  printk("}\n");
-
-  printk("GPPIrqInTbl: 0x%x :\n", GPPIrqInTbl);
-}
Index: c/src/lib/libbsp/powerpc/mvme5500/irq/irq.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/irq/irq.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/irq/irq.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -30,5 +30,6 @@
 #define LIBBSP_POWERPC_MVME5500_IRQ_IRQ_H
 
-/*#define BSP_SHARED_HANDLER_SUPPORT      1*/
+#define BSP_SHARED_HANDLER_SUPPORT      1
+
 #include <rtems/irq.h>
 
@@ -85,9 +86,9 @@
    * Summary
    */
-#define BSP_IRQ_NUMBER			(BSP_MISC_IRQ_MAX_OFFSET + 1)
+#define BSP_IRQ_NUMBER			(BSP_PIC_IRQ_NUMBER + BSP_PROCESSOR_IRQ_NUMBER)
 #define BSP_MAIN_IRQ_NUMBER             (64)
 #define BSP_PIC_IRQ_NUMBER              (96)
-#define BSP_LOWEST_OFFSET		(BSP_MICL_IRQ_LOWEST_OFFSET)
-#define BSP_MAX_OFFSET			(BSP_MISC_IRQ_MAX_OFFSET)
+#define BSP_LOWEST_OFFSET		(0)
+#define BSP_MAX_OFFSET			(BSP_LOWEST_OFFSET + BSP_IRQ_NUMBER - 1)
 
   /* Main CPU interrupt cause (Low) */
Index: c/src/lib/libbsp/powerpc/mvme5500/irq/irq_init.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/irq/irq_init.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/irq/irq_init.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -42,8 +42,16 @@
 static rtems_irq_connect_data     	rtemsIrq[BSP_IRQ_NUMBER];
 static rtems_irq_global_settings     	initial_config;
+
+#ifdef BSP_SHARED_HANDLER_SUPPORT
+static rtems_irq_connect_data     	defaultIrq = {
+  /* vectorIdex,  hdl	    ,handle  , on	, off	   , isOn      ,next_handler, */
+  0, 		  nop_func  , NULL   , nop_func	, nop_func , not_connected, 0
+};
+#else
 static rtems_irq_connect_data     	defaultIrq = {
   /* vectorIdex,	 hdl	  , handle	, on		, off		, isOn */
   0, 			 nop_func  , NULL	, nop_func	, nop_func	, not_connected
 };
+#endif
 
 rtems_irq_prio BSPirqPrioTable[BSP_PIC_IRQ_NUMBER]={
@@ -141,25 +149,4 @@
 #endif      
 
-  /*
-   * We must connect the raw irq handler for the two
-   * expected interrupt sources : decrementer and external interrupts.
-   */
-  vectorDesc.exceptIndex 	= ASM_DEC_VECTOR;
-  vectorDesc.hdl.vector	= ASM_DEC_VECTOR;
-  vectorDesc.hdl.raw_hdl	= decrementer_exception_vector_prolog_code;
-  vectorDesc.hdl.raw_hdl_size	= (unsigned) decrementer_exception_vector_prolog_code_size;
-  vectorDesc.on		= nop_func;
-  vectorDesc.off		= nop_func;
-  vectorDesc.isOn		= connected;
-  if (!ppc_set_exception (&vectorDesc)) {
-      BSP_panic("Unable to initialize RTEMS decrementer raw exception\n");
-  }
-  vectorDesc.exceptIndex	= ASM_EXT_VECTOR;
-  vectorDesc.hdl.vector	= ASM_EXT_VECTOR;
-  vectorDesc.hdl.raw_hdl	= external_exception_vector_prolog_code;
-  vectorDesc.hdl.raw_hdl_size	= (unsigned) external_exception_vector_prolog_code_size;
-  if (!ppc_set_exception (&vectorDesc)) {
-      BSP_panic("Unable to initialize RTEMS external raw exception\n");
-    }
 #ifdef TRACE_IRQ_INIT  
   printk("RTEMS IRQ management is now operationnal\n");
Index: c/src/lib/libbsp/powerpc/mvme5500/network/if_100MHz/GT64260eth.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/network/if_100MHz/GT64260eth.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/network/if_100MHz/GT64260eth.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -3,21 +3,14 @@
  * Copyright (c) 2003,2004 Brookhaven National  Laboratory
  *               S. Kate Feng <feng1@bnl.gov>
- * All rights reserved 
+ *               All rights reserved 
  *
  * Acknowledgements:
  * netBSD : Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc. 
  * Marvell : NDA document for the discovery system controller
- * The author referenced two RTEMS network drivers of other NICs.
- * rtems : 1) dec21140.c, a network driver for for TULIP based Ethernet Controller
- *            (C) 1999 Emmanuel Raguet. raguet@crf.canon.fr
- *
- *         2) yellowfin.c, a network driver for the SVGM5 BSP.
- *           Stanford Linear Accelerator Center, Till Straumann 
  *
  * Some notes from the author, S. Kate Feng :
  *
  * 1) Mvme5500 uses Eth0 (controller 0) of the GT64260 to implement
- *    the 10/100 BaseT Ethernet with PCI Master Data Byte Swap\
- *    control.
+ *    the 10/100 BaseT Ethernet with PCI Master Data Byte Swap control.
  * 2) Implemented hardware snoop instead of software snoop
  *    to ensure SDRAM cache coherency. (Copyright : NDA item)
@@ -56,4 +49,5 @@
 #include <net/if.h>
 #include <net/if_dl.h>
+#include <net/ethernet.h>
 #include <netinet/in.h>
 #include <netinet/if_ether.h>
@@ -111,5 +105,5 @@
 #define	ET_MINLEN 64		/* minimum message length */
 
-static int GTeth_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
+static int GTeth_ifioctl(struct ifnet *ifp, ioctl_command_t cmd, caddr_t data);
 static void GTeth_ifstart (struct ifnet *);
 static void GTeth_ifchange(struct GTeth_softc *sc);
@@ -170,6 +164,6 @@
 
   if ( (!cause) || (cause & 0x803d00)) {
-       sc->intr_errsts[sc->intr_err_ptr2++]=cause;
-       sc->intr_err_ptr2 %=INTR_ERR_SIZE;   /* Till Straumann */
+       sc->if_errsts[sc->if_err_ptr2]=cause;
+       if ( (++sc->if_err_ptr2) == IF_ERR_BUFSZE) sc->if_err_ptr2=0; /* Till Straumann */
        events |= ERR_EVENT;
   }  
@@ -202,5 +196,5 @@
 	BSP_MAIN_ETH0_IRQ,
 	(rtems_irq_hdl) GT64260eth_isr,
-        NULL,
+        (rtems_irq_hdl_param) NULL,
 	(rtems_irq_enable) GT64260eth_irq_on,
 	(rtems_irq_disable) GT64260eth_irq_off,
@@ -331,7 +325,7 @@
 #endif
 
-  sc->intr_err_ptr1=0;
-  sc->intr_err_ptr2=0;
-  for (i=0; i< INTR_ERR_SIZE; i++) sc->intr_errsts[i]=0;
+  sc->if_err_ptr1=0;
+  sc->if_err_ptr2=0;
+  for (i=0; i< IF_ERR_BUFSZE; i++) sc->if_errsts[i]=0;
 
   /* initialize the hardware (we are holding the network semaphore at this point) */
@@ -339,10 +333,5 @@
 
   /* launch network daemon */
-
-  /* NOTE:
-   * in ss-20011025 (and later) any task created by 'bsdnet_newproc' is
-   * wrapped by code which acquires the network semaphore...
-   */
-   sc->daemonTid = rtems_bsdnet_newproc(GT_ETH_TASK_NAME,4096,GT64260eth_daemon,arg);
+  sc->daemonTid = rtems_bsdnet_newproc(GT_ETH_TASK_NAME,4096,GT64260eth_daemon,arg);
 
   /* Tell the world that we're running */
@@ -365,7 +354,9 @@
   unit = rtems_bsdnet_parse_driver_name(config, &name);
   if (unit < 0) return 0;
- 
-  printk("\nEthernet driver name %s unit %d \n",name, unit);
-  printk("(c) 2004, Brookhaven National Lab. <feng1@bnl.gov> (RTEMS/mvme5500 port)\n");
+  if ( !strncmp((const char *)name,"autoz",5))
+     memcpy(name,"gtMHz",5);
+           
+  printk("\nAttaching GT64260 built-in 10/100 MHz NIC%d\n", unit); 
+  printk("RTEMS-mvme5500 BSP Copyright (c) 2004, Brookhaven National Lab., Shuchen Kate Feng\n");
 
   /* Make certain elements e.g. descriptor lists are aligned. */
@@ -389,19 +380,14 @@
    * by config
    */
-  if (config->hardware_address) {
-     memcpy(hwaddr, config->hardware_address, ETHER_ADDR_LEN);
-  } else {
-    printk("Read EEPROM ");
-     for (i = 0; i < 6; i++)
-       hwaddr[i] = ConfVPD_buff[VPD_ENET0_OFFSET+i];
-  }
+  if (config->hardware_address)
+     memcpy((void *)sc->arpcom.ac_enaddr,(const void *) config->hardware_address, ETHER_ADDR_LEN);
+  else
+    memcpy((void *)sc->arpcom.ac_enaddr, (const void *) &ConfVPD_buff[VPD_ENET0_OFFSET], ETHER_ADDR_LEN);
 
 #ifdef GT_DEBUG
   printk("using MAC addr from device:");
-  for (i = 0; i < ETHER_ADDR_LEN; i++) printk("%x:", hwaddr[i]);
+  for (i = 0; i < ETHER_ADDR_LEN; i++) printk("%x:", sc->arpcom.ac_enaddr[i]);
   printk("\n");
 #endif
-
-  memcpy(sc->arpcom.ac_enaddr, hwaddr, ETHER_ADDR_LEN);
 
   ifp = &sc->arpcom.ac_if;
@@ -411,7 +397,6 @@
   sc->sc_intrmask = inl(ETH0_EIMR) | ETH_IR_MIIPhySTC;
 
+#ifdef GT_DEBUG
   printk("address %s\n", ether_sprintf(hwaddr));
-
-#ifdef GT_DEBUG
   printk(", pcr %x, pcxr %x ", sc->sc_pcr, sc->sc_pcxr);
 #endif
@@ -512,5 +497,4 @@
   struct ifnet *ifp = &sc->arpcom.ac_if;
 
-#if 0
   printf("       Rx Interrupts:%-8lu\n", sc->stats.rxInterrupts);
   printf("     Receive Packets:%-8lu\n", ifp->if_ipackets);
@@ -521,16 +505,8 @@
   printf("         Active Rxqs:%-8u\n",  sc->rxq_active); 
   printf("       Tx Interrupts:%-8lu\n", sc->stats.txInterrupts);
-#endif
-  printf("Multi-BuffTx Packets:%-8lu\n", sc->stats.txMultiBuffPacket);
-  printf("Multi-BuffTx max len:%-8lu\n", sc->stats.txMultiMaxLen);
-  printf("SingleBuffTx max len:%-8lu\n", sc->stats.txSinglMaxLen);
-  printf("Multi-BuffTx maxloop:%-8lu\n", sc->stats.txMultiMaxLoop);
-  printf("Tx buffer max len   :%-8lu\n", sc->stats.txBuffMaxLen);
-#if 0
   printf("   Transmitt Packets:%-8lu\n", ifp->if_opackets);
   printf("   Transmitt  errors:%-8lu\n", ifp->if_oerrors);
   printf("    Tx/Rx collisions:%-8lu\n", ifp->if_collisions);
   printf("         Active Txqs:%-8u\n", sc->txq_nactive); 
-#endif
 }
 
@@ -540,5 +516,5 @@
 }
 
-static int GTeth_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+static int GTeth_ifioctl(struct ifnet *ifp, ioctl_command_t cmd, caddr_t data)
 {
   struct GTeth_softc *sc = ifp->if_softc;
@@ -586,5 +562,5 @@
 	   if (ifp->if_flags & IFF_RUNNING)
 	      GTeth_ifchange(sc);
-	   else
+           else
 	      error = 0;
        }
@@ -863,4 +839,5 @@
 }
 
+#if 0
 static int txq_high_limit(struct GTeth_softc *sc)
 {
@@ -902,4 +879,5 @@
   return 0;
 }
+#endif
 
 static int GT64260eth_sendpacket(struct GTeth_softc *sc,struct mbuf *m)
@@ -917,8 +895,6 @@
   intrmask = sc->sc_intrmask;
 
-  if ( !(m->m_next)) {/* single buffer packet */
+  if ( !(m->m_next)) /* single buffer packet */
     sc->txq_mbuf[index]= m;
-    sc->stats.txSinglMaxLen= MAX(m->m_len, sc->stats.txSinglMaxLen);
-  }
   else /* multiple mbufs in this packet */
   { 
@@ -948,7 +924,5 @@
 #endif
       len += mtp->m_len;
-      sc->stats.txBuffMaxLen=MAX(mtp->m_len,sc->stats.txBuffMaxLen); 
     }
-    sc->stats.txMultiMaxLoop=MAX(loop, sc->stats.txMultiMaxLoop);
 #if 0
     printk("\n");
@@ -958,6 +932,4 @@
     m_freem(m);
     sc->txq_mbuf[index] = m = mdest;
-    sc->stats.txMultiBuffPacket++;
-    sc->stats.txMultiMaxLen= MAX(m->m_len, sc->stats.txMultiMaxLen);
   }
   if (m->m_len < ET_MINLEN) m->m_len = ET_MINLEN;
@@ -1138,10 +1110,8 @@
 }
 
-/* TOCHECK : Should it be about rx or tx ? */
 static void GTeth_ifchange(struct GTeth_softc *sc)
 {
   if (GTeth_debug>0) printk("GTeth_ifchange(");
   if (GTeth_debug>5) printk("(pcr=%#x,imr=%#x)",inl(ETH0_EPCR),inl(ETH0_EIMR));
-  /*  printk("SIOCADDMULTI (SIOCDELMULTI): is it about rx or tx ?\n");*/
   outl(sc->sc_pcr | ETH_EPCR_EN, ETH0_EPCR);
   outl(sc->sc_intrmask, ETH0_EIMR);
@@ -1446,8 +1416,9 @@
 }
 
+#ifdef GT64260eth_DEBUG
 static void GT64260eth_error(struct GTeth_softc *sc)
 {
   struct ifnet	        *ifp = &sc->arpcom.ac_if;
-  unsigned int		intr_status= sc->intr_errsts[sc->intr_err_ptr1];
+  unsigned int		intr_status= sc->if_errsts[sc->if_err_ptr1];
 
   /* read and reset the status; because this is written
@@ -1472,8 +1443,8 @@
     printk("%s%d: Ghost interrupt ?\n",ifp->if_name,
 	   ifp->if_unit);
-  sc->intr_errsts[sc->intr_err_ptr1++]=0;  
-  sc->intr_err_ptr1 %= INTR_ERR_SIZE;   /* Till Straumann */
-}
-
+  sc->if_errsts[sc->if_err_ptr1]=0;  
+  if ( (++sc->if_err_ptr1) == IF_ERR_BUFSZE) sc->if_err_ptr1=0; /* Till Straumann */
+}
+#endif
 
 /* The daemon does all of the work; RX, TX and cleaning up buffers/descriptors */
@@ -1484,11 +1455,4 @@
   struct mbuf	*m=0;
   struct ifnet	*ifp=&sc->arpcom.ac_if;
-
-#if 0	
-  /* see comments in GT64260eth_init(); in newer versions of
-   * rtems, we hold the network semaphore at this point
-   */
-  rtems_semaphore_release(sc->daemonSync);
-#endif
 
   /* NOTE: our creator possibly holds the bsdnet_semaphore.
@@ -1549,5 +1513,7 @@
 
        /* Log errors and other uncommon events. */
-       if (events & ERR_EVENT) GT64260eth_error(sc); 
+#ifdef GT64260eth_DEBUG
+	  if (events & ERR_EVENT) GT64260eth_error(sc); 
+#endif
   } /* end for(;;) { rtems_bsdnet_event_receive() .....*/
 
Index: c/src/lib/libbsp/powerpc/mvme5500/network/if_100MHz/GT64260eth.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/network/if_100MHz/GT64260eth.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/network/if_100MHz/GT64260eth.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -5,4 +5,5 @@
  * 
  * RTEMS/Mvme5500 port 2004  by S. Kate Feng, <feng1@bnl.gov>,
+ * under the Deaprtment of Energy contract DE-AC02-98CH10886
  * All rights reserved.
  *
@@ -51,5 +52,5 @@
 #define HASH_TABLE_SIZE 16
 #define HASH_DRAM_SIZE  HASH_TABLE_SIZE*1024  /* size of DRAM for hash table */
-#define INTR_ERR_SIZE   16
+#define IF_ERR_BUFSZE   16
 		
 enum GTeth_txprio {
@@ -71,7 +72,7 @@
   struct mbuf* rxq_mbuf[RX_RING_SIZE];	/* receive buffer memory */
   struct GTeth_softc *next_module;
-  volatile unsigned int intr_errsts[INTR_ERR_SIZE]; /* capture the right intr_status */
-  unsigned int intr_err_ptr1;   /* ptr used in GTeth_error() */
-  unsigned int intr_err_ptr2;   /* ptr used in ISR */
+  volatile unsigned int if_errsts[IF_ERR_BUFSZE]; /* capture the right intr_status */
+  unsigned int if_err_ptr1;   /* ptr used in GTeth_error() */
+  unsigned int if_err_ptr2;   /* ptr used in ISR */
   struct ifqueue txq_pendq;	/* these are ready to go to the GT */
   unsigned int txq_pending;
@@ -126,11 +127,5 @@
   struct {
     volatile unsigned long       rxInterrupts;
-
     volatile unsigned long       txInterrupts;
-    unsigned long	txMultiBuffPacket;
-    unsigned long       txMultiMaxLen;
-    unsigned long       txSinglMaxLen;
-    unsigned long       txMultiMaxLoop;
-    unsigned long       txBuffMaxLen;
     unsigned long 	length_errors;
     unsigned long	frame_errors;
Index: c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/if_wm.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/if_wm.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/if_wm.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,4 +1,5 @@
 /*
- * Copyright (c) 2004,2005 RTEMS/Mvme5500 port by S. Kate Feng <feng1@bnl.gov>
+ * Copyright (c) 2004,2005, 2008 RTEMS/Mvme5500 port by S. Kate Feng <feng1@bnl.gov>
+ *      under the Deaprtment of Energy contract DE-AC02-98CH10886
  *      Brookhaven National Laboratory, All rights reserved
  *
@@ -26,6 +27,5 @@
  *    to WB region", MII mode (PHY) instead of TBI mode.
  * 6) We currently only use 32-bit (instead of 64-bit) DMA addressing.
- * 7) Support for checksum offloading and TCP segmentation offload will
- *    be available for releasing in 2008, upon request, if I still believe.
+ * 7) Implementation for Jumbo Frame and TCP checksum is not yet completed.
  *    
  */
@@ -34,7 +34,10 @@
 
 #define INET
+
+/*#define RTEMS_ETHERMTU_JUMBO*/
 
 #include <rtems.h>
 #include <rtems/bspIo.h>      /* printk */
+
 #include <stdio.h>	      /* printf for statistics */
 #include <string.h>
@@ -65,4 +68,5 @@
 #include <netinet/in.h>
 #include <netinet/if_ether.h>
+#include <net/ethernet.h>
 
 #ifdef INET
@@ -83,5 +87,5 @@
 #define SOFTC_ALIGN        4095
 
-#define INTR_ERR_SIZE        16
+#define IF_ERR_BUFSZE        16
 
 /*#define WM_DEBUG*/
@@ -110,10 +114,10 @@
 #define ALL_EVENTS (KILL_EVENT|START_TRANSMIT_EVENT|RX_EVENT|TX_EVENT|ERR_EVENT|INIT_EVENT)
 
-
-#define	NTXDESC		        128
+/* <skf> used 64 in 4.8.0, TOD; try 4096 */
+#define	NTXDESC		        256
 #define	NTXDESC_MASK		(NTXDESC - 1)
 #define	WM_NEXTTX(x)		(((x) + 1) & NTXDESC_MASK)
 
-#define	NRXDESC		        64
+#define	NRXDESC		        256
 #define	NRXDESC_MASK		(NRXDESC - 1)
 #define	WM_NEXTRX(x)		(((x) + 1) & NRXDESC_MASK)
@@ -124,7 +128,8 @@
 #define	WM_CDRXOFF(x)	WM_CDOFF(sc_rxdescs[(x)])
 
-#define TXQ_HiLmt_OFF 64
+#define TXQ_HiLmt_OFF 32
 
 static uint32_t TxDescCmd;
+static unsigned BSP_1GHz_membase;
 
 /*
@@ -137,7 +142,7 @@
 	struct mbuf *rxs_mbuf[NRXDESC];	       /* receive buffer memory */
         struct wm_softc *next_module;
-        volatile unsigned int intr_errsts[INTR_ERR_SIZE]; /* intr_status */
-        unsigned int intr_err_ptr1;     /* ptr used in i82544EI_error() */
-        unsigned int intr_err_ptr2;     /* ptr used in ISR */
+        volatile unsigned int if_errsts[IF_ERR_BUFSZE]; /* intr_status */
+        unsigned int if_err_ptr1;     /* ptr used in i82544EI_error() */
+        unsigned int if_err_ptr2;     /* ptr used in ISR */
 	int txs_firstdesc;		/* first descriptor in packet */
 	int txs_lastdesc;		/* last descriptor in packet */
@@ -169,8 +174,8 @@
 	int	sc_rxdiscard;
 	int	sc_rxlen;
+
 	uint32_t sc_ctrl;		/* prototype CTRL register */
-#if 0
 	uint32_t sc_ctrl_ext;		/* prototype CTRL_EXT register */
-#endif
+
 	uint32_t sc_icr;		/* prototype interrupt bits */
 	uint32_t sc_tctl;		/* prototype TCTL register */
@@ -178,4 +183,5 @@
 	uint32_t sc_tipg;		/* prototype TIPG register */
 	uint32_t sc_fcrtl;		/* prototype FCRTL register */
+	uint32_t sc_pba;		/* prototype PBA register */
 
 	int sc_mchash_type;		/* multicast filter offset */
@@ -185,9 +191,4 @@
           volatile unsigned long     rxInterrupts;
           volatile unsigned long     txInterrupts;
-          unsigned long	    txMultiBuffPacket;
-          unsigned long     txMultiMaxLen;
-          unsigned long     txSinglMaxLen;
-          unsigned long     txMultiMaxLoop;
-          unsigned long     txBuffMaxLen;
 	  unsigned long     linkInterrupts;
           unsigned long     length_errors;
@@ -225,7 +226,8 @@
 
 static void i82544EI_ifstart(struct ifnet *ifp);
-static int  wm_ioctl(struct ifnet *ifp, u_long cmd,uint32_t data);
+static int  wm_ioctl(struct ifnet *ifp, ioctl_command_t cmd,caddr_t data);
 static void i82544EI_ifinit(void *arg);
 static void wm_stop(struct ifnet *ifp, int disable);
+static void wm_gmii_mediainit(struct wm_softc *sc);
 
 static void wm_rxdrain(struct wm_softc *sc);
@@ -234,9 +236,8 @@
 static void i82544EI_daemon(void *arg);
 static void wm_set_filter(struct wm_softc *sc);
-
-static void i82544EI_isr();
+static void i82544EI_rx(struct wm_softc *sc);
+static void i82544EI_isr(rtems_irq_hdl_param handle);
 static void i82544EI_sendpacket(struct wm_softc *sc, struct mbuf *m);
 extern int  pci_mem_find(), pci_io_find(), pci_get_capability();
-extern char * ether_sprintf1();
 
 static void i82544EI_irq_on(const rtems_irq_connect_data *irq)
@@ -270,4 +271,5 @@
 	BSP_GPP_82544_IRQ,
 	(rtems_irq_hdl) i82544EI_isr,
+        (rtems_irq_hdl_param) NULL,
 	(rtems_irq_enable) i82544EI_irq_on,
 	(rtems_irq_disable) i82544EI_irq_off,
@@ -289,7 +291,10 @@
   unit = rtems_bsdnet_parse_driver_name(config, &name);
   if (unit < 0) return 0;
- 
-  printk("\nEthernet driver name %s unit %d \n",name, unit);
-  printk("Copyright (c) 2004,2005 S. Kate Feng <feng1@bnl.gov> (RTEMS/mvme5500 port)\n");
+
+  if ( !strncmp((const char *)name,"autoz",5))
+     memcpy(name,"gtGHz",5);
+          
+  printk("\nAttaching MVME5500 1GHz NIC%d\n", unit); 
+  printk("RTEMS-mvme5500 BSP Copyright (c) 2004,2005,2008 Shuchen Kate Feng \n");
 
   /* Make sure certain elements e.g. descriptor lists are aligned.*/ 
@@ -317,4 +322,7 @@
      rtems_panic("i82544EI: unable to map memory space\n");
 
+  printk("Memory base addr 0x%x\n", sc->sc_membase);
+  BSP_1GHz_membase= sc->sc_membase;
+
 #ifdef WM_DEBUG
   printk("Memory base addr 0x%x\n", sc->sc_membase);
@@ -323,5 +331,5 @@
 
 
-  sc->sc_ctrl |=CSR_READ(sc,WMREG_CTRL);  
+  sc->sc_ctrl=CSR_READ(sc,WMREG_CTRL);  
   /*
    * Determine a few things about the bus we're connected to.
@@ -361,9 +369,8 @@
   enaddr[5] = myea[2] >> 8;
 
-
   memcpy(sc->arpcom.ac_enaddr, enaddr, ETHER_ADDR_LEN);
 #ifdef WM_DEBUG
   printk("%s: Ethernet address %s\n", sc->dv_xname,
-	    ether_sprintf1(enaddr));
+	    ether_sprintf(enaddr));
 #endif
 
@@ -395,4 +402,15 @@
   CSR_WRITE(sc,WMREG_CTRL_EXT, sc->sc_ctrl_ext);
 #endif
+
+  /*
+   * Determine if we're TBI or GMII mode, and initialize the
+   * media structures accordingly.
+   */
+  if ((CSR_READ(sc, WMREG_STATUS) & STATUS_TBIMODE) != 0) {
+    /* 1000BASE-X : fiber  (TBI mode) 
+       wm_tbi_mediainit(sc); */
+  } else {   /* 1000BASE-T : copper (internal PHY mode), for the mvme5500 */
+	   wm_gmii_mediainit(sc);
+  }  
 
   ifp = &sc->arpcom.ac_if;
@@ -402,5 +420,20 @@
   ifp->if_softc = sc;
   ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+#ifdef RTEMS_ETHERMTU_JUMBO 
+  sc->arpcom.ec_capabilities |= ETHERCAP_JUMBO_MTU;
+  ifp->if_mtu = config->mtu ? config->mtu : ETHERMTU_JUMBO;
+#else
   ifp->if_mtu = config->mtu ? config->mtu : ETHERMTU;
+#endif
+#ifdef RTEMS_CKSUM_OFFLOAD 
+  /* < skf> The following is really not related to jumbo frame
+  sc->arpcom.ec_capabilities |= ETHERCAP_VLAN_MTU;*/
+  ifp->if_capabilities |= IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx |
+		    IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
+		    IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx |
+		    IFCAP_CSUM_TCPv6_Tx | IFCAP_CSUM_UDPv6_Tx |
+                    IFCAP_TSOv4;  /* TCP segmentation offload. */
+#endif
+
   ifp->if_ioctl = wm_ioctl;
   ifp->if_start = i82544EI_ifstart;
@@ -417,5 +450,6 @@
      rtems_panic("i82544EI: semaphore creation failed");
 
-  sc->next_module = root_i82544EI_dev;
+  i82544IrqData.handle= (rtems_irq_hdl_param) sc;
+  /* sc->next_module = root_i82544EI_dev;*/
   root_i82544EI_dev = sc;
 
@@ -431,4 +465,37 @@
 
 /*
+ * wm_reset:
+ *
+ *	Reset the i82544 chip.
+ */
+static void wm_reset(struct wm_softc *sc)
+{
+  int i;
+
+  sc->sc_pba = sc->arpcom.ac_if.if_mtu > 8192 ? PBA_40K : PBA_48K;
+  CSR_WRITE(sc, WMREG_PBA, sc->sc_pba);
+
+  /* device reset */
+  CSR_WRITE(sc, WMREG_CTRL, CTRL_RST);
+  rtems_bsp_delay(10000);
+
+  for (i = 0; i < 1000; i++) {
+      if ((CSR_READ(sc, WMREG_CTRL) & CTRL_RST) == 0)
+	break;
+      rtems_bsp_delay(20);
+  }
+  if (CSR_READ(sc, WMREG_CTRL) & CTRL_RST)
+      printk("Intel 82544 1GHz reset failed to complete\n");
+
+  sc->sc_ctrl_ext = CSR_READ(sc,WMREG_CTRL_EXT);
+  sc->sc_ctrl_ext |= CTRL_EXT_EE_RST;
+  CSR_WRITE(sc, WMREG_CTRL_EXT, sc->sc_ctrl_ext);  
+  CSR_READ(sc, WMREG_STATUS);
+  /* Wait for EEPROM reload */
+  rtems_bsp_delay(2000);
+  sc->sc_ctrl= CSR_READ(sc, WMREG_CTRL);
+}
+
+/*
  * i82544EI_ifstart:		[ifnet interface function]
  *
@@ -462,25 +529,19 @@
   struct ifnet *ifp = &sc->arpcom.ac_if;
 
-  printf("       Rx Interrupts:%-8u\n", sc->stats.rxInterrupts);
+  printf("    Ghost Interrupts:%-8lu\n", sc->stats.ghostInterrupts);
+  printf("       Rx Interrupts:%-8lu\n", sc->stats.rxInterrupts);
   printf("     Receive Packets:%-8u\n", CSR_READ(sc,WMREG_GPRC));
-  printf("     Receive Overrun:%-8u\n", sc->stats.rxOvrRunInterrupts);
+  printf("     Receive Overrun:%-8lu\n", sc->stats.rxOvrRunInterrupts);
   printf("     Receive  errors:%-8u\n", CSR_READ(sc,WMREG_RXERRC));
-  printf("   Rx sequence error:%-8u\n", sc->stats.rxSeqErr);
-  printf("      Rx /C/ ordered:%-8u\n", sc->stats.rxC_ordered);
+  printf("   Rx sequence error:%-8lu\n", sc->stats.rxSeqErr);
+  printf("      Rx /C/ ordered:%-8lu\n", sc->stats.rxC_ordered);
   printf("    Rx Length Errors:%-8u\n", CSR_READ(sc,WMREG_RLEC));
-  printf("       Tx Interrupts:%-8u\n", sc->stats.txInterrupts);
-#if 0
-  printf("Multi-BuffTx Packets:%-8u\n", sc->stats.txMultiBuffPacket);
-  printf("Multi-BuffTx max len:%-8u\n", sc->stats.txMultiMaxLen);
-  printf("SingleBuffTx max len:%-8u\n", sc->stats.txSinglMaxLen);
-  printf("Multi-BuffTx maxloop:%-8u\n", sc->stats.txMultiMaxLoop);
-  printf("Tx buffer max len   :%-8u\n", sc->stats.txBuffMaxLen);
-#endif
+  printf("       Tx Interrupts:%-8lu\n", sc->stats.txInterrupts);
   printf("   Transmitt Packets:%-8u\n", CSR_READ(sc,WMREG_GPTC));
-  printf("   Transmitt  errors:%-8u\n", ifp->if_oerrors);
-  printf("         Active Txqs:%-8u\n", sc->txq_nactive); 
+  printf("   Transmitt  errors:%-8lu\n", ifp->if_oerrors);
+  printf("         Active Txqs:%-8lu\n", sc->txq_nactive); 
   printf("          collisions:%-8u\n", CSR_READ(sc,WMREG_COLC));
   printf("          Crc Errors:%-8u\n", CSR_READ(sc,WMREG_CRCERRS));
-  printf("  Link Status Change:%-8u\n", sc->stats.linkStatusChng);
+  printf("  Link Status Change:%-8lu\n", sc->stats.linkStatusChng);
 }
 
@@ -490,5 +551,5 @@
  *	Handle control requests from the operator.
  */
-static int wm_ioctl(struct ifnet *ifp, u_long cmd,uint32_t data)
+static int wm_ioctl(struct ifnet *ifp, ioctl_command_t cmd,caddr_t data)
 {
   struct wm_softc *sc = ifp->if_softc;
@@ -522,7 +583,7 @@
  *	Interrupt service routine.
  */
-static void i82544EI_isr()
-{
-  volatile struct wm_softc *sc = root_i82544EI_dev;
+static void i82544EI_isr(rtems_irq_hdl_param handle)
+{
+  volatile struct wm_softc *sc = (struct wm_softc *) handle;
   uint32_t icr;
   rtems_event_set  events=0;
@@ -548,6 +609,6 @@
   }
   if (icr & ICR_RXSEQ) /* framing error */ {
-     sc->intr_errsts[sc->intr_err_ptr2++]=icr;
-     sc->intr_err_ptr2 %=INTR_ERR_SIZE; /* Till Straumann */
+     sc->if_errsts[sc->if_err_ptr2]=icr;
+     if ((++sc->if_err_ptr2)==IF_ERR_BUFSZE) sc->if_err_ptr2=0;/* Till Straumann */
      events |= ERR_EVENT;
      sc->stats.rxSeqErr++;
@@ -607,5 +668,5 @@
          */
         if ( ((y=(len+mtp->m_len)) > sizeof(union mcluster))) {
-          printk(">2048, use next descriptor\n");
+          printk(" >%d, use next descriptor\n", sizeof(union mcluster));
 	  break; 
         }
@@ -613,7 +674,4 @@
         pt += mtp->m_len;
         len += mtp->m_len;
-#if 0
-        sc->stats.txSinglMaxLen= MAX(mtp->m_len, sc->stats.txSinglMaxLen);
-#endif
       } /* end for loop */
       mdest->m_len=len;
@@ -629,13 +687,6 @@
       else
          rtems_panic("i8254EI : no more free descriptors");
-#if 0
-      sc->stats.txMultiMaxLen= MAX(mdest->m_len, sc->stats.txMultiMaxLen);
-      sc->stats.txMultiBuffPacket++;
-#endif
     } /* end for while */
     /* free old mbuf chain */
-#if 0
-    sc->stats.txMultiMaxLoop=MAX(loop, sc->stats.txMultiMaxLoop);
-#endif
     m_freem(m); 
     m=0;
@@ -743,10 +794,9 @@
 
     status = sc->sc_rxdescs[i].wrx_status;
+    if ((status & WRX_ST_DD) == 0)  break; /* descriptor not done */
+
     errors = sc->sc_rxdescs[i].wrx_errors;
     len = le16toh(sc->sc_rxdescs[i].wrx_len);
     m = sc->rxs_mbuf[i];
-
-    if ((status & WRX_ST_DD) == 0)  break; /* descriptor not done */
-
     if (sc->sc_rxdiscard) {
        printk("RX: discarding contents of descriptor %d\n", i);
@@ -820,14 +870,44 @@
   uint8_t cksumfields;
 
+#if 0
+  /* KATETODO : sc_align_tweak */
+	/*
+	 * *_HDR_ALIGNED_P is constant 1 if __NO_STRICT_ALIGMENT is set.
+	 * There is a small but measurable benefit to avoiding the adjusment
+	 * of the descriptor so that the headers are aligned, for normal mtu,
+	 * on such platforms.  One possibility is that the DMA itself is
+	 * slightly more efficient if the front of the entire packet (instead
+	 * of the front of the headers) is aligned.
+	 *
+	 * Note we must always set align_tweak to 0 if we are using
+	 * jumbo frames.
+	 */
+#ifdef __NO_STRICT_ALIGNMENT
+	sc->sc_align_tweak = 0;
+#else
+	if ((ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN) > (MCLBYTES - 2))
+		sc->sc_align_tweak = 0;
+	else
+		sc->sc_align_tweak = 2;
+#endif /* __NO_STRICT_ALIGNMENT */
+#endif
+
   /* Cancel any pending I/O. */
   wm_stop(ifp, 0);
 
+  /* update statistics before reset */
+  ifp->if_collisions += CSR_READ(sc, WMREG_COLC);
+  ifp->if_ierrors += CSR_READ(sc, WMREG_RXERRC);
+
+  /* Reset the chip to a known state. */
+  wm_reset(sc);
+
   /* Initialize the error buffer ring */
-  sc->intr_err_ptr1=0;
-  sc->intr_err_ptr2=0;
-  for (i=0; i< INTR_ERR_SIZE; i++) sc->intr_errsts[i]=0;
+  sc->if_err_ptr1=0;
+  sc->if_err_ptr2=0;
+  for (i=0; i< IF_ERR_BUFSZE; i++) sc->if_errsts[i]=0;
 
   /* Initialize the transmit descriptor ring. */
-  memset(sc->sc_txdescs, 0, sizeof(sc->sc_txdescs));
+  memset( (void *) sc->sc_txdescs, 0, sizeof(sc->sc_txdescs));
   sc->txq_free = NTXDESC;
   sc->txq_next = 0;
@@ -848,6 +928,6 @@
   CSR_WRITE(sc,WMREG_TDH, 0);
   CSR_WRITE(sc,WMREG_TDT, 0);
-  CSR_WRITE(sc,WMREG_TIDV, 64 ); 
-  CSR_WRITE(sc,WMREG_TADV, 128);
+  CSR_WRITE(sc,WMREG_TIDV, 0 ); 
+  /* CSR_WRITE(sc,WMREG_TADV, 128);  not for 82544 */
 
   CSR_WRITE(sc,WMREG_TXDCTL, TXDCTL_PTHRESH(0) |
@@ -863,8 +943,9 @@
    * this packet.
    */
-#ifdef CKSUM_OFFLOAD
-  if (m0->m_pkthdr.csum_flags &
-     (M_CSUM_IPv4|M_CSUM_TCPv4|M_CSUM_UDPv4)) {
-     if (wm_tx_cksum(sc, txs, &TxDescCmd,&cksumfields) != 0) {
+#ifdef RTEMS_CKSUM_OFFLOAD
+  if (m0->m_pkthdr.csum_flags & (M_CSUM_TSOv4|M_CSUM_TSOv6|
+		    M_CSUM_IPv4|M_CSUM_TCPv4|M_CSUM_UDPv4|
+				 M_CSUM_TCPv6|M_CSUM_UDPv6)) {
+     if (wm_tx_offload(sc, txs, &TxDescCmd,&cksumfields) != 0) {
 	 /* Error message already displayed. */
 	 continue;
@@ -874,5 +955,5 @@
      TxDescCmd = 0;
      cksumfields = 0;
-#ifdef CKSUM_OFFLOAD
+#ifdef RTEMS_CKSUM_OFFLOAD
   }
 #endif
@@ -893,5 +974,5 @@
    * descriptor rings.
    */
-  memset(sc->sc_rxdescs, 0, sizeof(sc->sc_rxdescs));
+  memset( (void *) sc->sc_rxdescs, 0, sizeof(sc->sc_rxdescs));
   CSR_WRITE(sc,WMREG_RDBAH, 0);
   CSR_WRITE(sc,WMREG_RDBAL, WM_CDRXADDR(sc));
@@ -900,5 +981,5 @@
   CSR_WRITE(sc,WMREG_RDT, 0);
   CSR_WRITE(sc,WMREG_RDTR, 0 |RDTR_FPD); 
-  CSR_WRITE(sc, WMREG_RADV, 256);
+  /* CSR_WRITE(sc, WMREG_RADV, 256);  not for 82544.  */
 
   for (i = 0; i < NRXDESC; i++) {
@@ -944,10 +1025,11 @@
   CSR_WRITE(sc,WMREG_FCRTH, FCRTH_DFLT);
   CSR_WRITE(sc,WMREG_FCRTL, sc->sc_fcrtl);
-  CSR_WRITE(sc,WMREG_FCTTV, FCTTV_DFLT);
+  /*KATETO   CSR_WRITE(sc,WMREG_FCTTV, FCTTV_DFLT);*/
+  CSR_WRITE(sc,WMREG_FCTTV, 0x100);
 
   sc->sc_ctrl &= ~CTRL_VME;
-  /*sc->sc_ctrl |= CTRL_TFCE | CTRL_RFCE;*/
-  /* enable Big Endian Mode for the powerPC 
-  sc->sc_ctrl |= CTRL_BEM;*/
+  /* KATETODo : not here.
+     Configures flow control settings after link is established
+     sc->sc_ctrl |= CTRL_TFCE | CTRL_RFCE; */
 
   /* Write the control registers. */
@@ -957,5 +1039,19 @@
 #endif
 
-  /* MOTLoad : WMREG_RXCSUM (0x5000)= 0, no Rx checksum offloading */  
+  /* MOTLoad : WMREG_RXCSUM (0x5000)= 0, no Rx checksum offloading */ 
+#ifdef RTEMS_CKSUM_OFFLOAD
+  /*
+   * Set up checksum offload parameters.
+   */
+   reg = CSR_READ(sc, WMREG_RXCSUM);
+   reg &= ~(RXCSUM_IPOFL | RXCSUM_IPV6OFL | RXCSUM_TUOFL);
+   if (ifp->if_capenable & IFCAP_CSUM_IPv4_Rx)
+	    reg |= RXCSUM_IPOFL;
+   if (ifp->if_capenable & (IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_UDPv4_Rx))
+	    reg |= RXCSUM_IPOFL | RXCSUM_TUOFL;
+   if (ifp->if_capenable & (IFCAP_CSUM_TCPv6_Rx | IFCAP_CSUM_UDPv6_Rx))
+	    reg |= RXCSUM_IPV6OFL | RXCSUM_TUOFL;
+   CSR_WRITE(sc, WMREG_RXCSUM, reg);
+#endif
 
   /*
@@ -986,5 +1082,6 @@
    */
   sc->sc_tctl = TCTL_EN | TCTL_PSP | TCTL_CT(TX_COLLISION_THRESHOLD) |
-	    TCTL_COLD(TX_COLLISION_DISTANCE_FDX) | TCTL_RTLC; /*transmitter enable*/
+	    TCTL_COLD(TX_COLLISION_DISTANCE_FDX) |
+            TCTL_RTLC /* transmit on late collision */; 
 
   /*
@@ -994,12 +1091,29 @@
    *
    * Only the i82544 has the ability to strip the incoming
-   * CRC, so we don't enable that feature. (TODO)
+   * CRC, so we don't enable that feature. (TODO: |RCTL_SECRC)
    */
   sc->sc_mchash_type = 0;
   sc->sc_rctl = RCTL_EN | RCTL_LBM_NONE | RCTL_RDMTS_1_2 | RCTL_LPE |
-	    RCTL_DPF | RCTL_MO(sc->sc_mchash_type);
-
-  /* (MCLBYTES == 2048) */
-  sc->sc_rctl |= RCTL_2k;
+    RCTL_DPF | RCTL_MO(sc->sc_mchash_type)|RCTL_SECRC;
+
+  if (MCLBYTES == 2048) {
+     sc->sc_rctl |= RCTL_2k;
+  } else {
+	switch(MCLBYTES) {
+	case 4096:
+	     sc->sc_rctl |= RCTL_BSEX | RCTL_BSEX_4k;
+	     break;
+	case 8192:
+	     sc->sc_rctl |= RCTL_BSEX | RCTL_BSEX_8k;
+	     break;
+        case 16384:
+	     sc->sc_rctl |= RCTL_BSEX | RCTL_BSEX_16k;
+	     break;
+	default:
+	     rtems_panic("wm_init: MCLBYTES %d unsupported",
+		    MCLBYTES);
+	     break;
+	}
+  }
 
 #ifdef WM_DEBUG
@@ -1019,4 +1133,22 @@
 }
 
+void BSP_rdTIDV()
+{
+  printf("Reg TIDV: 0x%x\n", in_le32((volatile unsigned *) (BSP_1GHz_membase+WMREG_TIDV)));
+}
+void BSP_rdRDTR()
+{
+  printf("Reg RDTR: 0x%x\n", in_le32((volatile unsigned *) (BSP_1GHz_membase+WMREG_RDTR)));
+}
+
+void BSP_setTIDV(int val)
+{
+  out_le32((volatile unsigned *) (BSP_1GHz_membase+WMREG_TIDV), val);
+}
+
+void BSP_setRDTR(int val)
+{
+  out_le32((volatile unsigned *) (BSP_1GHz_membase+WMREG_RDTR), val);
+}
 /*
  * i82544EI_ifinit:		[ifnet interface function]
@@ -1234,4 +1366,5 @@
 }
 
+#if 0
 /*
  * wm_acquire_eeprom:
@@ -1265,4 +1398,5 @@
   return (0);
 }
+#endif
 
 /*
@@ -1369,5 +1503,5 @@
   sc->sc_rctl &= ~(RCTL_BAM | RCTL_UPE | RCTL_MPE);
 
-  /*  if (ifp->if_flags & IFF_BROADCAST)*/
+  if (ifp->if_flags & IFF_BROADCAST)
      sc->sc_rctl |= RCTL_BAM;
   if (ifp->if_flags & IFF_PROMISC) {
@@ -1439,10 +1573,9 @@
 {
   struct ifnet	        *ifp = &sc->arpcom.ac_if;
-  unsigned long		intr_status= sc->intr_errsts[sc->intr_err_ptr1++];
+  unsigned long		intr_status= sc->if_errsts[sc->if_err_ptr1];
 
   /* read and reset the status; because this is written
    * by the ISR, we must disable interrupts here
    */
-  sc->intr_err_ptr1 %=INTR_ERR_SIZE; /* Till Straumann */
   if (intr_status) {
     printk("Error %s%d:", ifp->if_name, ifp->if_unit);
@@ -1454,4 +1587,6 @@
   else 
     printk("%s%d: Ghost interrupt ?\n",ifp->if_name,ifp->if_unit);
+  sc->if_errsts[sc->if_err_ptr1]=0;  
+  if ( (++sc->if_err_ptr1) == IF_ERR_BUFSZE) sc->if_err_ptr1=0; /* Till Straumann */
 }
 
@@ -1494,5 +1629,5 @@
      if (KILL_EVENT & events)  break;
 
-     if (events & RX_EVENT)  i82544EI_rx(sc);
+     if (events & RX_EVENT)  i82544EI_rx(sc); /* in ISR instead */
 
      /* clean up and try sending packets */
@@ -1502,4 +1637,5 @@
         while (sc->txq_free>0) {
            if (sc->txq_free>TXQ_HiLmt_OFF) {
+	      m=0;
 	      IF_DEQUEUE(&ifp->if_snd,m);
               if (m==0) break;
@@ -1510,5 +1646,4 @@
 	      break;
            }
-           if (events & RX_EVENT)  i82544EI_rx(sc);
         }
          /* we leave this loop
@@ -1518,5 +1653,5 @@
 	  *    returned 0
 	  */
-     } while (m && sc->txq_free);
+     } while (m);
 
      ifp->if_flags &= ~IFF_OACTIVE;
@@ -1555,2 +1690,64 @@
   rtems_task_delete(RTEMS_SELF);
 }
+
+/*
+ * wm_gmii_reset:
+ *
+ *	Reset the PHY.
+ */
+static void wm_gmii_reset(struct wm_softc *sc)
+{
+
+  CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl | CTRL_PHY_RESET);
+  rtems_bsp_delay(20000);
+
+  CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
+  rtems_bsp_delay(20000);
+
+}
+
+/*
+ * wm_gmii_mediainit:
+ *
+ *	Initialize media for use on 1000BASE-T devices.
+ */
+static void wm_gmii_mediainit(struct wm_softc *sc)
+{
+  /*  struct ifnet *ifp = &sc->arpcom.ac_if;*/
+
+  /* We have MII. */
+  sc->sc_flags |= WM_F_HAS_MII;
+
+  sc->sc_tipg = TIPG_1000T_DFLT; /* 0x602008 */
+
+  /*
+   * Let the chip set speed/duplex on its own based on
+   * signals from the PHY.
+   * XXXbouyer - I'm not sure this is right for the 80003,
+   * the em driver only sets CTRL_SLU here - but it seems to work.
+   */
+  sc->sc_ctrl |= CTRL_SLU;
+  CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
+
+  wm_gmii_reset(sc);
+
+#if 0
+  /* Initialize our media structures and probe the GMII. */
+  sc->sc_mii.mii_ifp = ifp;
+
+  sc->sc_mii.mii_readreg = wm_gmii_i82544_readreg;
+  sc->sc_mii.mii_writereg = wm_gmii_i82544_writereg;
+  sc->sc_mii.mii_statchg = wm_gmii_statchg;
+
+  ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, wm_gmii_mediachange,
+	    wm_gmii_mediastatus);
+
+  mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
+	    MII_OFFSET_ANY, MIIF_DOPAUSE);
+  if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
+     ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
+     ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
+  } else
+      ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+#endif
+}
Index: c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/if_wmreg.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/if_wmreg.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/if_wmreg.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -6,4 +6,7 @@
  *
  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ * Some are added by Shuchen Kate Feng <feng1@bnl.gov>,
+ *            NSLS, Brookhaven National Laboratory. All rights reserved.
+ *            under the Deaprtment of Energy contract DE-AC02-98CH10886
  *
  * Redistribution and use in source and binary forms, with or without
@@ -57,5 +60,5 @@
  * and there must be an even multiple of 8 descriptors in the ring.
  */
-typedef struct wiseman_rxdesc {
+typedef volatile struct wiseman_rxdesc {
 	wiseman_addr_t	wrx_addr;	/* buffer address */
 
@@ -104,5 +107,5 @@
 	uint16_t wtxu_vlan;		/* VLAN info */
 } __attribute__((__packed__)) wiseman_txfields_t;
-typedef struct wiseman_txdesc {
+typedef volatile struct wiseman_txdesc {
 	wiseman_addr_t	wtx_addr;	/* buffer address */
 	uint32_t	wtx_cmdlen;	/* command and length */
Index: c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/pci_map.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/pci_map.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/pci_map.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -4,4 +4,5 @@
  * Copyright (c) 2004, 2005  Brookhaven National  Laboratory
  *               S. Kate Feng <feng1@bnl.gov>
+ *               under the Deaprtment of Energy contract DE-AC02-98CH10886
  *
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
Index: c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/pcireg.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/pcireg.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/pcireg.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -5,4 +5,5 @@
  *     Christopher G. Demetriou.  All rights reserved.
  * Copyright (c) 1994, 1996 Charles M. Hannum.  All rights reserved.
+ * Copyright (C) 2007 Brookhaven National Laboratory, Shuchen Kate Feng
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,4 +32,5 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+#include <bsp.h>
 
 /*
@@ -306,5 +308,5 @@
 
 #define	PCI_MAPREG_IO_ADDR(mr)						\
-	    ((mr) & PCI_MAPREG_IO_ADDR_MASK)
+	    ((mr+PCI0_IO_BASE) & PCI_MAPREG_IO_ADDR_MASK)
 #define	PCI_MAPREG_IO_SIZE(mr)						\
 	    (PCI_MAPREG_IO_ADDR(mr) & -PCI_MAPREG_IO_ADDR(mr))
Index: c/src/lib/libbsp/powerpc/mvme5500/pci/detect_host_bridge.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/pci/detect_host_bridge.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/pci/detect_host_bridge.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -7,5 +7,6 @@
  * 
  * Copyright (C) 2004 S. Kate Feng, <feng1@bnl.gov>
- * wrote it to support the MVME5500 board.
+ * wrote it to support the MVME5500 board,
+ * under the Deaprtment of Energy contract DE-AC02-98CH10886.
  * 
  */
@@ -24,10 +25,10 @@
 #define PCI_INVALID_VENDORDEVICEID	0xffffffff
 #define PCI_MULTI_FUNCTION		0x80
-#define HOSTBRIDGET_ERROR               0xf0000000
 
 unsigned long _BSP_clear_hostbridge_errors(int enableMCP, int quiet)
 {
-  unsigned int pcidata, pcidata1;
-  int PciLocal, busNumber=0;
+  unsigned long pcidata=0;
+  unsigned short val;
+  int PciLocal, busNumber=0, loop;
   
   /* On the mvme5500 board, the GT64260B system controller had the MCP
@@ -36,38 +37,40 @@
    */
   if (enableMCP) return(-1);
-  for (PciLocal=0; PciLocal<1; PciLocal++ ) {
-     pci_read_config_dword(busNumber,
-			0,
-			0,
-		        PCI_COMMAND,
-                        &pcidata); 
+  for (PciLocal=0; PciLocal<2; PciLocal++ ) {
+      pci_read_config_word(busNumber,
+			       0,
+			       0,
+			  PCI_STATUS,
+			   &val);
+    if ( (val & PCI_STATUS_CLRERR_MASK) && (!quiet)) 
+       printk("Before _BSP_clear_hostbridge_errors(): PCI %d sts was 0x%x\n", 
+                       PciLocal, val);
+      if (!busNumber) 
+	pcidata |= val;
+      else
+        pcidata |= (val <<16);
 
-    if (!quiet)
-    printk("Before _BSP_clear_hostbridge_errors(): 0x%x, cause 0x%x\n", 
-	   pcidata, inl(0x1d58));
-
-    outl(0,0x1d58);
-
-    /* Clear the error on the host bridge */
-    pcidata1= pcidata;
-    pcidata1 |= PCI_STATUS_CLRERR_MASK;
-    pcidata1 |= 0x140; 
-    pci_write_config_dword(busNumber,
+      for ( loop=0; loop < 10; loop++) {
+          /* Clear the error on the host bridge */
+          pci_write_config_word(busNumber,
  			       0,
 			       0,
-			  PCI_COMMAND,
-                          pcidata1);
+			  PCI_STATUS,
+                          PCI_STATUS_CLRERR_MASK);
 
-    pci_read_config_dword(busNumber,
+          pci_read_config_word(busNumber,
 			       0,
 			       0,
-			  PCI_COMMAND,
-                          &pcidata1); 
-
-    if (!quiet) printk("After _BSP_clear_hostbridge_errors(): sts 0x%x\n", 
-                        pcidata1);
-    if (pcidata1 & HOSTBRIDGET_ERROR) printk("BSP_clear_hostbridge_errors(): unable to clear pending hostbridge errors\n");
-    busNumber += BSP_MAX_PCI_BUS_ON_PCI0;
+			  PCI_STATUS,
+                          &val); 
+          if ( !(val & PCI_STATUS_CLRERR_MASK)) 
+             break;
+          else {
+	    if (loop==9)
+	      printk("BSP_clear_hostbridge_errors(): unable to clear pending hostbridge errors\n");
+          }
+      }
+      busNumber += BSP_MAX_PCI_BUS_ON_PCI0;
   }
-  return(pcidata &  HOSTBRIDGET_ERROR);
+  return(pcidata);
 }
Index: c/src/lib/libbsp/powerpc/mvme5500/pci/gtpcireg.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/pci/gtpcireg.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/pci/gtpcireg.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -47,5 +47,5 @@
 #define PCI_IO_BASE_ADDR  PCI_BASE_ADDRESS_5
 
-#define  PCI_STATUS_CLRERR_MASK 0xf9000000 /* <SKF> */
+#define  PCI_STATUS_CLRERR_MASK 0xf900 /* <SKF> */
 
 #define PCI_BARE_IntMemEn     0x200
Index: c/src/lib/libbsp/powerpc/mvme5500/pci/pci.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/pci/pci.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/pci/pci.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -17,9 +17,9 @@
  *
  *  Copyright 2004, Brookhaven National Laboratory and
- *                  Shuchen K. Feng, <feng1@bnl.gov>, 2004
- *   - modified and added support for MVME5500 board
- *   - added 2nd PCI support for the mvme5500/GT64260 PCI bridge
- *   - added bus support for the expansion of PMCSpan, thanks to 
- *     Peter Dufault (dufault@hda.com) for inputs.
+ *                  Shuchen K. Feng, <feng1@bnl.gov>, 2004, 2008
+ *   
+ *   - to be consistent with the original pci.c written by Eric Valette
+ *   - added 2nd PCI support for discovery based PCI bridge (e.g. mvme5500/mvme6100)
+ *   - added bus support for the expansion of PMCSpan as per request by Peter
  */
 #define PCI_MAIN
@@ -28,7 +28,9 @@
 #include <rtems/bspIo.h>	    /* printk */
 
+#include <bsp/irq.h>
 #include <bsp/pci.h>
 #include <bsp/gtreg.h>
 #include <bsp/gtpcireg.h> 
+#include <bsp.h>
 
 #include <stdio.h>
@@ -36,5 +38,5 @@
 
 #define PCI_DEBUG 0
-#define PCI_PRINT 0
+#define PCI_PRINT 1
 
 /* allow for overriding these definitions */
@@ -57,8 +59,22 @@
 #define HOSTBRIDGET_ERROR               0xf0000000
 
-/* define a shortcut */
-#define pci	BSP_pci_configuration
-
-static int		  numPCIDevs=0;
+#define GT64x60_PCI_CONFIG_ADDR         GT64x60_REG_BASE + PCI_CONFIG_ADDR
+#define GT64x60_PCI_CONFIG_DATA         GT64x60_REG_BASE + PCI_CONFIG_DATA
+
+#define GT64x60_PCI1_CONFIG_ADDR        GT64x60_REG_BASE + PCI1_CONFIG_ADDR
+#define GT64x60_PCI1_CONFIG_DATA        GT64x60_REG_BASE + PCI1_CONFIG_DATA
+
+static int      numPCIDevs=0;
+static DiscoveryChipVersion BSP_sysControllerVersion = 0;
+static BSP_VMEchipTypes BSP_VMEinterface = 0;
+static pci_config BSP_pci[2]={
+  {(volatile unsigned char*) (GT64x60_PCI_CONFIG_ADDR),
+   (volatile unsigned char*) (GT64x60_PCI_CONFIG_DATA),
+   0 /* defined at BSP_pci_configuration */},
+  {(volatile unsigned char*) (GT64x60_PCI1_CONFIG_ADDR),
+   (volatile unsigned char*) (GT64x60_PCI1_CONFIG_DATA),
+   0 /* defined at BSP_pci_configuration */}
+};
+
 extern void pci_interface();
 
@@ -67,5 +83,5 @@
  */
 #define pciConfigPack(bus,dev,func,offset)\
-(((func&7)<<8)|((dev&0x1f )<<11)|(( bus&0xff)<<16)|(offset&0xfc))|0x80000000
+((offset&~3)<<24)|(PCI_DEVFN(dev,func)<<16)|(bus<<8)|0x80
 
 /*
@@ -76,42 +92,34 @@
 /* Please note that PCI0 and PCI1 does not correlate with the busNum 0 and 1.
  */
-static int direct_pci_read_config_byte(unsigned char bus,unsigned char dev,unsigned char func,
+static int indirect_pci_read_config_byte(unsigned char bus,unsigned char dev,unsigned char func,
 unsigned char offset,unsigned char *val)
 {
-  volatile unsigned char *config_addr, *config_data;
-
-  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
-     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
-     config_addr = (volatile unsigned char*) PCI1_CONFIG_ADDR;
-     config_data = (volatile unsigned char*) PCI1_CONFIG_DATA;
-  }
-  else {
-     config_addr = pci.pci_config_addr;
-     config_data = pci.pci_config_data;
-  }
+  int n=0;
+
+  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
+     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
+     n=1;
+  }
+
   *val = 0xff;
   if (offset & ~0xff) return PCIBIOS_BAD_REGISTER_NUMBER;
 #if 0
-  printk("addr %x, data %x, pack %x \n", config_addr,
-    config_data,pciConfigPack(bus,dev,func,offset));
-#endif
-  outl(pciConfigPack(bus,dev,func,offset),config_addr);
-  *val = inb(config_data + (offset&3));
-  return PCIBIOS_SUCCESSFUL;
-}
-
-static int direct_pci_read_config_word(unsigned char bus, unsigned char dev,
+  printk("addr %x, data %x, pack %x \n", BSP_pci[n].pci_config_addr),
+    BSP_pci[n].config_data,pciConfigPack(bus,dev,func,offset));
+#endif
+
+  out_be32(BSP_pci[n].pci_config_addr, pciConfigPack(bus,dev,func,offset));
+  *val = in_8(BSP_pci[n].pci_config_data + (offset&3));
+  return PCIBIOS_SUCCESSFUL;
+}
+
+static int indirect_pci_read_config_word(unsigned char bus, unsigned char dev,
 unsigned char func, unsigned char offset, unsigned short *val)
 {
-  volatile unsigned char *config_addr, *config_data;
-
-  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
-     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
-     config_addr = (volatile unsigned char*) PCI1_CONFIG_ADDR;
-     config_data = (volatile unsigned char*) PCI1_CONFIG_DATA;
-  }
-  else {
-     config_addr = (volatile unsigned char*) pci.pci_config_addr;
-     config_data = (volatile unsigned char*) pci.pci_config_data;
+  int n=0;
+
+  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
+     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
+     n=1;
   }
 
@@ -122,121 +130,99 @@
     config_data,pciConfigPack(bus,dev,func,offset));
 #endif
-  outl(pciConfigPack(bus,dev,func,offset),config_addr);
-  *val = inw(config_data + (offset&2));
-  return PCIBIOS_SUCCESSFUL;
-}
-
-static int direct_pci_read_config_dword(unsigned char bus, unsigned char dev,
+  out_be32(BSP_pci[n].pci_config_addr, pciConfigPack(bus,dev,func,offset));
+  *val = in_le16(BSP_pci[n].pci_config_data + (offset&2));
+  return PCIBIOS_SUCCESSFUL;
+}
+
+static int indirect_pci_read_config_dword(unsigned char bus, unsigned char dev,
 unsigned char func, unsigned char offset, unsigned int *val) 
 {
-  volatile unsigned char *config_addr, *config_data;
-
-  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
-     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
-     config_addr = (volatile unsigned char*) PCI1_CONFIG_ADDR;
-     config_data = (volatile unsigned char*) PCI1_CONFIG_DATA;
-  }
-  else {
-     config_addr = (volatile unsigned char*) pci.pci_config_addr;
-     config_data = (volatile unsigned char*) pci.pci_config_data;
+  int n=0;
+
+  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
+     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
+     n=1;
   }
 
   *val = 0xffffffff; 
   if ((offset&3)|| (offset & ~0xff)) return PCIBIOS_BAD_REGISTER_NUMBER;
-#if 0
-  printk("addr %x, data %x, pack %x \n", config_addr,
-    pci.pci_config_data,pciConfigPack(bus,dev,func,offset)); 
-#endif
-  outl(pciConfigPack(bus,dev,func,offset),config_addr);
-  *val = inl(config_data);
-  return PCIBIOS_SUCCESSFUL;
-}
-
-static int direct_pci_write_config_byte(unsigned char bus, unsigned char dev,unsigned char func, unsigned char offset, unsigned char val) 
-{
-  volatile unsigned char *config_addr, *config_data;
-
-  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
-     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
-     config_addr = (volatile unsigned char*) PCI1_CONFIG_ADDR;
-     config_data = (volatile unsigned char*) PCI1_CONFIG_DATA;
-  }
-  else {
-     config_addr = pci.pci_config_addr;
-     config_data = pci.pci_config_data;
+
+  out_be32(BSP_pci[n].pci_config_addr, pciConfigPack(bus,dev,func,offset));
+  *val = in_le32(BSP_pci[n].pci_config_data);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+static int indirect_pci_write_config_byte(unsigned char bus, unsigned char dev,unsigned char func, unsigned char offset, unsigned char val) 
+{
+  int n=0;
+
+  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
+     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
+     n=1;
   }
 
   if (offset & ~0xff) return PCIBIOS_BAD_REGISTER_NUMBER;
-#if 0
-  printk("addr %x, data %x, pack %x \n", config_addr,
-    config_data,pciConfigPack(bus,dev,func,offset));
-#endif
-
-  outl(pciConfigPack(bus,dev,func,offset), config_addr);
-  outb(val, config_data + (offset&3));
-  return PCIBIOS_SUCCESSFUL;
-}
-
-static int direct_pci_write_config_word(unsigned char bus, unsigned char dev,unsigned char func, unsigned char offset, unsigned short val) 
-{
-  volatile unsigned char *config_addr, *config_data;
-
-  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
-     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
-     config_addr = (volatile unsigned char*) PCI1_CONFIG_ADDR;
-     config_data = (volatile unsigned char*) PCI1_CONFIG_DATA;
-  }
-  else {
-     config_addr = (volatile unsigned char*) pci.pci_config_addr;
-     config_data = (volatile unsigned char*) pci.pci_config_data;
+
+  out_be32(BSP_pci[n].pci_config_addr, pciConfigPack(bus,dev,func,offset));
+  out_8(BSP_pci[n].pci_config_data + (offset&3), val);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+static int indirect_pci_write_config_word(unsigned char bus, unsigned char dev,unsigned char func, unsigned char offset, unsigned short val) 
+{
+  int n=0;
+
+  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
+     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
+     n=1;
   }
 
   if ((offset&1)|| (offset & ~0xff)) return PCIBIOS_BAD_REGISTER_NUMBER;
-#if 0
-  printk("addr %x, data %x, pack %x \n", config_addr,
-    config_data,pciConfigPack(bus,dev,func,offset));
-#endif
-  outl(pciConfigPack(bus,dev,func,offset),config_addr);
-  outw(val, config_data + (offset&3));
-  return PCIBIOS_SUCCESSFUL;
-}
-
-static int direct_pci_write_config_dword(unsigned char bus,unsigned char dev,unsigned char func, unsigned char offset, unsigned int val) 
-{
-  volatile unsigned char *config_addr, *config_data;
-
-  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
-     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
-     config_addr = (volatile unsigned char *) PCI1_CONFIG_ADDR;
-     config_data = (volatile unsigned char *) PCI1_CONFIG_DATA;
-  }
-  else {
-     config_addr = (volatile unsigned char*) pci.pci_config_addr;
-     config_data = (volatile unsigned char*) pci.pci_config_data;
+
+  out_be32(BSP_pci[n].pci_config_addr, pciConfigPack(bus,dev,func,offset));
+  out_le16(BSP_pci[n].pci_config_data + (offset&3), val);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+static int indirect_pci_write_config_dword(unsigned char bus,unsigned char dev,unsigned char func, unsigned char offset, unsigned int val) 
+{
+  int n=0;
+
+  if (bus>= BSP_MAX_PCI_BUS_ON_PCI0) {
+     bus-=BSP_MAX_PCI_BUS_ON_PCI0;
+     n=1;
   }
 
   if ((offset&3)|| (offset & ~0xff)) return PCIBIOS_BAD_REGISTER_NUMBER;
-#if 0
-  printk("addr %x, data %x, pack %x \n", config_addr,
-    config_data,pciConfigPack(bus,dev,func,offset));
-#endif
-  outl(pciConfigPack(bus,dev,func,offset),config_addr);
-  outl(val,config_data);
-  return PCIBIOS_SUCCESSFUL;
-}
-
-const pci_config_access_functions pci_direct_functions = {
-  	direct_pci_read_config_byte,
-  	direct_pci_read_config_word,
-  	direct_pci_read_config_dword,
-  	direct_pci_write_config_byte,
-  	direct_pci_write_config_word,
-  	direct_pci_write_config_dword
+
+  out_be32(BSP_pci[n].pci_config_addr, pciConfigPack(bus,dev,func,offset));
+  out_le32(BSP_pci[n].pci_config_data, val);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+const pci_config_access_functions pci_indirect_functions = {
+  	indirect_pci_read_config_byte,
+  	indirect_pci_read_config_word,
+  	indirect_pci_read_config_dword,
+  	indirect_pci_write_config_byte,
+  	indirect_pci_write_config_word,
+  	indirect_pci_write_config_dword
 };
 
 
-pci_config BSP_pci_configuration = {(volatile unsigned char*) PCI_CONFIG_ADDR,
-			 (volatile unsigned char*)PCI_CONFIG_DATA,
-				    &pci_direct_functions};
+pci_config BSP_pci_configuration = {
+           (volatile unsigned char*) (GT64x60_PCI_CONFIG_ADDR),
+	   (volatile unsigned char*) (GT64x60_PCI_CONFIG_DATA),
+	   &pci_indirect_functions};
+
+DiscoveryChipVersion BSP_getDiscoveryChipVersion()
+{
+  return(BSP_sysControllerVersion);
+}
+
+BSP_VMEchipTypes BSP_getVMEchipType()
+{
+  return(BSP_VMEinterface);
+}
 
 /*
@@ -249,10 +235,10 @@
 {
   int deviceFound;
-  unsigned char ucBusNumber, ucSlotNumber, ucFnNumber, ucNumFuncs;
-  unsigned int ulHeader;
-  unsigned int pcidata, ulClass, ulDeviceID;
-
-  pci_interface();
-  
+  unsigned char ucBusNumber, ucSlotNumber, ucFnNumber, ucNumFuncs, data8;
+  uint32_t ulHeader, ulClass, ulDeviceID;
+#if PCI_DEBUG
+  uint32_t pcidata;
+#endif
+
   /*
    * Scan PCI0 and PCI1 buses
@@ -280,10 +266,34 @@
       switch(ulDeviceID) { 
         case (PCI_VENDOR_ID_MARVELL+(PCI_DEVICE_ID_MARVELL_GT6426xAB<<16)):
-#if PCI_PRINT
-	  printk("Marvell GT6426xA/B hostbridge detected at bus%d slot%d\n",
+          pci_read_config_byte(0,0,0,PCI_REVISION_ID, &data8);
+          switch(data8) {
+	  case 0x10:
+	    BSP_sysControllerVersion = GT64260A;
+#if PCI_PRINT
+	    printk("Marvell GT64260A (Discovery I) hostbridge detected at bus%d slot%d\n",
+                 ucBusNumber,ucSlotNumber);
+#endif
+	    break;
+          case 0x20:
+	    BSP_sysControllerVersion = GT64260B;
+#if PCI_PRINT
+	    printk("Marvell GT64260B (Discovery I) hostbridge detected at bus%d slot%d\n",
+                 ucBusNumber,ucSlotNumber);
+#endif
+	    break;
+	  default:
+	    printk("Undefined revsion of GT64260 chip\n");
+            break;
+          }
+	  break;
+        case (PCI_VENDOR_ID_MARVELL+(PCI_DEVICE_ID_MARVELL_GT64360<<16)):
+	  BSP_sysControllerVersion = MV64360;
+#if PCI_PRINT
+	  printk("Marvell GT64360 (Discovery II) hostbridge detected at bus%d slot%d\n",
                  ucBusNumber,ucSlotNumber);
 #endif
 	  break;
         case (PCI_VENDOR_ID_PLX2+(PCI_DEVICE_ID_PLX2_PCI6154_HB2<<16)):
+	  BSP_VMEinterface = UNIVERSE2;
 #if PCI_PRINT
           printk("PLX PCI6154 PCI-PCI bridge detected at bus%d slot%d\n",
@@ -297,4 +307,11 @@
 #endif
           break;
+        case (PCI_VENDOR_ID_TUNDRA+(PCI_DEVICE_ID_TUNDRA_TSI148<<16)):
+	  BSP_VMEinterface = TSI148;
+#if PCI_PRINT
+          printk("TUNDRA Tsi148 PCI/X-VME bridge detected at bus%d slot%d\n",
+                 ucBusNumber,ucSlotNumber);
+#endif
+          break;
       case (PCI_VENDOR_ID_INTEL+(PCI_DEVICE_INTEL_82544EI_COPPER<<16)):
 #if PCI_PRINT
@@ -304,5 +321,5 @@
           break;
       case (PCI_VENDOR_ID_DEC+(PCI_DEVICE_ID_DEC_21150<<16)):
- #if PCI_PRINT
+#if PCI_PRINT
           printk("DEC21150 PCI-PCI bridge detected at bus%d slot%d\n",
                  ucBusNumber,ucSlotNumber);
@@ -310,6 +327,13 @@
 	  break;
        default : 
+#if PCI_PRINT
           printk("BSP unlisted vendor, Bus%d Slot%d DeviceID 0x%x \n",
              ucBusNumber,ucSlotNumber, ulDeviceID);
+#endif
+	  /* Kate Feng : device not supported by BSP needs to remap the IRQ line on mvme5500/mvme6100 */
+          pci_read_config_byte(ucBusNumber,ucSlotNumber,0,PCI_INTERRUPT_LINE,&data8);
+	  if (data8 < BSP_GPP_IRQ_LOWEST_OFFSET)  pci_write_config_byte(ucBusNumber,
+ 	     ucSlotNumber,0,PCI_INTERRUPT_LINE,BSP_GPP_IRQ_LOWEST_OFFSET+data8);
+
           break;
       }
@@ -404,32 +428,4 @@
 
       }
-
-      pci_read_config_dword(ucBusNumber,
-			       ucSlotNumber,
-			       0,
-			  PCI_COMMAND,
-                          &pcidata); 
-#if PCI_DEBUG
-      printk("MOTLoad command staus 0x%x, ", pcidata);
-#endif
-      /* Clear the error on the host bridge */
-      if ( (ucBusNumber==0) && (ucSlotNumber==0))
-	pcidata |= PCI_STATUS_CLRERR_MASK;
-      /* Enable bus,I/O and memory master access. */
-      pcidata |= (PCI_COMMAND_MASTER|PCI_COMMAND_IO|PCI_COMMAND_MEMORY);
-      pci_write_config_dword(ucBusNumber,
- 			       ucSlotNumber,
-			       0,
-			  PCI_COMMAND,
-                          pcidata);
-
-      pci_read_config_dword(ucBusNumber,
-			       ucSlotNumber,
-			       0,
-			  PCI_COMMAND,
-                          &pcidata); 
-#if PCI_DEBUG      
-      printk("Now command/staus 0x%x\n", pcidata);
-#endif
     }
     if (deviceFound) ucMaxPCIBus++;
@@ -439,4 +435,5 @@
 	 pci_bus_count(), numPCIDevs);
 #endif
+  pci_interface(BSP_sysControllerVersion); 
   return(0);
 }
Index: c/src/lib/libbsp/powerpc/mvme5500/pci/pci.h
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/pci/pci.h	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/pci/pci.h	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -15,6 +15,5 @@
  *      pci.h,v 1.2 2002/05/14 17:10:16 joel Exp
  *
- *      S. Kate Feng : Added support for Marvell and PLX. 3/5/2004.
-
+ *      S. Kate Feng : Added support for Marvell and PLX. 2004, 2007.
  */
 
@@ -24,8 +23,9 @@
 #include <rtems/pci.h>
 
-#define PCI_CAPABILITY_LIST_POINTER    0x34  /* <SKF> */
+/************   Beginning of added by Kate Feng **********************/
+#define PCI_CAPABILITY_LIST_POINTER    0x34
 
 /* Device classes and subclasses */
-#define PCI_CLASS_GT6426xAB_BRIDGE_PCI  0x0580    /* <SKF> */
+#define PCI_CLASS_GT6426xAB_BRIDGE_PCI  0x0580 
           
 /*
@@ -34,14 +34,18 @@
  * <linux-pcisupport@cck.uni-kl.de>.
  */
-#define PCI_VENDOR_ID_MARVELL           0x11ab   /* <SKF> */
-#define PCI_DEVICE_ID_MARVELL_GT6426xAB 0x6430   /* <SKF> */
+#define PCI_VENDOR_ID_MARVELL           0x11ab  
+#define PCI_DEVICE_ID_MARVELL_GT6426xAB 0x6430   
+#define PCI_DEVICE_ID_MARVELL_GT64360   0x6460  
 
 /* Note : The PLX Technology Inc. had the old VENDOR_ID.
  * See PCI_VENDOR_ID_PLX,  PCI_VENDOR_ID_PLX_9050, ..etc.
  */
-#define PCI_VENDOR_ID_PLX2              0x3388   /* <SKF> */
-#define PCI_DEVICE_ID_PLX2_PCI6154_HB2  0x26     /* <SKF> */
+#define PCI_VENDOR_ID_PLX2              0x3388   
+#define PCI_DEVICE_ID_PLX2_PCI6154_HB2  0x26     
 
-#define PCI_DEVICE_INTEL_82544EI_COPPER	0x1008	/* <SKF> */
+#define PCI_DEVICE_ID_TUNDRA_TSI148     0x0148  
+#define PCI_DEVICE_INTEL_82544EI_COPPER	0x1008
+
+/* end of added by Kate Feng */
 
 struct _pin_routes
Index: c/src/lib/libbsp/powerpc/mvme5500/pci/pci_interface.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/pci/pci_interface.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/pci/pci_interface.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -8,8 +8,12 @@
  *
  * 8/17/2006 : S. Kate Feng
- *             uses in_le32()/out_le32(), instead of inl()/outl() so that
- *             it is easier to be ported.
+ *             uses in_le32()/out_le32(), instead of inl()/outl() for compatibility.
  *
+ * 11/2008 : Enable "PCI Read Agressive Prefetch", 
+ *           "PCI Read Line Agressive Prefetch", and
+ *           "PCI Read Multiple Agressive Prefetch" to improve the
+ *           performance of the PCI based applications (e.g. 1GHz NIC).
  */
+
 #include <libcpu/io.h>
 #include <rtems/bspIo.h>	    /* printk */
@@ -20,40 +24,21 @@
 #include <bsp/gtpcireg.h> 
 
-#define REG32_READ(reg) in_le32((volatile unsigned int *)(GT64260_REG_BASE+reg))
-#define REG32_WRITE(data, reg) out_le32((volatile unsigned int *)(GT64260_REG_BASE+reg), data)
-
 #define PCI_DEBUG     0
 
-/* Please reference the GT64260B datasheet, for the PCI interface, 
- * Synchronization Barriers and PCI ordering.
- *
- * Some PCI devices require Synchronization Barriers or PCI ordering
- * for synchronization (only one mechanism allowed. See section 11.1.2).
- * To use the former mechanism(default), one needs to call 
- * CPU0_PciEnhanceSync() or CPU1_PciEnhanceSync() to perform software
- * synchronization between the CPU and PCI activities.
- * 
- * To use the PCI-ordering, one can call pciToCpuSync() to trigger
- * the PCI-to-CPU sync barrier after the out_xx(). In this mode,
- * PCI configuration reads suffer sync barrier latency. Please reference
- * the datasheet to explore other options.
- *
- * Note : If PCI_ORDERING is needed for the PCI0, while disabling the
- * deadlock  for the PCI0, one should keep the CommDLEn bit enabled
- * for the deadlock mechanism so that the 10/100 MB ethernet will
- * function correctly.
- *
+#if 0
+#define CPU2PCI_ORDER
+#define PCI2CPU_ORDER
+#endif
+
+/* PCI Read Agressive Prefetch Enable (1<<16 ),
+ * PCI Read Line Agressive Prefetch Enable( 1<<17),
+ * PCI Read Multiple Agressive Prefetch Enable (1<<18).
  */
-/*#define PCI_ORDERING*/
+#ifdef PCI2CPU_ORDER
+#define PCI_ACCCTLBASEL_VALUE          0x01079000
+#else
+#define PCI_ACCCTLBASEL_VALUE          0x01071000 
+#endif
 
-#define EN_SYN_BAR   /* take MOTLoad default for enhanced SYN Barrier mode */
-
-/*#define PCI_DEADLOCK*/
-
-#ifdef PCI_ORDERING
-#define PCI_ACCCTLBASEL_VALUE          0x01009000
-#else
-#define PCI_ACCCTLBASEL_VALUE          0x01001000
-#endif
 
 #define ConfSBDis     0x10000000  /* 1: disable, 0: enable */
@@ -61,11 +46,4 @@
 #define ConfIOSBDis   0x30000000
 #define CpuPipeline   0x00002000  /* optional, 1:enable, 0:disable */
-
-#define CPU0_SYNC_TRIGGER   0xD0  /* CPU0 Sync Barrier trigger */
-#define CPU0_SYNC_VIRTUAL   0xC0  /* CPU0 Sync Barrier Virtual */
-
-#define CPU1_SYNC_TRIGGER   0xD8  /* CPU1 Sync Barrier trigger */
-#define CPU1_SYNC_VIRTUAL   0xC8  /* CPU1 Sync Barrier Virtual */
-
 
 /* CPU to PCI ordering register */
@@ -87,73 +65,34 @@
 #define ADDR_PIPELINE 0x00020000
 
-void  pciAccessInit();
+void  pciAccessInit(void);
 
-void pci_interface()
+void pci_interface(void)
 {
 
-#ifdef PCI_DEADLOCK
-  REG32_WRITE(0x07fff600, CNT_SYNC_REG);
+#ifdef CPU2PCI_ORDER
+    /* MOTLOad deafult : 0x07ff8600 */
+    out_le32((volatile unsigned int *)(GT64x60_REG_BASE+CNT_SYNC_REG), 0x07fff600);
 #endif
-#ifdef PCI_ORDERING
-  /* Let's leave this to be MOTLOad deafult : 0x80070000 
-     REG32_WRITE(0xc0070000, DLOCK_ORDER_REG);*/
-  /* Leave the CNT_SYNC_REG b/c MOTload default had the SyncBarMode set to 1 */
-#endif
+    /* asserts SERR upon various detection */
+    out_le32((volatile unsigned int *)(GT64x60_REG_BASE+0xc28), 0x3fffff);
+    pciAccessInit();
+}
 
-  /* asserts SERR upon various detection */
-  REG32_WRITE(0x3fffff, 0xc28);
-
-  pciAccessInit();
-}
-/* Use MOTLoad default for Writeback Priority and Buffer Depth 
- */
-void pciAccessInit()
+void pciAccessInit(void)
 {
   unsigned int PciLocal, data;
 
   for (PciLocal=0; PciLocal < 2; PciLocal++) {
-    /* MOTLoad combines the two banks of SDRAM into
-     * one PCI access control because the top = 0x1ff
-     */
-    data = REG32_READ(GT_SCS0_Low_Decode) & 0xfff; 
+    data = in_le32((volatile unsigned int *)(GT64x60_REG_BASE+PCI0_ACCESS_CNTL_BASE0_LOW+(PciLocal * 0x80)));
+#if 0
+    printk("PCI%d_ACCESS_CNTL_BASE0_LOW was 0x%x\n",PciLocal,data);
+#endif 
     data |= PCI_ACCCTLBASEL_VALUE;
     data &= ~0x300000;
-    REG32_WRITE(data, PCI0_ACCESS_CNTL_BASE0_LOW+(PciLocal * 0x80));
-#if PCI_DEBUG
-    printk("PCI%d_ACCESS_CNTL_BASE0_LOW 0x%x\n",PciLocal,REG32_READ(PCI_ACCESS_CNTL_BASE0_LOW+(PciLocal * 0x80))); 
+    out_le32((volatile unsigned int *)(GT64x60_REG_BASE+PCI0_ACCESS_CNTL_BASE0_LOW+(PciLocal * 0x80)), data);
+#if 0
+      printf("PCI%d_ACCESS_CNTL_BASE0_LOW now 0x%x\n",PciLocal,in_le32((volatile unsigned int *)(GT64x60_REG_BASE+PCI0_ACCESS_CNTL_BASE0_LOW+(PciLocal * 0x80)))); 
 #endif
-
   }
 }
 
-/* Sync Barrier Trigger. A write to the CPU_SYNC_TRIGGER register triggers
- * the sync barrier process.  The three bits, define which buffers should
- * be flushed.
- * Bit 0 = PCI0 slave write buffer.
- * Bit 1 = PCI1 slave write buffer.
- * Bit 2 = SDRAM snoop queue.
- */
-void CPU0_PciEnhanceSync(unsigned int syncVal)
-{
-  REG32_WRITE(syncVal,CPU0_SYNC_TRIGGER);
-  while (REG32_READ(CPU0_SYNC_VIRTUAL));
-}
-
-void CPU1_PciEnhanceSync(unsigned int syncVal)
-{
-  REG32_WRITE(syncVal,CPU1_SYNC_TRIGGER);
-  while (REG32_READ(CPU1_SYNC_VIRTUAL));
-}
-
-/* Currently, if PCI_ordering is used for synchronization, configuration
- * reads is programmed to be the PCI slave "synchronization barrier" 
- * cycles. 
- */
-void pciToCpuSync(int pci_num)
-{
-  unsigned char data;
-  unsigned char bus=0;
-
-  if (pci_num) bus += BSP_MAX_PCI_BUS_ON_PCI0;
-  pci_read_config_byte(bus,0,0,4, &data);
-}
Index: c/src/lib/libbsp/powerpc/mvme5500/pci/pcifinddevice.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/pci/pcifinddevice.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/pci/pcifinddevice.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -8,5 +8,5 @@
  * 
  * Kate Feng <feng1@bnl.gov>, modified it to support the mvme5500 board.
- * 
+ * Under the Deaprtment of Energy contract DE-AC02-98CH10886.
  */
 
Index: c/src/lib/libbsp/powerpc/mvme5500/startup/bspclean.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/startup/bspclean.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/startup/bspclean.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,2 +1,5 @@
+/* Copyright 2003, Shuchen Kate Feng <feng1@bnl.gov>,
+ *                    NSLS,Brookhaven National Laboratory
+ */
 #include <bsp.h>
 #include <rtems/bspIo.h>
Index: c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/startup/bspstart.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -18,8 +18,7 @@
  *  (C) by Till Straumann, <strauman@slac.stanford.edu>, 2002, 2004, 2005
  *
- *  Modified to support the MVME5500 board.
- *  Also, the settings of L1, L2, and L3 caches is not necessary here.
- *  (C) by Brookhaven National Lab., S. Kate Feng <feng1@bnl.gov>, 2003, 2004, 2005
- *  
+ *  Modified to support the mvme5500 BSP 
+ *  (C) S. Kate Feng,Brookhaven National Lab <feng1@bnl.gov>, 2003, 2004, 2005, 2008
+ *
  *  $Id$
  */
@@ -43,4 +42,5 @@
 #include <bsp/vectors.h>
 #include <bsp/bspException.h>
+#include <bsp/VPD.h>
 
 #include <rtems/bspIo.h>
@@ -51,6 +51,5 @@
 #endif
 
-/*
-#define SHOW_MORE_INIT_SETTINGS
+/*efine SHOW_MORE_INIT_SETTINGS
 #define SHOW_LCR1_REGISTER
 #define SHOW_LCR2_REGISTER
@@ -75,4 +74,5 @@
 SPR_RW(SPRG0)
 SPR_RW(SPRG1)
+extern uint32_t probeMemoryEnd();
 
 typedef struct CmdLineRec_ {
@@ -96,4 +96,8 @@
 #define MAX_LOADER_ADD_PARM 80
 char loaderParam[MAX_LOADER_ADD_PARM];
+
+BSP_BoardTypes BSP_boardType=0;
+
+DiscoveryChipVersion BSP_controller_version;
 
 /*
@@ -223,4 +227,9 @@
 }
 
+BSP_BoardTypes BSP_getBoardType()
+{
+	return BSP_boardType;
+}
+
 /*
  *  bsp_start
@@ -234,4 +243,5 @@
   int i;
 #endif
+  int x;
   unsigned char *stack;
   unsigned long	 *r1sp;
@@ -251,4 +261,6 @@
   ppc_cpu_revision_t myCpuRevision;
   Triv121PgTbl	pt=0;
+  ConfVpdRec_t *pVPD = (ConfVpdRec_t *) &ConfVPD_buff[0];
+
 
   /* Till Straumann: 4/2005
@@ -261,10 +273,9 @@
   setdbat(2, PCI0_MEM_BASE, PCI0_MEM_BASE, 0x10000000, IO_PAGE);
 
-  /* Till Straumann: 2004
-   * map the PCI 0, 1 Domain I/O space, GT64260B registers
-   * and the reserved area so that the size is the power of 2.
+  /* map the PCI 0, 1 Domain I/O space, GT64260B registers,
+   * Flash Bank 0 and Flash Bank 2.
    * 
    */
-  setdbat(3,PCI0_IO_BASE, PCI0_IO_BASE, 0x2000000, IO_PAGE);
+  setdbat(3,PCI0_IO_BASE, PCI0_IO_BASE, 0x10000000, IO_PAGE);
 
 
@@ -323,4 +334,21 @@
   Cpu_table.exceptions_in_RAM = TRUE;
   initialize_exceptions();
+
+  /* <SKF> pci_initialize() before BSP_rtems_irq_mng_init to identify the version of the
+   * Discovery chip.
+   */
+#ifdef SHOW_MORE_INIT_SETTINGS
+  printk("Going to start PCI buses scanning and initialization\n");
+#endif  
+  pci_initialize();
+#ifdef SHOW_MORE_INIT_SETTINGS
+  printk("Number of PCI buses found is : %d\n", pci_bus_count());
+#endif
+
+  /*
+   * Initalize RTEMS IRQ system
+   */
+  BSP_rtems_irq_mng_init(0);
+
   /*
    * Init MMU block address translation to enable hardware
@@ -329,31 +357,8 @@
    */
   printk("-----------------------------------------\n");
-  printk("Welcome to %s on MVME5500-0163\n", _RTEMS_version );
+  printk("Welcome to %s on MVME5500\n", _RTEMS_version );
   printk("-----------------------------------------\n");
 
-#ifdef TEST_RETURN_TO_PPCBUG  
-  printk("Hit <Enter> to return to PPCBUG monitor\n");
-  printk("When Finished hit GO. It should print <Back from monitor>\n");
-  debug_getc();
-  _return_to_ppcbug();
-  printk("Back from monitor\n");
-  _return_to_ppcbug();
-#endif /* TEST_RETURN_TO_PPCBUG  */
-
-#ifdef TEST_RAW_EXCEPTION_CODE  
-  printk("Testing exception handling Part 1\n");
-  /*
-   * Cause a software exception
-   */
-  __asm__ __volatile ("sc");
-  /*
-   * Check we can still catch exceptions and returned coorectly.
-   */
-  printk("Testing exception handling Part 2\n");
-  __asm__ __volatile ("sc");
-#endif  
-
-  BSP_mem_size 				=  _512M;
-  /* TODO: calculate the BSP_bus_frequency using the REF_CLK bit of System Status  register */
+  BSP_mem_size 				=  probeMemoryEnd();
   /* rtems_bsp_delay_in_bus_cycles are defined in registers.h */
   BSP_bus_frequency			= 133333333;
@@ -402,9 +407,4 @@
   BSP_Configuration.work_space_start = work_space_start;
 
-  /*
-   * Initalize RTEMS IRQ system
-   */
-   BSP_rtems_irq_mng_init(0);
-
 #ifdef SHOW_LCR2_REGISTER
   l2cr = get_L2CR();
@@ -430,28 +430,5 @@
   }
 
-  /*
-   * PCI 1 domain memory space
-   */
-  setdbat(1, PCI1_MEM_BASE, PCI1_MEM_BASE, 0x10000000, IO_PAGE);
- 
-
-#ifdef SHOW_MORE_INIT_SETTINGS
-  printk("Going to start PCI buses scanning and initialization\n");
-#endif  
-  pci_initialize();
-#ifdef SHOW_MORE_INIT_SETTINGS
-  printk("Number of PCI buses found is : %d\n", pci_bus_count());
-#endif
-
-  /* Install our own exception handler (needs PCI) */
-  globalExceptHdl = BSP_exceptionHandler;
-
-  /* clear hostbridge errors. MCP signal is not used on the MVME5500
-   * PCI config space scanning code will trip otherwise :-(
-   */
-  _BSP_clear_hostbridge_errors(0, 1 /*quiet*/);
-
-  /* Read Configuration Vital Product Data (VPD) */
-  if ( I2Cread_eeprom(0xa8, 4,2, &ConfVPD_buff[0], 150))
+  if ( I2Cread_eeprom(0xa8, 0,2, (void *) pVPD, sizeof(ConfVpdRec_t)))
      printk("I2Cread_eeprom() error \n");
   else {
@@ -462,7 +439,22 @@
       if ((i % 20)==0 ) printk("\n");
     }
-    printk("\n");
 #endif
   }
+
+  /*
+   * PCI 1 domain memory space
+   */
+  setdbat(1, PCI1_MEM_BASE, PCI1_MEM_BASE, 0x10000000, IO_PAGE);
+ 
+  /* Install our own exception handler (needs PCI) */
+  globalExceptHdl = BSP_exceptionHandler;
+
+
+#if 1
+  /* clear hostbridge errors. MCP signal is not used on the MVME5500
+   * PCI config space scanning code will trip otherwise :-(
+   */
+  _BSP_clear_hostbridge_errors(0, 1 /*quiet*/);
+#endif
 
 #ifdef SHOW_MORE_INIT_SETTINGS
@@ -470,4 +462,3 @@
   printk("Exit from bspstart\n");
 #endif
-
-}
+}
Index: c/src/lib/libbsp/powerpc/mvme5500/startup/pgtbl_activate.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/startup/pgtbl_activate.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/startup/pgtbl_activate.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -12,4 +12,5 @@
 /* Author: Till Straumann, <strauman@slac.stanford.edu>, 4/2002 
  * Kate Feng <feng1@bnl.gov> ported it to MVME5500, 4/2004
+ *
  */
 
Index: c/src/lib/libbsp/powerpc/mvme5500/startup/reboot.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/startup/reboot.c	(revision e1be2b30ad3b43c28cba087614a6ebca6356445e)
+++ c/src/lib/libbsp/powerpc/mvme5500/startup/reboot.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -1,2 +1,8 @@
+/* Copyright 2003, Shuchen Kate Feng <feng1@bnl.gov>,
+ *                    NSLS,Brookhaven National Laboratory
+ *
+ * Ported it from powerpc/shared/console/reboot.c for mvme5500
+ *
+ */
 #include <rtems.h>
 #include <bsp.h>
@@ -13,4 +19,4 @@
   printk("RTEMS terminated; Rebooting ...\n");
   /* Mvme5500 board reset : 2004 S. Kate Feng <feng1@bnl.gov>  */
-  out_8((volatile unsigned char*) (GT64260_DEV1_BASE +2), 0x80);
+  out_8((volatile unsigned char*) (GT64x60_DEV1_BASE +2), 0x80);
 }
Index: c/src/lib/libbsp/powerpc/mvme5500/vme/vmeconfig.c
===================================================================
--- c/src/lib/libbsp/powerpc/mvme5500/vme/vmeconfig.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
+++ c/src/lib/libbsp/powerpc/mvme5500/vme/vmeconfig.c	(revision d7196bfd6696be61880fff7db8ca4de044c30748)
@@ -0,0 +1,132 @@
+/* vmeconfig.c,v 1.1.2.2 2003/03/25 16:46:01 joel Exp */
+
+/* Standard VME bridge configuration for PPC boards */
+
+/* Copyright Author: Till Straumann <strauman@slac.stanford.edu>, 3/2002 */
+
+/* Copyright 2004, Brookhaven National Lab. and S. Kate Feng <feng1@bnl.gov> 
+ * Modified to support the MVME5500, 3/2004
+ */
+
+#include <bsp.h>
+#include <bsp/VME.h>
+#include <bsp/VMEConfig.h>
+#include <bsp/vmeUniverse.h>
+#include <bsp/irq.h>
+#include <libcpu/bat.h>
+
+/* Use a weak alias for the VME configuration.
+ * This permits individual applications to override
+ * this routine.
+ * They may even create an 'empty'
+ *
+ *    void BSP_vme_config(void) {}
+ *
+ * which will avoid linking in the Universe driver
+ * at all :-).
+ */
+
+void BSP_vme_config(void) __attribute__ (( weak, alias("__BSP_default_vme_config") ));
+
+/* translate through host bridge and vme master window of vme bridge */
+int
+BSP_vme2local_adrs(unsigned long am, unsigned long vmeaddr, unsigned long *plocaladdr)
+{
+    int rval=vmeUniverseXlateAddr(1,0,am,vmeaddr,plocaladdr);
+    *plocaladdr+=PCI_MEM_BASE;
+    return rval;
+}
+
+/* how a CPU address is mapped to the VME bus (if at all) */
+int
+BSP_local2vme_adrs(unsigned long am, unsigned long localaddr, unsigned long *pvmeaddr)
+{
+  return vmeUniverseXlateAddr(0, 0, am,localaddr+PCI_DRAM_OFFSET,pvmeaddr);
+}
+
+int BSP_installVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *arg)
+{
+  return(vmeUniverseInstallISR(vector, handler, arg));
+}
+
+int
+BSP_removeVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *arg)
+{
+  return(vmeUniverseRemoveISR(vector, handler, arg));
+}
+
+/* retrieve the currently installed ISR for a given vector */
+BSP_VME_ISR_t BSP_getVME_isr(unsigned long vector, void **parg)
+{
+  return(vmeUniverseISRGet(vector, parg));
+}
+
+int BSP_enableVME_int_lvl(unsigned int level)
+{
+  return(vmeUniverseIntEnable(level));
+}
+
+int BSP_disableVME_int_lvl(unsigned int level)
+{
+  return(vmeUniverseIntDisable(level));
+}
+
+
+void
+__BSP_default_vme_config(void)
+{
+
+  vmeUniverseInit();
+  vmeUniverseReset();
+
+  /* setup a PCI0 area to map the VME bus */
+  setdbat(0,_VME_A32_WIN0_ON_PCI, _VME_A32_WIN0_ON_PCI, 0x10000000, IO_PAGE);
+
+  /* map VME address ranges */
+  vmeUniverseMasterPortCfg(
+	0,
+	VME_AM_EXT_SUP_DATA,
+	_VME_A32_WIN0_ON_VME,
+	_VME_A32_WIN0_ON_PCI,
+	0x0F000000);
+  vmeUniverseMasterPortCfg(
+	1,
+	VME_AM_STD_SUP_DATA,
+	0x00000000,
+	_VME_A24_ON_PCI,
+	0x00ff0000);
+  vmeUniverseMasterPortCfg(
+	2,
+	VME_AM_SUP_SHORT_IO,
+	0x00000000,
+	_VME_A16_ON_PCI,
+	0x00010000);
+
+#ifdef _VME_DRAM_OFFSET
+  /* map our memory to VME */
+  vmeUniverseSlavePortCfg(
+	0,
+	VME_AM_EXT_SUP_DATA| VME_AM_IS_MEMORY,
+	_VME_DRAM_OFFSET,
+	PCI_DRAM_OFFSET,
+	BSP_mem_size);
+
+  /* make sure the host bridge PCI master is enabled */
+  vmeUniverseWriteReg(
+	vmeUniverseReadReg(UNIV_REGOFF_PCI_CSR) | UNIV_PCI_CSR_BM,
+	UNIV_REGOFF_PCI_CSR);
+#endif
+
+  /* stdio is not yet initialized; the driver will revert to printk */
+  vmeUniverseMasterPortsShow(0);
+  vmeUniverseSlavePortsShow(0);
+
+  /* install the VME insterrupt manager */
+  vmeUniverseInstallIrqMgrAlt(1,
+			0, BSP_GPP_IRQ_LOWEST_OFFSET + 12,
+			1, BSP_GPP_IRQ_LOWEST_OFFSET + 13,
+			2, BSP_GPP_IRQ_LOWEST_OFFSET + 14,
+			3, BSP_GPP_IRQ_LOWEST_OFFSET + 15,
+			-1); 
+  
+}
