1 | /* MotLoad VPD format */ |
---|
2 | |
---|
3 | /* |
---|
4 | VPD = "MOTOROLA" , { field } |
---|
5 | |
---|
6 | field = 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 |
---|
69 | extern 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 | |
---|
79 | static ssize_t (*read_bytes)(int fd, void *buf, size_t len) = 0; |
---|
80 | |
---|
81 | static ssize_t early_fp = 0; |
---|
82 | |
---|
83 | static ssize_t early_read(int fd, void *buf, size_t len) |
---|
84 | { |
---|
85 | ssize_t rval; |
---|
86 | rtems_libi2c_bus_t *d = (rtems_libi2c_bus_t*)fd; |
---|
87 | uint8_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 | |
---|
109 | static int early_close(int fd) |
---|
110 | { |
---|
111 | rtems_libi2c_bus_t *d = (rtems_libi2c_bus_t*)fd; |
---|
112 | return d->ops->send_stop(d); |
---|
113 | } |
---|
114 | |
---|
115 | static int read_buf(int fd, void *buf, size_t len) |
---|
116 | { |
---|
117 | int 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 */ |
---|
128 | int |
---|
129 | BSP_vpdRetrieveFields(VpdBuf data) |
---|
130 | { |
---|
131 | VpdBuf b, b1; |
---|
132 | VpdKey k; |
---|
133 | int l,fd = -1, put, got; |
---|
134 | int rval = -1; |
---|
135 | unsigned char mot[9]; |
---|
136 | static 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 | |
---|
218 | bail: |
---|
219 | |
---|
220 | stop(fd); |
---|
221 | return rval; |
---|
222 | } |
---|
223 | |
---|
224 | int |
---|
225 | BSP_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 | /* |
---|
235 | 005C3000 4D4F544F 524F4C41 0200010D 4D564D45 MOTOROLA....MVME |
---|
236 | 005C3010 35353030 2D303136 31020C30 312D5733 5500-0161..01-W3 |
---|
237 | 005C3020 38323946 30324803 07373237 39303630 829F02H..7279060 |
---|
238 | 005C3030 05053B9A CA000106 0507F281 55010807 ..;.........U... |
---|
239 | 005C3040 0001AF12 CA780008 070001AF 12CA7901 .....x........y. |
---|
240 | 005C3050 09043734 35350A04 D3223DD0 0B0C0089 ..7455..."=..... |
---|
241 | 005C3060 00181002 02101000 78070B0C FFFFFFFF ........x....... |
---|
242 | 005C3070 10020210 10017805 0E0FFFFF FFFFFFFF ......x......... |
---|
243 | 005C3080 FFFFFF01 FF01FFFF FF0F0400 03000019 ................ |
---|
244 | 005C3090 0A010107 02030000 000100FF FFFFFFFF ................ |
---|
245 | 005C30A0 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF ................ |
---|
246 | 005C30B0 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF ................ |
---|
247 | 005C30C0 00000000 00000000 00000000 00000000 ................ |
---|
248 | 005C30D0 00000000 00000000 00000000 00000000 ................ |
---|
249 | 005C30E0 00000000 00000000 00000000 00000000 ................ |
---|
250 | 005C30F0 00000000 00000000 00000000 00000000 ................ |
---|
251 | |
---|
252 | Product Identifier : MVME5500-0161 |
---|
253 | Manufacturing Assembly Number : 01-W3829F02H |
---|
254 | Serial Number : 7279060 |
---|
255 | Internal Clock Speed (Hertz) : 3B9ACA00 (&1000000000) |
---|
256 | External Clock Speed (Hertz) : 07F28155 (&133333333) |
---|
257 | Ethernet Address : 00 01 AF 12 CA 78 00 |
---|
258 | Ethernet Address : 00 01 AF 12 CA 79 01 |
---|
259 | Microprocessor Type : 7455 |
---|
260 | SROM/EEPROM CRC : D3223DD0 (&-752730672) |
---|
261 | Flash Memory Configuration : 00 89 00 18 10 02 02 10 |
---|
262 | : 10 00 78 07 |
---|
263 | Flash Memory Configuration : FF FF FF FF 10 02 02 10 |
---|
264 | : 10 01 78 05 |
---|
265 | L2 Cache Configuration : FF FF FF FF FF FF FF FF |
---|
266 | : FF 01 FF 01 FF FF FF |
---|
267 | VPD Revision : 00 03 00 00 |
---|
268 | L3 Cache Configuration : 01 01 07 02 03 00 00 00 |
---|
269 | : 01 00 |
---|
270 | |
---|
271 | |
---|
272 | |
---|
273 | |
---|
274 | 0x01889128: 4d4f544f 524f4c41 02000f04 00030000 MOTOROLA........ |
---|
275 | 0x01889138: 060507f2 81550101 0d4d564d 45363130 .....U...MVME610 |
---|
276 | 0x01889148: 302d3031 3631020c 30312d57 33383738 0-0161..01-W3878 |
---|
277 | 0x01889158: 46303144 03073732 33313137 300e0fff F01D..7231170... |
---|
278 | 0x01889168: ffffffff ffffffff 01ff01ff ffff190a ................ |
---|
279 | 0x01889178: 01000002 03000000 01000904 37343537 ............7457 |
---|
280 | 0x01889188: 0a047277 144d0807 0001af13 b53c0008 ..rw.M.......<.. |
---|
281 | 0x01889198: 070001af 13b53d01 0b0c0089 00031002 ......=......... |
---|
282 | 0x018891a8: 02101000 78080b0c 00890003 10020210 ....x........... |
---|
283 | 0x018891b8: 10017808 ffffffff ffffffff ffffffff ..x............. |
---|
284 | 0x018891c8: ffffffff ffffffff ffffffff ffffffff ................ |
---|
285 | 0x018891d8: ffffffff ffffffff ffffffff ffffffff ................ |
---|
286 | 0x018891e8: ffffffff ffffffff ........ |
---|
287 | 0x00000000 (0) |
---|
288 | |
---|
289 | 0x003895c0: 4d4f544f 524f4c41 02000f04 00030000 MOTOROLA........ |
---|
290 | 0x003895d0: 060503f9 40aa0101 0d4d564d 45333130 ....@....MVME310 |
---|
291 | 0x003895e0: 302d3132 3633020c 30312d57 33383933 0-1263..01-W3893 |
---|
292 | 0x003895f0: 46303143 03073734 35383831 340e0fff F01C..7458814... |
---|
293 | 0x00389600: ffffffff ffffffff 01ff01ff ffff0904 ................ |
---|
294 | 0x00389610: 38353430 0a047129 d2d60807 0001af16 8540..q)........ |
---|
295 | 0x00389620: e5c50008 070001af 16e5c601 08070001 ................ |
---|
296 | 0x00389630: af16e5c7 020b0c00 017e2310 02021010 .........~#..... |
---|
297 | 0x00389640: 006409ff ffffffff ffffffff ffffffff .d.............. |
---|
298 | 0x00389650: ffffffff ffffffff ffffffff ffffffff ................ |
---|
299 | 0x00389660: ffffffff ffffffff ffffffff ffffffff ................ |
---|
300 | 0x00389670: ffffffff ffffffff ffffffff ffffffff ................ |
---|
301 | 0x00389680: ffffffff ffffffff ffffffff ffffffff ................ |
---|
302 | 0x00389690: ffffffff ffffffff ffffffff ffffffff ................ |
---|
303 | 0x003896a0: ffffffff ffffffff ffffffff ffffffff ................ |
---|
304 | 0x003896b0: ffffffff ffffffff ffffffff ffffffff ................ |
---|
305 | |
---|
306 | MVME3100> vpdDisplay |
---|
307 | VPD Revision : 00 03 00 00 |
---|
308 | External Clock Speed (Hertz) : 03F940AA (&66666666) |
---|
309 | Product Identifier : MVME3100-1263 |
---|
310 | Manufacturing Assembly Number : 01-W3893F01C |
---|
311 | Serial Number : 7458814 |
---|
312 | L2 Cache Configuration : FF FF FF FF FF FF FF FF |
---|
313 | : FF 01 FF 01 FF FF FF |
---|
314 | Microprocessor Type : 8540 |
---|
315 | SROM/EEPROM CRC : 7129D2D6 (&1898566358) |
---|
316 | Ethernet Address : 00 01 AF 16 E5 C5 00 |
---|
317 | Ethernet Address : 00 01 AF 16 E5 C6 01 |
---|
318 | Ethernet Address : 00 01 AF 16 E5 C7 02 |
---|
319 | Flash Memory Configuration : 00 01 7E 23 10 02 02 10 |
---|
320 | : 10 00 64 09 |
---|
321 | |
---|
322 | */ |
---|