Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:51

0001 /* 
0002  * Authorship
0003  * ----------
0004  * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was
0005  *     created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
0006  *     Stanford Linear Accelerator Center, Stanford University.
0007  * 
0008  * Acknowledgement of sponsorship
0009  * ------------------------------
0010  * The 'beatnik' BSP was produced by
0011  *     the Stanford Linear Accelerator Center, Stanford University,
0012  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0013  * 
0014  * Government disclaimer of liability
0015  * ----------------------------------
0016  * Neither the United States nor the United States Department of Energy,
0017  * nor any of their employees, makes any warranty, express or implied, or
0018  * assumes any legal liability or responsibility for the accuracy,
0019  * completeness, or usefulness of any data, apparatus, product, or process
0020  * disclosed, or represents that its use would not infringe privately owned
0021  * rights.
0022  * 
0023  * Stanford disclaimer of liability
0024  * --------------------------------
0025  * Stanford University makes no representations or warranties, express or
0026  * implied, nor assumes any liability for the use of this software.
0027  * 
0028  * Stanford disclaimer of copyright
0029  * --------------------------------
0030  * Stanford University, owner of the copyright, hereby disclaims its
0031  * copyright and all other rights in this software.  Hence, anyone may
0032  * freely use it for any purpose without restriction.  
0033  * 
0034  * Maintenance of notices
0035  * ----------------------
0036  * In the interest of clarity regarding the origin and status of this
0037  * SLAC software, this and all the preceding Stanford University notices
0038  * are to remain affixed to any copy or derivative of this software made
0039  * or distributed by the recipient and are to be affixed to any copy of
0040  * software made or distributed by the recipient that contains a copy or
0041  * derivative of this software.
0042  * 
0043  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0044  */ 
0045 
0046 #include <bsp.h>
0047 #include <stdio.h>
0048 #include <inttypes.h>
0049 
0050 #define STATIC static
0051 
0052 #include <bsp/flashPgmPvt.h>
0053 
0054 /* MVME Board Specifica; board status reg. 2 where write-enable is controlled... */
0055 
0056 #define SYS_FLASHA_WP       (1<<5)
0057 #define SYS_FBOOTB_WP       (1<<3)
0058 #define SYS_FBA_WP_HDR      (1<<2)
0059 #define SYS_FBOOTB_WP_HDR   (1<<1)
0060 
0061 #define SYS_STATUS_2_REG    (1)
0062 
0063 /* Forward Declarations */
0064 STATIC struct bankdesc *
0065 bankcheck(int bank, int quiet);
0066 
0067 static int
0068 flash_wp(int bank, int enbl);
0069 
0070 STATIC uint32_t
0071 read_us_timer(void);
0072 
0073 /* Global Variables     */
0074 
0075 /* motload memory map   */
0076 static struct bankdesc mvme5500Flash[] = {
0077     { 0, 2                   }, /* first entry gives number of entries */
0078     { 0xf2000000, 0x08000000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
0079     { 0xff800000, 0x00800000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
0080 };
0081 
0082 /* motload memory map */
0083 static struct bankdesc mvme6100Flash[] = {
0084     { 0, 2                   }, /* first entry gives number of entries */
0085     { 0xf4000000, 0x04000000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
0086     { 0xf8000000, 0x04000000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
0087 };
0088 
0089 struct flash_bsp_ops BSP_flashBspOps = {
0090     bankcheck    : bankcheck,
0091     flash_wp     : flash_wp,
0092     read_us_timer: read_us_timer,
0093 };
0094 
0095 /* set (enbl:1), clear (enbl:0) or query (enbl:-1) write protection
0096  * 
0097  * RETURNS 0 on success, nonzero on error.
0098  */
0099 static int
0100 flash_wp(int bank, int enbl)
0101 {
0102 BSP_BoardType b;
0103 A8            p;
0104 unsigned char   hwp = 0, swp;
0105 
0106     /* validate 'bank' argument */
0107     if ( !bankcheck( bank, 0 ) )
0108         return -1;
0109 
0110     switch ( (b=BSP_getBoardType()) ) {
0111         default:
0112             fprintf(stderr,"Unknown board type %i\n",b);
0113             return -1;
0114             
0115         case MVME5500:
0116             /* bit enables both banks; no readback of jumper available */
0117             p = (A8)(BSP_MV64x60_DEV1_BASE + SYS_STATUS_2_REG);
0118             swp = SYS_FLASHA_WP;
0119             break;
0120 
0121         case MVME6100:
0122             {
0123 
0124                 p = (A8)(BSP_MV64x60_DEV1_BASE + SYS_STATUS_2_REG);
0125                 if ( 0 == bank ) {
0126                     hwp = SYS_FBA_WP_HDR;
0127                     swp = SYS_FLASHA_WP;
0128                 } else {
0129                     hwp = SYS_FBOOTB_WP_HDR;
0130                     swp = SYS_FBOOTB_WP;
0131                 }
0132                 if ( enbl && (*p & hwp) ) {
0133                     fprintf(stderr,"HW write protection enabled (jumper)\n");
0134                     return -1;
0135                 }
0136             }
0137             break;
0138     }
0139     if ( -1 == enbl ) {
0140         /* query */
0141         return *p & (swp | hwp);
0142     } else {
0143         if ( enbl ) {
0144             *p |= swp;
0145         } else {
0146             *p &= ~swp;
0147         }
0148     }
0149     return 0;
0150 }
0151 
0152 /* Lookup bank description in table */
0153 STATIC struct bankdesc *
0154 bankcheck(int bank, int quiet)
0155 {
0156 struct bankdesc *b;
0157     switch ( BSP_getBoardType() ) {
0158         case MVME5500:  b = mvme5500Flash; break;
0159         case MVME6100:  b = mvme6100Flash; break;
0160         default:
0161             fprintf(stderr,"Unknown/unsupported board type\n");
0162             return 0;
0163     }
0164     if ( bank >= b->size || bank < 0 ) {
0165         if ( !quiet )
0166             fprintf(stderr,"Invalid flash bank #: %i; (too big)\n", bank);
0167         return 0;
0168     }
0169     return b + bank + 1;
0170 }
0171 
0172 STATIC uint32_t read_us_timer(void)
0173 {
0174 uint32_t now, mhz;
0175 
0176     /* we burn cycles anyways... */
0177     mhz = BSP_bus_frequency/BSP_time_base_divisor/1000;
0178 
0179     asm volatile("mftb %0":"=r"(now));
0180 
0181     return now/mhz;
0182 }