2 * @file IxNpeDlImageMgr.c
4 * @author Intel Corporation
5 * @date 09 January 2002
7 * @brief This file contains the implementation of the private API for the
8 * IXP425 NPE Downloader ImageMgr module
12 * IXP400 SW Release version 2.0
14 * -- Copyright Notice --
17 * Copyright 2001-2005, Intel Corporation.
18 * All rights reserved.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * 3. Neither the name of the Intel Corporation nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
35 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * -- End of Copyright Notice --
52 * Put the system defined include files required.
57 * Put the user defined include files required.
59 #include "IxNpeDlImageMgr_p.h"
60 #include "IxNpeDlMacros_p.h"
63 * define the flag which toggles the firmare inclusion
65 #define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1
66 #include "IxNpeMicrocode.h"
69 * Indicates the start of an NPE Image, in new NPE Image Library format.
70 * 2 consecutive occurances indicates the end of the NPE Image Library
72 #define NPE_IMAGE_MARKER 0xfeedf00d
75 * Typedefs whose scope is limited to this file.
79 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
80 * TO BE DEPRECATED IN A FUTURE RELEASE
87 } IxNpeDlImageMgrImageEntry;
90 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
91 * TO BE DEPRECATED IN A FUTURE RELEASE
95 IxNpeDlImageMgrImageEntry image;
97 } IxNpeDlImageMgrHeaderEntry;
100 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
101 * TO BE DEPRECATED IN A FUTURE RELEASE
106 /* 1st entry in the header (there may be more than one) */
107 IxNpeDlImageMgrHeaderEntry entry[1];
108 } IxNpeDlImageMgrImageLibraryHeader;
112 * NPE Image Header definition, used in new NPE Image Library format
119 } IxNpeDlImageMgrImageHeader;
121 /* module statistics counters */
124 UINT32 invalidSignature;
125 UINT32 imageIdListOverflow;
126 UINT32 imageIdNotFound;
127 } IxNpeDlImageMgrStats;
131 * Variable declarations global to this file only. Externs are followed by
134 static IxNpeDlImageMgrStats ixNpeDlImageMgrStats;
137 #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
138 static UINT32 *IxNpeMicroCodeImageLibrary = NULL; /* Gets set to proper value at runtime */
140 static UINT32 *IxNpeMicroCodeImageLibrary = (UINT32 *)IxNpeMicrocode_array;
145 * static function prototypes.
148 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
151 ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
154 ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
155 IxNpeDlImageId *imageIdB);
158 ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
159 IxNpeDlImageId *imageIdB);
162 ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
168 * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
170 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
171 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
174 ixNpeDlImageMgrMicrocodeImageLibraryOverride (
175 UINT32 *clientImageLibrary)
177 IX_STATUS status = IX_SUCCESS;
179 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
180 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
182 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
184 IxNpeMicroCodeImageLibrary = clientImageLibrary;
188 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
189 "Client-supplied image has invalid signature\n");
193 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
194 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
201 * Function definition: ixNpeDlImageMgrImageListExtract
203 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
204 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
207 ixNpeDlImageMgrImageListExtract (
208 IxNpeDlImageId *imageListPtr,
212 IxNpeDlImageId formattedImageId;
213 IX_STATUS status = IX_SUCCESS;
214 UINT32 imageCount = 0;
215 IxNpeDlImageMgrImageLibraryHeader *header;
217 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
218 "Entering ixNpeDlImageMgrImageListExtract\n");
220 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
222 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
224 /* for each image entry in the image header ... */
225 while (header->entry[imageCount].eohMarker !=
226 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
229 * if the image list container from calling function has capacity,
230 * add the image id to the list
232 if ((imageListPtr != NULL) && (imageCount < *numImages))
234 rawImageId = header->entry[imageCount].image.id;
235 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
236 imageListPtr[imageCount] = formattedImageId;
238 /* imageCount reflects no. of image entries in image library header */
243 * if image list container from calling function was too small to
244 * contain all image ids in the header, set return status to FAIL
246 if ((imageListPtr != NULL) && (imageCount > *numImages))
249 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
250 "number of Ids found exceeds list capacity\n");
251 ixNpeDlImageMgrStats.imageIdListOverflow++;
253 /* return number of image ids found in image library header */
254 *numImages = imageCount;
259 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
260 "invalid signature in image\n");
263 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
264 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
271 * Function definition: ixNpeDlImageMgrImageLocate
273 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
274 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
277 ixNpeDlImageMgrImageLocate (
278 IxNpeDlImageId *imageId,
284 IxNpeDlImageId formattedImageId;
285 /* used to index image entries in image library header */
286 UINT32 imageCount = 0;
287 IX_STATUS status = IX_FAIL;
288 IxNpeDlImageMgrImageLibraryHeader *header;
290 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
291 "Entering ixNpeDlImageMgrImageLocate\n");
293 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
295 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
297 /* for each image entry in the image library header ... */
298 while (header->entry[imageCount].eohMarker !=
299 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
301 rawImageId = header->entry[imageCount].image.id;
302 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
303 /* if a match for imageId is found in the image library header... */
304 if (ixNpeDlImageMgrImageIdCompare (imageId, &formattedImageId))
307 * get pointer to the image in the image library using offset from
308 * 1st word in image library
310 imageOffset = header->entry[imageCount].image.offset;
311 *imagePtr = &IxNpeMicroCodeImageLibrary[imageOffset];
312 /* get the image size */
313 *imageSize = header->entry[imageCount].image.size;
319 if (status != IX_SUCCESS)
321 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
322 "imageId not found in image library header\n");
323 ixNpeDlImageMgrStats.imageIdNotFound++;
328 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
329 "invalid signature in image library\n");
332 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
333 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
338 * Function definition: ixNpeDlImageMgrLatestImageExtract
340 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
341 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
344 ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
346 UINT32 imageCount = 0;
348 IxNpeDlImageId formattedImageId;
349 IX_STATUS status = IX_FAIL;
350 IxNpeDlImageMgrImageLibraryHeader *header;
353 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
354 "Entering ixNpeDlImageMgrLatestImageExtract\n");
356 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
358 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
360 /* for each image entry in the image library header ... */
361 while (header->entry[imageCount].eohMarker !=
362 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
364 rawImageId = header->entry[imageCount].image.id;
365 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
367 * if a match for the npe Id and functionality Id of the imageId is
368 * found in the image library header...
370 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
372 if(imageId->major <= formattedImageId.major)
374 if(imageId->minor < formattedImageId.minor)
376 imageId->minor = formattedImageId.minor;
378 imageId->major = formattedImageId.major;
384 if (status != IX_SUCCESS)
386 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
387 "imageId not found in image library header\n");
388 ixNpeDlImageMgrStats.imageIdNotFound++;
393 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
394 "invalid signature in image library\n");
397 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
398 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
403 * Function definition: ixNpeDlImageMgrSignatureCheck
405 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
406 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
409 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
411 IxNpeDlImageMgrImageLibraryHeader *header =
412 (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
415 if (header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
418 ixNpeDlImageMgrStats.invalidSignature++;
426 * Function definition: ixNpeDlImageMgrImageIdFormat
428 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
429 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
432 ixNpeDlImageMgrImageIdFormat (
434 IxNpeDlImageId *imageId)
436 imageId->npeId = (rawImageId >>
437 IX_NPEDL_IMAGEID_NPEID_OFFSET) &
438 IX_NPEDL_NPEIMAGE_FIELD_MASK;
439 imageId->functionalityId = (rawImageId >>
440 IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET) &
441 IX_NPEDL_NPEIMAGE_FIELD_MASK;
442 imageId->major = (rawImageId >>
443 IX_NPEDL_IMAGEID_MAJOR_OFFSET) &
444 IX_NPEDL_NPEIMAGE_FIELD_MASK;
445 imageId->minor = (rawImageId >>
446 IX_NPEDL_IMAGEID_MINOR_OFFSET) &
447 IX_NPEDL_NPEIMAGE_FIELD_MASK;
453 * Function definition: ixNpeDlImageMgrImageIdCompare
455 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
456 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
459 ixNpeDlImageMgrImageIdCompare (
460 IxNpeDlImageId *imageIdA,
461 IxNpeDlImageId *imageIdB)
463 if ((imageIdA->npeId == imageIdB->npeId) &&
464 (imageIdA->functionalityId == imageIdB->functionalityId) &&
465 (imageIdA->major == imageIdB->major) &&
466 (imageIdA->minor == imageIdB->minor))
477 * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
479 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
480 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
483 ixNpeDlImageMgrNpeFunctionIdCompare (
484 IxNpeDlImageId *imageIdA,
485 IxNpeDlImageId *imageIdB)
487 if ((imageIdA->npeId == imageIdB->npeId) &&
488 (imageIdA->functionalityId == imageIdB->functionalityId))
500 * Function definition: ixNpeDlImageMgrStatsShow
503 ixNpeDlImageMgrStatsShow (void)
505 ixOsalLog (IX_OSAL_LOG_LVL_USER,
506 IX_OSAL_LOG_DEV_STDOUT,
507 "\nixNpeDlImageMgrStatsShow:\n"
508 "\tInvalid Image Signatures: %u\n"
509 "\tImage Id List capacity too small: %u\n"
510 "\tImage Id not found: %u\n\n",
511 ixNpeDlImageMgrStats.invalidSignature,
512 ixNpeDlImageMgrStats.imageIdListOverflow,
513 ixNpeDlImageMgrStats.imageIdNotFound,
519 * Function definition: ixNpeDlImageMgrStatsReset
522 ixNpeDlImageMgrStatsReset (void)
524 ixNpeDlImageMgrStats.invalidSignature = 0;
525 ixNpeDlImageMgrStats.imageIdListOverflow = 0;
526 ixNpeDlImageMgrStats.imageIdNotFound = 0;
531 * Function definition: ixNpeDlImageMgrImageFind_legacy
533 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
534 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
537 ixNpeDlImageMgrImageFind_legacy (
538 UINT32 *imageLibrary,
544 /* used to index image entries in image library header */
545 UINT32 imageCount = 0;
546 IX_STATUS status = IX_FAIL;
547 IxNpeDlImageMgrImageLibraryHeader *header;
548 BOOL imageFound = FALSE;
550 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
551 "Entering ixNpeDlImageMgrImageFind\n");
554 /* If user didn't specify a library to use, use the default
555 * one from IxNpeMicrocode.h
557 if (imageLibrary == NULL)
559 imageLibrary = IxNpeMicroCodeImageLibrary;
562 if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
564 header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
566 /* for each image entry in the image library header ... */
567 while ((header->entry[imageCount].eohMarker !=
568 IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
570 /* if a match for imageId is found in the image library header... */
571 if (imageId == header->entry[imageCount].image.id)
574 * get pointer to the image in the image library using offset from
575 * 1st word in image library
577 imageOffset = header->entry[imageCount].image.offset;
578 *imagePtr = &imageLibrary[imageOffset];
579 /* get the image size */
580 *imageSize = header->entry[imageCount].image.size;
586 if (status != IX_SUCCESS)
588 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
589 "imageId not found in image library header\n");
590 ixNpeDlImageMgrStats.imageIdNotFound++;
595 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
596 "invalid signature in image library\n");
599 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
600 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
606 * Function definition: ixNpeDlImageMgrImageFind
609 ixNpeDlImageMgrImageFind (
610 UINT32 *imageLibrary,
615 IxNpeDlImageMgrImageHeader *image;
618 /* If user didn't specify a library to use, use the default
619 * one from IxNpeMicrocode.h
621 if (imageLibrary == NULL)
623 #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
624 if (ixNpeMicrocode_binaryArray == NULL)
626 printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
631 imageLibrary = ixNpeMicrocode_binaryArray;
634 imageLibrary = IxNpeMicroCodeImageLibrary;
635 #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
638 /* For backward's compatibility with previous image format */
639 if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
641 return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
647 while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
649 image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
650 offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
652 if (image->id == imageId)
654 *imagePtr = imageLibrary + offset;
655 *imageSize = image->size;
658 /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
659 else if (image->id == NPE_IMAGE_MARKER)
661 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
662 "imageId not found in image library header\n");
663 ixNpeDlImageMgrStats.imageIdNotFound++;
664 /* reached end of library, image not found */
667 offset += image->size;
670 /* If we get here, our image library may be corrupted */
671 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
672 "image library format may be invalid or corrupted\n");