source: rtems/bsps/powerpc/shared/start/vpd.c @ afa90ee5

5
Last change on this file since afa90ee5 was afa90ee5, checked in by Sebastian Huber <sebastian.huber@…>, on 04/24/18 at 05:24:52

bsps: Move vpd.c to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 10.4 KB
Line 
1/* MotLoad VPD format */
2
3/*
4VPD = "MOTOROLA" , { field }
5
6field = type, length, { data }
7*/
8
9/*
10 * Authorship
11 * ----------
12 * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was
13 *     created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
14 *         Stanford Linear Accelerator Center, Stanford University.
15 *
16 * Acknowledgement of sponsorship
17 * ------------------------------
18 * The 'beatnik' BSP was produced by
19 *     the Stanford Linear Accelerator Center, Stanford University,
20 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
21 *
22 * Government disclaimer of liability
23 * ----------------------------------
24 * Neither the United States nor the United States Department of Energy,
25 * nor any of their employees, makes any warranty, express or implied, or
26 * assumes any legal liability or responsibility for the accuracy,
27 * completeness, or usefulness of any data, apparatus, product, or process
28 * disclosed, or represents that its use would not infringe privately owned
29 * rights.
30 *
31 * Stanford disclaimer of liability
32 * --------------------------------
33 * Stanford University makes no representations or warranties, express or
34 * implied, nor assumes any liability for the use of this software.
35 *
36 * Stanford disclaimer of copyright
37 * --------------------------------
38 * Stanford University, owner of the copyright, hereby disclaims its
39 * copyright and all other rights in this software.  Hence, anyone may
40 * freely use it for any purpose without restriction.
41 *
42 * Maintenance of notices
43 * ----------------------
44 * In the interest of clarity regarding the origin and status of this
45 * SLAC software, this and all the preceding Stanford University notices
46 * are to remain affixed to any copy or derivative of this software made
47 * or distributed by the recipient and are to be affixed to any copy of
48 * software made or distributed by the recipient that contains a copy or
49 * derivative of this software.
50 *
51 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
52 */
53
54#include <unistd.h>
55#include <rtems.h>
56#include <rtems/score/sysstate.h>
57#include <string.h>
58#include <sys/fcntl.h>
59#include <bsp.h>
60
61#include <bsp/vpd.h>
62
63/* FIXME XXX: all of the early i2c reading stuff should
64 * be moved elsewhere. This file should only deal with
65 * VPD.
66 */
67#include <rtems/libi2c.h>
68#define dev                     BSP_I2C_BUS_DESCRIPTOR
69extern rtems_libi2c_bus_t *dev;
70
71#define init            dev->ops->init
72#define start           dev->ops->send_start
73#define addr            dev->ops->send_addr
74#define write_bytes     dev->ops->write_bytes
75
76#define I2C_READ                1
77#define I2C_WRITE               0
78
79static ssize_t  (*read_bytes)(int fd, void *buf, size_t len) = 0;
80
81static ssize_t early_fp = 0;
82
83static ssize_t early_read(int fd, void *buf, size_t len)
84{
85ssize_t rval;
86rtems_libi2c_bus_t *d = (rtems_libi2c_bus_t*)fd;
87uint8_t            fp[2];
88
89        /* Always send the file-pointer. Some i2c controllers
90         * (mpc8540) have 'pipelined' operation and do extra
91         * read cycles so that a sequence of
92         * 'read_bytes', 'read_bytes' does NOT return the true
93         * sequence of bytes :-(
94         */
95        start(d);
96        addr(d, BSP_VPD_I2C_ADDR, I2C_WRITE);
97        fp[0] = early_fp>>8;
98        fp[1] = early_fp;
99        write_bytes(dev,fp,2);
100
101        start(d);
102        addr(d, BSP_VPD_I2C_ADDR, I2C_READ);
103        rval = d->ops->read_bytes(d, buf, len);
104        if ( rval > 0 )
105                early_fp += rval;
106        return rval;
107}
108
109static int early_close(int fd)
110{
111rtems_libi2c_bus_t *d = (rtems_libi2c_bus_t*)fd;
112        return d->ops->send_stop(d);
113}
114
115static int read_buf(int fd, void *buf, size_t len)
116{
117int got, rval = 0;
118        while ( len > 0 ) {
119                if ( (got = read_bytes(fd, buf+rval, len)) <= 0 )
120                        return -1;
121                len -= got;
122                rval+= got;
123        }
124        return rval;
125}
126
127/* Not Efficient but simple */
128int
129BSP_vpdRetrieveFields(VpdBuf data)
130{
131VpdBuf        b, b1;
132VpdKey        k;
133int                   l,fd = -1, put, got;
134int           rval = -1;
135unsigned char mot[9];
136static int        (*stop)(int fd);
137
138        memset(mot,0,sizeof(mot));
139
140        if ( 0 && _System_state_Is_up(_System_state_Get()) ) {
141                read_bytes = read;
142                stop       = close;
143                fd         = open(BSP_I2C_VPD_EEPROM_DEV_NAME, 0);
144                if ( fd < 0 )
145                        return -1;
146        } else {
147                fd = (int)dev;
148/*
149                init(dev);
150 *
151 *       Hangs - probably would need a delay here - just leave motload settings
152 */
153
154                read_bytes = early_read;
155                stop       = early_close;
156        }
157
158        if ( read_bytes(fd, mot, 8) < 8 ) {
159                goto bail;
160        }
161
162        if ( strcmp((char*)mot,"MOTOROLA") )
163                goto bail;
164
165        l = 0;
166        do {
167
168                /* skip field -- this is not done the first time since l=0 */
169                while ( l > sizeof(mot) ) {
170                        got = read_buf(fd, mot, sizeof(mot));
171                        if ( got < 1 )
172                                goto bail;
173                        l -= got;
174                }
175                if ( read_buf(fd, mot, l) < 0 )
176                        goto bail;
177
178                /* now get a new header */
179                if ( read_buf(fd, mot, 2) < 2 )
180                        goto bail;
181
182                k = mot[0];
183                l = mot[1];
184
185                for ( b = data; b->key != End; b++ ) {
186                        if ( b->key == k && (signed char)b->instance >= 0 ) {
187                                if ( 0 == b->instance--  ) {
188                                        /* found 'instance' of field 'type' */
189
190                                        /* limit to buffer size */
191                                        put = b->buflen > l ? l : b->buflen;
192                                        if ( read_buf(fd, b->buf, put) < put )
193                                                goto bail;
194
195                                        /* if this instance is multiply requested, copy the data */
196                                        for ( b1 = b + 1; b1->key != End; b1++ ) {
197                                                if ( b1->key == k && 0 == b1->instance ) {
198                                                        b1->instance--;
199                                                        /* we dont' handle the case where
200                                                         * the first buffer couldn't hold the entire
201                                                         * item but this one could...
202                                                         */
203                                                        memcpy(b1->buf, b->buf, put);
204                                                        b1->found = mot[1];
205                                                }
206                                        }
207
208                                        l -= put;
209                                        b->found = mot[1];
210                                }
211                        }
212                }
213
214        } while ( k != End );
215
216        rval = 0;
217
218bail:
219
220        stop(fd);
221        return rval;
222}
223
224int
225BSP_vpdRetrieveKey(VpdKey k, void *buf, int len, int inst)
226{
227        VpdBufRec       d[] = {
228                { key: k, buf: buf, buflen: len, instance: inst },
229                VPD_END
230        };
231        return  BSP_vpdRetrieveFields(d) ? -1 : d[0].found;
232}
233
234/*
235005C3000  4D4F544F 524F4C41 0200010D 4D564D45  MOTOROLA....MVME
236005C3010  35353030 2D303136 31020C30 312D5733  5500-0161..01-W3
237005C3020  38323946 30324803 07373237 39303630  829F02H..7279060
238005C3030  05053B9A CA000106 0507F281 55010807  ..;.........U...
239005C3040  0001AF12 CA780008 070001AF 12CA7901  .....x........y.
240005C3050  09043734 35350A04 D3223DD0 0B0C0089  ..7455..."=.....
241005C3060  00181002 02101000 78070B0C FFFFFFFF  ........x.......
242005C3070  10020210 10017805 0E0FFFFF FFFFFFFF  ......x.........
243005C3080  FFFFFF01 FF01FFFF FF0F0400 03000019  ................
244005C3090  0A010107 02030000 000100FF FFFFFFFF  ................
245005C30A0  FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  ................
246005C30B0  FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF  ................
247005C30C0  00000000 00000000 00000000 00000000  ................
248005C30D0  00000000 00000000 00000000 00000000  ................
249005C30E0  00000000 00000000 00000000 00000000  ................
250005C30F0  00000000 00000000 00000000 00000000  ................
251
252Product Identifier                 : MVME5500-0161
253Manufacturing Assembly Number      : 01-W3829F02H
254Serial Number                      : 7279060
255Internal Clock Speed (Hertz)       : 3B9ACA00 (&1000000000)
256External Clock Speed (Hertz)       : 07F28155 (&133333333)
257Ethernet Address                   : 00 01 AF 12 CA 78 00
258Ethernet Address                   : 00 01 AF 12 CA 79 01
259Microprocessor Type                : 7455
260SROM/EEPROM CRC                    : D3223DD0 (&-752730672)
261Flash Memory Configuration         : 00 89 00 18 10 02 02 10
262                                   : 10 00 78 07
263Flash Memory Configuration         : FF FF FF FF 10 02 02 10
264                                   : 10 01 78 05
265L2 Cache Configuration             : FF FF FF FF FF FF FF FF
266                                   : FF 01 FF 01 FF FF FF
267VPD Revision                       : 00 03 00 00
268L3 Cache Configuration             : 01 01 07 02 03 00 00 00
269                                   : 01 00
270
271
272
273
2740x01889128:  4d4f544f  524f4c41  02000f04  00030000  MOTOROLA........
2750x01889138:  060507f2  81550101  0d4d564d  45363130  .....U...MVME610
2760x01889148:  302d3031  3631020c  30312d57  33383738  0-0161..01-W3878
2770x01889158:  46303144  03073732  33313137  300e0fff  F01D..7231170...
2780x01889168:  ffffffff  ffffffff  01ff01ff  ffff190a  ................
2790x01889178:  01000002  03000000  01000904  37343537  ............7457
2800x01889188:  0a047277  144d0807  0001af13  b53c0008  ..rw.M.......<..
2810x01889198:  070001af  13b53d01  0b0c0089  00031002  ......=.........
2820x018891a8:  02101000  78080b0c  00890003  10020210  ....x...........
2830x018891b8:  10017808  ffffffff  ffffffff  ffffffff  ..x.............
2840x018891c8:  ffffffff  ffffffff  ffffffff  ffffffff  ................
2850x018891d8:  ffffffff  ffffffff  ffffffff  ffffffff  ................
2860x018891e8:  ffffffff  ffffffff                      ........
2870x00000000 (0)
288
2890x003895c0:  4d4f544f  524f4c41  02000f04  00030000  MOTOROLA........
2900x003895d0:  060503f9  40aa0101  0d4d564d  45333130  ....@....MVME310
2910x003895e0:  302d3132  3633020c  30312d57  33383933  0-1263..01-W3893
2920x003895f0:  46303143  03073734  35383831  340e0fff  F01C..7458814...
2930x00389600:  ffffffff  ffffffff  01ff01ff  ffff0904  ................
2940x00389610:  38353430  0a047129  d2d60807  0001af16  8540..q)........
2950x00389620:  e5c50008  070001af  16e5c601  08070001  ................
2960x00389630:  af16e5c7  020b0c00  017e2310  02021010  .........~#.....
2970x00389640:  006409ff  ffffffff  ffffffff  ffffffff  .d..............
2980x00389650:  ffffffff  ffffffff  ffffffff  ffffffff  ................
2990x00389660:  ffffffff  ffffffff  ffffffff  ffffffff  ................
3000x00389670:  ffffffff  ffffffff  ffffffff  ffffffff  ................
3010x00389680:  ffffffff  ffffffff  ffffffff  ffffffff  ................
3020x00389690:  ffffffff  ffffffff  ffffffff  ffffffff  ................
3030x003896a0:  ffffffff  ffffffff  ffffffff  ffffffff  ................
3040x003896b0:  ffffffff  ffffffff  ffffffff  ffffffff  ................
305
306MVME3100> vpdDisplay
307VPD Revision                       : 00 03 00 00
308External Clock Speed (Hertz)       : 03F940AA (&66666666)
309Product Identifier                 : MVME3100-1263
310Manufacturing Assembly Number      : 01-W3893F01C
311Serial Number                      : 7458814
312L2 Cache Configuration             : FF FF FF FF FF FF FF FF
313                                   : FF 01 FF 01 FF FF FF
314Microprocessor Type                : 8540
315SROM/EEPROM CRC                    : 7129D2D6 (&1898566358)
316Ethernet Address                   : 00 01 AF 16 E5 C5 00
317Ethernet Address                   : 00 01 AF 16 E5 C6 01
318Ethernet Address                   : 00 01 AF 16 E5 C7 02
319Flash Memory Configuration         : 00 01 7E 23 10 02 02 10
320                                                                   : 10 00 64 09
321
322*/
Note: See TracBrowser for help on using the repository browser.