Back to home page

LXR

 
 

    


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

0001 /* MotLoad VPD format */
0002 
0003 /*
0004 VPD = "MOTOROLA" , { field }
0005 
0006 field = type, length, { data }
0007 */
0008 
0009 /*
0010  * Authorship
0011  * ----------
0012  * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was
0013  *     created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
0014  *     Stanford Linear Accelerator Center, Stanford University.
0015  *
0016  * Acknowledgement of sponsorship
0017  * ------------------------------
0018  * The 'beatnik' BSP was produced by
0019  *     the Stanford Linear Accelerator Center, Stanford University,
0020  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0021  *
0022  * Government disclaimer of liability
0023  * ----------------------------------
0024  * Neither the United States nor the United States Department of Energy,
0025  * nor any of their employees, makes any warranty, express or implied, or
0026  * assumes any legal liability or responsibility for the accuracy,
0027  * completeness, or usefulness of any data, apparatus, product, or process
0028  * disclosed, or represents that its use would not infringe privately owned
0029  * rights.
0030  *
0031  * Stanford disclaimer of liability
0032  * --------------------------------
0033  * Stanford University makes no representations or warranties, express or
0034  * implied, nor assumes any liability for the use of this software.
0035  *
0036  * Stanford disclaimer of copyright
0037  * --------------------------------
0038  * Stanford University, owner of the copyright, hereby disclaims its
0039  * copyright and all other rights in this software.  Hence, anyone may
0040  * freely use it for any purpose without restriction.
0041  *
0042  * Maintenance of notices
0043  * ----------------------
0044  * In the interest of clarity regarding the origin and status of this
0045  * SLAC software, this and all the preceding Stanford University notices
0046  * are to remain affixed to any copy or derivative of this software made
0047  * or distributed by the recipient and are to be affixed to any copy of
0048  * software made or distributed by the recipient that contains a copy or
0049  * derivative of this software.
0050  *
0051  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0052  */
0053 
0054 #include <unistd.h>
0055 #include <rtems.h>
0056 #include <rtems/score/sysstate.h>
0057 #include <string.h>
0058 #include <sys/fcntl.h>
0059 #include <bsp.h>
0060 
0061 #include <bsp/vpd.h>
0062 
0063 /* FIXME XXX: all of the early i2c reading stuff should
0064  * be moved elsewhere. This file should only deal with
0065  * VPD.
0066  */
0067 #include <rtems/libi2c.h>
0068 #define dev         BSP_I2C_BUS_DESCRIPTOR
0069 extern rtems_libi2c_bus_t *dev;
0070 
0071 #define init        dev->ops->init
0072 #define start       dev->ops->send_start
0073 #define addr        dev->ops->send_addr
0074 #define write_bytes dev->ops->write_bytes
0075 
0076 #define I2C_READ        1
0077 #define I2C_WRITE       0
0078 
0079 static ssize_t  (*read_bytes)(int fd, void *buf, size_t len) = 0;
0080 
0081 static ssize_t early_fp = 0;
0082 
0083 static ssize_t early_read(int fd, void *buf, size_t len)
0084 {
0085 ssize_t rval;
0086 rtems_libi2c_bus_t *d = (rtems_libi2c_bus_t*)fd;
0087 uint8_t            fp[2];
0088 
0089     /* Always send the file-pointer. Some i2c controllers
0090      * (mpc8540) have 'pipelined' operation and do extra
0091      * read cycles so that a sequence of
0092      * 'read_bytes', 'read_bytes' does NOT return the true
0093      * sequence of bytes :-(
0094      */
0095     start(d);
0096     addr(d, BSP_VPD_I2C_ADDR, I2C_WRITE);
0097     fp[0] = early_fp>>8;
0098     fp[1] = early_fp;
0099     write_bytes(dev,fp,2);
0100 
0101     start(d);
0102     addr(d, BSP_VPD_I2C_ADDR, I2C_READ);
0103     rval = d->ops->read_bytes(d, buf, len);
0104     if ( rval > 0 )
0105         early_fp += rval;
0106     return rval;
0107 }
0108 
0109 static int early_close(int fd)
0110 {
0111 rtems_libi2c_bus_t *d = (rtems_libi2c_bus_t*)fd;
0112     return d->ops->send_stop(d);
0113 }
0114 
0115 static int read_buf(int fd, void *buf, size_t len)
0116 {
0117 int got, rval = 0;
0118     while ( len > 0 ) {
0119         if ( (got = read_bytes(fd, buf+rval, len)) <= 0 )
0120             return -1;
0121         len -= got;
0122         rval+= got;
0123     }
0124     return rval;
0125 }
0126 
0127 /* Not Efficient but simple */
0128 int
0129 BSP_vpdRetrieveFields(VpdBuf data)
0130 {
0131 VpdBuf        b, b1;
0132 VpdKey        k;
0133 int           l,fd = -1, put, got;
0134 int           rval = -1;
0135 unsigned char mot[9];
0136 static int    (*stop)(int fd);
0137 
0138     memset(mot,0,sizeof(mot));
0139 
0140     if ( 0 && _System_state_Is_up(_System_state_Get()) ) {
0141         read_bytes = read;
0142         stop       = close;
0143         fd         = open(BSP_I2C_VPD_EEPROM_DEV_NAME, 0);
0144         if ( fd < 0 )
0145             return -1;
0146     } else {
0147         fd = (int)dev;
0148 /*
0149         init(dev);
0150  *
0151  *   Hangs - probably would need a delay here - just leave motload settings
0152  */
0153 
0154         read_bytes = early_read;
0155         stop       = early_close;
0156     }
0157 
0158     if ( read_bytes(fd, mot, 8) < 8 ) {
0159         goto bail;
0160     }
0161 
0162     if ( strcmp((char*)mot,"MOTOROLA") )
0163         goto bail;
0164 
0165     l = 0;
0166     do {
0167 
0168         /* skip field -- this is not done the first time since l=0 */
0169         while ( l > sizeof(mot) ) {
0170             got = read_buf(fd, mot, sizeof(mot));
0171             if ( got < 1 )
0172                 goto bail;
0173             l -= got;
0174         }
0175         if ( read_buf(fd, mot, l) < 0 )
0176             goto bail;
0177 
0178         /* now get a new header */
0179         if ( read_buf(fd, mot, 2) < 2 )
0180             goto bail;
0181 
0182         k = mot[0];
0183         l = mot[1];
0184 
0185         for ( b = data; b->key != End; b++ ) {
0186             if ( b->key == k && (signed char)b->instance >= 0 ) {
0187                 if ( 0 == b->instance--  ) {
0188                     /* found 'instance' of field 'type' */
0189 
0190                     /* limit to buffer size */
0191                     put = b->buflen > l ? l : b->buflen;
0192                     if ( read_buf(fd, b->buf, put) < put )
0193                         goto bail;
0194 
0195                     /* if this instance is multiply requested, copy the data */
0196                     for ( b1 = b + 1; b1->key != End; b1++ ) {
0197                         if ( b1->key == k && 0 == b1->instance ) {
0198                             b1->instance--;
0199                             /* we dont' handle the case where
0200                              * the first buffer couldn't hold the entire
0201                              * item but this one could...
0202                              */
0203                             memcpy(b1->buf, b->buf, put);
0204                             b1->found = mot[1];
0205                         }
0206                     }
0207 
0208                     l -= put;
0209                     b->found = mot[1];
0210                 }
0211             }
0212         }
0213 
0214     } while ( k != End );
0215 
0216     rval = 0;
0217 
0218 bail:
0219 
0220     stop(fd);
0221     return rval;
0222 }
0223 
0224 int
0225 BSP_vpdRetrieveKey(VpdKey k, void *buf, int len, int inst)
0226 {
0227     VpdBufRec   d[] = {
0228         { key: k, buf: buf, buflen: len, instance: inst },
0229         VPD_END
0230     };
0231     return  BSP_vpdRetrieveFields(d) ? -1 : d[0].found;
0232 }
0233 
0234 /*
0235 005C3000  4D4F544F 524F4C41 0200010D 4D564D45  MOTOROLA....MVME
0236 005C3010  35353030 2D303136 31020C30 312D5733  5500-0161..01-W3
0237 005C3020  38323946 30324803 07373237 39303630  829F02H..7279060
0238 005C3030  05053B9A CA000106 0507F281 55010807  ..;.........U...
0239 005C3040  0001AF12 CA780008 070001AF 12CA7901  .....x........y.
0240 005C3050  09043734 35350A04 D3223DD0 0B0C0089  ..7455..."=.....
0241 005C3060  00181002 02101000 78070B0C FFFFFFFF  ........x.......
0242 005C3070  10020210 10017805 0E0FFFFF FFFFFFFF  ......x.........
0243 005C3080  FFFFFF01 FF01FFFF FF0F0400 03000019  ................
0244 005C3090  0A010107 02030000 000100FF FFFFFFFF  ................
0245 005C30A0  FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  ................
0246 005C30B0  FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  ................
0247 005C30C0  00000000 00000000 00000000 00000000  ................
0248 005C30D0  00000000 00000000 00000000 00000000  ................
0249 005C30E0  00000000 00000000 00000000 00000000  ................
0250 005C30F0  00000000 00000000 00000000 00000000  ................
0251 
0252 Product Identifier                 : MVME5500-0161
0253 Manufacturing Assembly Number      : 01-W3829F02H
0254 Serial Number                      : 7279060
0255 Internal Clock Speed (Hertz)       : 3B9ACA00 (&1000000000)
0256 External Clock Speed (Hertz)       : 07F28155 (&133333333)
0257 Ethernet Address                   : 00 01 AF 12 CA 78 00
0258 Ethernet Address                   : 00 01 AF 12 CA 79 01
0259 Microprocessor Type                : 7455
0260 SROM/EEPROM CRC                    : D3223DD0 (&-752730672)
0261 Flash Memory Configuration         : 00 89 00 18 10 02 02 10
0262                                    : 10 00 78 07
0263 Flash Memory Configuration         : FF FF FF FF 10 02 02 10
0264                                    : 10 01 78 05
0265 L2 Cache Configuration             : FF FF FF FF FF FF FF FF
0266                                    : FF 01 FF 01 FF FF FF
0267 VPD Revision                       : 00 03 00 00
0268 L3 Cache Configuration             : 01 01 07 02 03 00 00 00
0269                                    : 01 00
0270 
0271 
0272 
0273 
0274 0x01889128:  4d4f544f  524f4c41  02000f04  00030000  MOTOROLA........
0275 0x01889138:  060507f2  81550101  0d4d564d  45363130  .....U...MVME610
0276 0x01889148:  302d3031  3631020c  30312d57  33383738  0-0161..01-W3878
0277 0x01889158:  46303144  03073732  33313137  300e0fff  F01D..7231170...
0278 0x01889168:  ffffffff  ffffffff  01ff01ff  ffff190a  ................
0279 0x01889178:  01000002  03000000  01000904  37343537  ............7457
0280 0x01889188:  0a047277  144d0807  0001af13  b53c0008  ..rw.M.......<..
0281 0x01889198:  070001af  13b53d01  0b0c0089  00031002  ......=.........
0282 0x018891a8:  02101000  78080b0c  00890003  10020210  ....x...........
0283 0x018891b8:  10017808  ffffffff  ffffffff  ffffffff  ..x.............
0284 0x018891c8:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0285 0x018891d8:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0286 0x018891e8:  ffffffff  ffffffff                      ........
0287 0x00000000 (0)
0288 
0289 0x003895c0:  4d4f544f  524f4c41  02000f04  00030000  MOTOROLA........
0290 0x003895d0:  060503f9  40aa0101  0d4d564d  45333130  ....@....MVME310
0291 0x003895e0:  302d3132  3633020c  30312d57  33383933  0-1263..01-W3893
0292 0x003895f0:  46303143  03073734  35383831  340e0fff  F01C..7458814...
0293 0x00389600:  ffffffff  ffffffff  01ff01ff  ffff0904  ................
0294 0x00389610:  38353430  0a047129  d2d60807  0001af16  8540..q)........
0295 0x00389620:  e5c50008  070001af  16e5c601  08070001  ................
0296 0x00389630:  af16e5c7  020b0c00  017e2310  02021010  .........~#.....
0297 0x00389640:  006409ff  ffffffff  ffffffff  ffffffff  .d..............
0298 0x00389650:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0299 0x00389660:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0300 0x00389670:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0301 0x00389680:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0302 0x00389690:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0303 0x003896a0:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0304 0x003896b0:  ffffffff  ffffffff  ffffffff  ffffffff  ................
0305 
0306 MVME3100> vpdDisplay
0307 VPD Revision                       : 00 03 00 00
0308 External Clock Speed (Hertz)       : 03F940AA (&66666666)
0309 Product Identifier                 : MVME3100-1263
0310 Manufacturing Assembly Number      : 01-W3893F01C
0311 Serial Number                      : 7458814
0312 L2 Cache Configuration             : FF FF FF FF FF FF FF FF
0313                                    : FF 01 FF 01 FF FF FF
0314 Microprocessor Type                : 8540
0315 SROM/EEPROM CRC                    : 7129D2D6 (&1898566358)
0316 Ethernet Address                   : 00 01 AF 16 E5 C5 00
0317 Ethernet Address                   : 00 01 AF 16 E5 C6 01
0318 Ethernet Address                   : 00 01 AF 16 E5 C7 02
0319 Flash Memory Configuration         : 00 01 7E 23 10 02 02 10
0320                                    : 10 00 64 09
0321 
0322 */