1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54#include "IxOsal.h"
55
56
57
58
59#include "IxNpeDlImageMgr_p.h"
60#include "IxNpeDlMacros_p.h"
61
62
63
64
65#define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1
66#include "IxNpeMicrocode.h"
67
68
69
70
71
72#define NPE_IMAGE_MARKER 0xfeedf00d
73
74
75
76
77
78
79
80
81
82typedef struct
83{
84 UINT32 size;
85 UINT32 offset;
86 UINT32 id;
87} IxNpeDlImageMgrImageEntry;
88
89
90
91
92
93typedef union
94{
95 IxNpeDlImageMgrImageEntry image;
96 UINT32 eohMarker;
97} IxNpeDlImageMgrHeaderEntry;
98
99
100
101
102
103typedef struct
104{
105 UINT32 signature;
106
107 IxNpeDlImageMgrHeaderEntry entry[1];
108} IxNpeDlImageMgrImageLibraryHeader;
109
110
111
112
113
114typedef struct
115{
116 UINT32 marker;
117 UINT32 id;
118 UINT32 size;
119} IxNpeDlImageMgrImageHeader;
120
121
122typedef struct
123{
124 UINT32 invalidSignature;
125 UINT32 imageIdListOverflow;
126 UINT32 imageIdNotFound;
127} IxNpeDlImageMgrStats;
128
129
130
131
132
133
134static IxNpeDlImageMgrStats ixNpeDlImageMgrStats;
135
136static UINT32* getIxNpeMicroCodeImageLibrary(void)
137{
138 char *s;
139
140 if ((s = getenv("npe_ucode")) != NULL)
141 return (UINT32*) simple_strtoul(s, NULL, 16);
142 else
143 return NULL;
144}
145
146
147
148
149PRIVATE BOOL
150ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
151
152PRIVATE void
153ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
154
155PRIVATE BOOL
156ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
157 IxNpeDlImageId *imageIdB);
158
159PRIVATE BOOL
160ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
161 IxNpeDlImageId *imageIdB);
162
163#if 0
164PRIVATE IX_STATUS
165ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
166 UINT32 imageId,
167 UINT32 **imagePtr,
168 UINT32 *imageSize);
169
170
171
172
173
174
175
176IX_STATUS
177ixNpeDlImageMgrMicrocodeImageLibraryOverride (
178 UINT32 *clientImageLibrary)
179{
180 IX_STATUS status = IX_SUCCESS;
181
182 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
183 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
184
185 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
186 {
187 IxNpeMicroCodeImageLibrary = clientImageLibrary;
188 }
189 else
190 {
191 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
192 "Client-supplied image has invalid signature\n");
193 status = IX_FAIL;
194 }
195
196 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
197 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
198 status);
199 return status;
200}
201#endif
202
203
204
205
206
207
208
209IX_STATUS
210ixNpeDlImageMgrImageListExtract (
211 IxNpeDlImageId *imageListPtr,
212 UINT32 *numImages)
213{
214 UINT32 rawImageId;
215 IxNpeDlImageId formattedImageId;
216 IX_STATUS status = IX_SUCCESS;
217 UINT32 imageCount = 0;
218 IxNpeDlImageMgrImageLibraryHeader *header;
219
220 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
221 "Entering ixNpeDlImageMgrImageListExtract\n");
222
223 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
224
225 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
226 {
227
228 while (header->entry[imageCount].eohMarker !=
229 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
230 {
231
232
233
234
235 if ((imageListPtr != NULL) && (imageCount < *numImages))
236 {
237 rawImageId = header->entry[imageCount].image.id;
238 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
239 imageListPtr[imageCount] = formattedImageId;
240 }
241
242 imageCount++;
243 }
244
245
246
247
248
249 if ((imageListPtr != NULL) && (imageCount > *numImages))
250 {
251 status = IX_FAIL;
252 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
253 "number of Ids found exceeds list capacity\n");
254 ixNpeDlImageMgrStats.imageIdListOverflow++;
255 }
256
257 *numImages = imageCount;
258 }
259 else
260 {
261 status = IX_FAIL;
262 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
263 "invalid signature in image\n");
264 }
265
266 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
267 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
268 status);
269 return status;
270}
271
272
273
274
275
276
277
278
279IX_STATUS
280ixNpeDlImageMgrImageLocate (
281 IxNpeDlImageId *imageId,
282 UINT32 **imagePtr,
283 UINT32 *imageSize)
284{
285 UINT32 imageOffset;
286 UINT32 rawImageId;
287 IxNpeDlImageId formattedImageId;
288
289 UINT32 imageCount = 0;
290 IX_STATUS status = IX_FAIL;
291 IxNpeDlImageMgrImageLibraryHeader *header;
292
293 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
294 "Entering ixNpeDlImageMgrImageLocate\n");
295
296 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
297
298 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
299 {
300
301 while (header->entry[imageCount].eohMarker !=
302 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
303 {
304 rawImageId = header->entry[imageCount].image.id;
305 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
306
307 if (ixNpeDlImageMgrImageIdCompare (imageId, &formattedImageId))
308 {
309
310
311
312
313 UINT32 *tmp=getIxNpeMicroCodeImageLibrary();
314 imageOffset = header->entry[imageCount].image.offset;
315 *imagePtr = &tmp[imageOffset];
316
317 *imageSize = header->entry[imageCount].image.size;
318 status = IX_SUCCESS;
319 break;
320 }
321 imageCount++;
322 }
323 if (status != IX_SUCCESS)
324 {
325 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
326 "imageId not found in image library header\n");
327 ixNpeDlImageMgrStats.imageIdNotFound++;
328 }
329 }
330 else
331 {
332 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
333 "invalid signature in image library\n");
334 }
335
336 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
337 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
338 return status;
339}
340
341
342
343
344
345
346
347IX_STATUS
348ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
349{
350 UINT32 imageCount = 0;
351 UINT32 rawImageId;
352 IxNpeDlImageId formattedImageId;
353 IX_STATUS status = IX_FAIL;
354 IxNpeDlImageMgrImageLibraryHeader *header;
355
356
357 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
358 "Entering ixNpeDlImageMgrLatestImageExtract\n");
359
360 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
361
362 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
363 {
364
365 while (header->entry[imageCount].eohMarker !=
366 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
367 {
368 rawImageId = header->entry[imageCount].image.id;
369 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
370
371
372
373
374 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
375 {
376 if(imageId->major <= formattedImageId.major)
377 {
378 if(imageId->minor < formattedImageId.minor)
379 {
380 imageId->minor = formattedImageId.minor;
381 }
382 imageId->major = formattedImageId.major;
383 }
384 status = IX_SUCCESS;
385 }
386 imageCount++;
387 }
388 if (status != IX_SUCCESS)
389 {
390 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
391 "imageId not found in image library header\n");
392 ixNpeDlImageMgrStats.imageIdNotFound++;
393 }
394 }
395 else
396 {
397 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
398 "invalid signature in image library\n");
399 }
400
401 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
402 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
403 return status;
404}
405
406
407
408
409
410
411
412PRIVATE BOOL
413ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
414{
415 IxNpeDlImageMgrImageLibraryHeader *header =
416 (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
417 BOOL result = TRUE;
418
419 if (!header || header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
420 {
421 result = FALSE;
422 ixNpeDlImageMgrStats.invalidSignature++;
423 }
424
425 return result;
426}
427
428
429
430
431
432
433
434
435PRIVATE void
436ixNpeDlImageMgrImageIdFormat (
437 UINT32 rawImageId,
438 IxNpeDlImageId *imageId)
439{
440 imageId->npeId = (rawImageId >>
441 IX_NPEDL_IMAGEID_NPEID_OFFSET) &
442 IX_NPEDL_NPEIMAGE_FIELD_MASK;
443 imageId->functionalityId = (rawImageId >>
444 IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET) &
445 IX_NPEDL_NPEIMAGE_FIELD_MASK;
446 imageId->major = (rawImageId >>
447 IX_NPEDL_IMAGEID_MAJOR_OFFSET) &
448 IX_NPEDL_NPEIMAGE_FIELD_MASK;
449 imageId->minor = (rawImageId >>
450 IX_NPEDL_IMAGEID_MINOR_OFFSET) &
451 IX_NPEDL_NPEIMAGE_FIELD_MASK;
452
453}
454
455
456
457
458
459
460
461
462PRIVATE BOOL
463ixNpeDlImageMgrImageIdCompare (
464 IxNpeDlImageId *imageIdA,
465 IxNpeDlImageId *imageIdB)
466{
467 if ((imageIdA->npeId == imageIdB->npeId) &&
468 (imageIdA->functionalityId == imageIdB->functionalityId) &&
469 (imageIdA->major == imageIdB->major) &&
470 (imageIdA->minor == imageIdB->minor))
471 {
472 return TRUE;
473 }
474 else
475 {
476 return FALSE;
477 }
478}
479
480
481
482
483
484
485
486PRIVATE BOOL
487ixNpeDlImageMgrNpeFunctionIdCompare (
488 IxNpeDlImageId *imageIdA,
489 IxNpeDlImageId *imageIdB)
490{
491 if ((imageIdA->npeId == imageIdB->npeId) &&
492 (imageIdA->functionalityId == imageIdB->functionalityId))
493 {
494 return TRUE;
495 }
496 else
497 {
498 return FALSE;
499 }
500}
501
502
503
504
505
506void
507ixNpeDlImageMgrStatsShow (void)
508{
509 ixOsalLog (IX_OSAL_LOG_LVL_USER,
510 IX_OSAL_LOG_DEV_STDOUT,
511 "\nixNpeDlImageMgrStatsShow:\n"
512 "\tInvalid Image Signatures: %u\n"
513 "\tImage Id List capacity too small: %u\n"
514 "\tImage Id not found: %u\n\n",
515 ixNpeDlImageMgrStats.invalidSignature,
516 ixNpeDlImageMgrStats.imageIdListOverflow,
517 ixNpeDlImageMgrStats.imageIdNotFound,
518 0,0,0);
519}
520
521
522
523
524
525void
526ixNpeDlImageMgrStatsReset (void)
527{
528 ixNpeDlImageMgrStats.invalidSignature = 0;
529 ixNpeDlImageMgrStats.imageIdListOverflow = 0;
530 ixNpeDlImageMgrStats.imageIdNotFound = 0;
531}
532
533
534#if 0
535
536
537
538
539
540
541PRIVATE IX_STATUS
542ixNpeDlImageMgrImageFind_legacy (
543 UINT32 *imageLibrary,
544 UINT32 imageId,
545 UINT32 **imagePtr,
546 UINT32 *imageSize)
547{
548 UINT32 imageOffset;
549
550 UINT32 imageCount = 0;
551 IX_STATUS status = IX_FAIL;
552 IxNpeDlImageMgrImageLibraryHeader *header;
553 BOOL imageFound = FALSE;
554
555 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
556 "Entering ixNpeDlImageMgrImageFind\n");
557
558
559
560
561
562 if (imageLibrary == NULL)
563 {
564 imageLibrary = IxNpeMicroCodeImageLibrary;
565 }
566
567 if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
568 {
569 header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
570
571
572 while ((header->entry[imageCount].eohMarker !=
573 IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
574 {
575
576 if (imageId == header->entry[imageCount].image.id)
577 {
578
579
580
581
582 imageOffset = header->entry[imageCount].image.offset;
583 *imagePtr = &imageLibrary[imageOffset];
584
585 *imageSize = header->entry[imageCount].image.size;
586 status = IX_SUCCESS;
587 imageFound = TRUE;
588 }
589 imageCount++;
590 }
591 if (status != IX_SUCCESS)
592 {
593 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
594 "imageId not found in image library header\n");
595 ixNpeDlImageMgrStats.imageIdNotFound++;
596 }
597 }
598 else
599 {
600 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
601 "invalid signature in image library\n");
602 }
603
604 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
605 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
606 return status;
607}
608#endif
609
610
611
612
613IX_STATUS
614ixNpeDlImageMgrImageFind (
615 UINT32 *imageLibrary,
616 UINT32 imageId,
617 UINT32 **imagePtr,
618 UINT32 *imageSize)
619{
620 IxNpeDlImageMgrImageHeader *image;
621 UINT32 offset = 0;
622
623
624
625
626 if (imageLibrary == NULL)
627 {
628#ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
629 if (ixNpeMicrocode_binaryArray == NULL)
630 {
631 printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
632 return IX_FAIL;
633 }
634 else
635 {
636 imageLibrary = ixNpeMicrocode_binaryArray;
637 }
638#else
639 imageLibrary = getIxNpeMicroCodeImageLibrary();
640 if (imageLibrary == NULL)
641 {
642 printf ("npe: ERROR, no Microcode found in memory\n");
643 return IX_FAIL;
644 }
645#endif
646 }
647
648#if 0
649
650 if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
651 {
652 return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
653 imageId,
654 imagePtr,
655 imageSize);
656 }
657#endif
658
659 while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
660 {
661 image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
662 offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
663
664 if (image->id == imageId)
665 {
666 *imagePtr = imageLibrary + offset;
667 *imageSize = image->size;
668 return IX_SUCCESS;
669 }
670
671 else if (image->id == NPE_IMAGE_MARKER)
672 {
673 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
674 "imageId not found in image library header\n");
675 ixNpeDlImageMgrStats.imageIdNotFound++;
676
677 return IX_FAIL;
678 }
679 offset += image->size;
680 }
681
682
683 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
684 "image library format may be invalid or corrupted\n");
685 return IX_FAIL;
686}
687
688