]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/LibSmbiosView.c
ShellPkg: Fix ARM build errors.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / LibSmbiosView.c
index 9e995683d0e6f2505c708bc1403a36a7ce6dca9e..23a46d3fe1116a0c6d4ae153d4f8b0b63e55dc56 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   API for SMBIOS table.\r
 \r
-  Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 \r
 #include "../UefiShellDebug1CommandsLib.h"\r
 #include <Guid/SmBios.h>\r
-#include "LibSmbios.h"\r
 #include "LibSmbiosView.h"\r
 #include "SmbiosView.h"\r
 \r
 STATIC UINT8                    mInit         = 0;\r
-STATIC SMBIOS_STRUCTURE_TABLE   *mSmbiosTable = NULL;\r
+STATIC SMBIOS_TABLE_ENTRY_POINT *mSmbiosTable = NULL;\r
 STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;\r
 STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;\r
 \r
@@ -90,7 +89,7 @@ LibSmbiosCleanup (
 **/\r
 VOID\r
 LibSmbiosGetEPS (\r
-  OUT SMBIOS_STRUCTURE_TABLE **EntryPointStructure\r
+  OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure\r
   )\r
 {\r
   //\r
@@ -100,27 +99,77 @@ LibSmbiosGetEPS (
 }\r
 \r
 /**\r
-    Get SMBIOS structure given the Handle,copy data to the Buffer,\r
+  Return SMBIOS string for the given string number.\r
+\r
+  @param[in] Smbios         Pointer to SMBIOS structure.\r
+  @param[in] StringNumber   String number to return. -1 is used to skip all strings and\r
+                            point to the next SMBIOS structure.\r
+\r
+  @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1\r
+**/\r
+CHAR8*\r
+LibGetSmbiosString (\r
+  IN  SMBIOS_STRUCTURE_POINTER    *Smbios,\r
+  IN  UINT16                      StringNumber\r
+  )\r
+{\r
+  UINT16  Index;\r
+  CHAR8   *String;\r
+\r
+  ASSERT (Smbios != NULL);\r
+\r
+  //\r
+  // Skip over formatted section\r
+  //\r
+  String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r
+\r
+  //\r
+  // Look through unformated section\r
+  //\r
+  for (Index = 1; Index <= StringNumber; Index++) {\r
+    if (StringNumber == Index) {\r
+      return String;\r
+    }\r
+    //\r
+    // Skip string\r
+    //\r
+    for (; *String != 0; String++);\r
+    String++;\r
+\r
+    if (*String == 0) {\r
+      //\r
+      // If double NULL then we are done.\r
+      //  Return pointer to next structure in Smbios.\r
+      //  if you pass in a -1 you will always get here\r
+      //\r
+      Smbios->Raw = (UINT8 *)++String;\r
+      return NULL;\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+/**\r
+    Get SMBIOS structure for the given Handle,\r
     Handle is changed to the next handle or 0xFFFF when the end is\r
     reached or the handle is not found.\r
 \r
-    @param[in,out] Handle     0xFFFF: get the first structure\r
-                              Others: get a structure according to this value.\r
-    @param[in,out] Buffer     The pointer to the caller's memory buffer.\r
-    @param[out] Length        Length of return buffer in bytes.\r
+    @param[in, out] Handle     0xFFFF: get the first structure\r
+                               Others: get a structure according to this value.\r
+    @param[out] Buffer         The pointer to the pointer to the structure.\r
+    @param[out] Length         Length of the structure.\r
 \r
-    @retval DMI_SUCCESS   Buffer contains the required structure data\r
-                          Handle is updated with next structure handle or\r
+    @retval DMI_SUCCESS   Handle is updated with next structure handle or\r
                           0xFFFF(end-of-list).\r
 \r
-    @retval DMI_INVALID_HANDLE  Buffer not contain the requiring structure data.\r
-                                Handle is updated with next structure handle or\r
+    @retval DMI_INVALID_HANDLE  Handle is updated with first structure handle or\r
                                 0xFFFF(end-of-list).\r
 **/\r
 EFI_STATUS\r
 LibGetSmbiosStructure (\r
   IN  OUT UINT16  *Handle,\r
-  IN  OUT UINT8   *Buffer,\r
+  OUT UINT8       **Buffer,\r
   OUT UINT16      *Length\r
   )\r
 {\r
@@ -128,13 +177,13 @@ LibGetSmbiosStructure (
   SMBIOS_STRUCTURE_POINTER  SmbiosEnd;\r
   UINT8                     *Raw;\r
 \r
-  if (*Handle == INVALIDE_HANDLE) {\r
+  if (*Handle == INVALID_HANDLE) {\r
     *Handle = mSmbiosStruct->Hdr->Handle;\r
     return DMI_INVALID_HANDLE;\r
   }\r
 \r
-  if (Buffer == NULL) {\r
-    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_SPEC), gShellDebug1HiiHandle);\r
+  if ((Buffer == NULL) || (Length == NULL)) {\r
+    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC), gShellDebug1HiiHandle);\r
     return DMI_INVALID_HANDLE;\r
   }\r
 \r
@@ -152,14 +201,14 @@ LibGetSmbiosStructure (
       // Length = Next structure head - this structure head\r
       //\r
       *Length = (UINT16) (Smbios.Raw - Raw);\r
-      CopyMem (Buffer, Raw, *Length);\r
+      *Buffer = Raw;\r
       //\r
       // update with the next structure handle.\r
       //\r
       if (Smbios.Raw < SmbiosEnd.Raw) {\r
         *Handle = Smbios.Hdr->Handle;\r
       } else {\r
-        *Handle = INVALIDE_HANDLE;\r
+        *Handle = INVALID_HANDLE;\r
       }\r
       return DMI_SUCCESS;\r
     }\r
@@ -169,126 +218,7 @@ LibGetSmbiosStructure (
     LibGetSmbiosString (&Smbios, (UINT16) (-1));\r
   }\r
 \r
-  *Handle = INVALIDE_HANDLE;\r
+  *Handle = INVALID_HANDLE;\r
   return DMI_INVALID_HANDLE;\r
 }\r
 \r
-/**\r
-  Check the structure to see if it is legal.\r
-\r
-  @param[in] Smbios    - Pointer to the structure that will be checked.\r
-\r
-  @retval DMI_SUCCESS           Structure data is legal.\r
-  @retval DMI_BAD_PARAMETER     Structure data contains bad parameter.\r
-**/\r
-EFI_STATUS\r
-SmbiosCheckStructure (\r
-  IN  SMBIOS_STRUCTURE_POINTER *Smbios\r
-  )\r
-{\r
-  //\r
-  // If key != value, then error.\r
-  //\r
-#define CHECK_VALUE(key, value) (((key) == (value)) ? EFI_SUCCESS : DMI_BAD_PARAMETER)\r
-\r
-  EFI_STATUS  Status;\r
-  //\r
-  // Assume staus is EFI_SUCCESS,\r
-  // but if check is error, then EFI_ERROR.\r
-  //\r
-  Status = EFI_SUCCESS;\r
-\r
-  switch (Smbios->Hdr->Type) {\r
-  case 0:\r
-    break;\r
-\r
-  case 1:\r
-    if (Smbios->Type1->Hdr.Length == 0x08 || Smbios->Type0->Hdr.Length == 0x19) {\r
-      Status = EFI_SUCCESS;\r
-    } else {\r
-      Status = DMI_BAD_PARAMETER;\r
-    }\r
-    break;\r
-\r
-  case 2:\r
-    Status = CHECK_VALUE (Smbios->Type2->Hdr.Length, 0x08);\r
-    break;\r
-\r
-  case 6:\r
-    Status = CHECK_VALUE (Smbios->Type6->Hdr.Length, 0x0C);\r
-    break;\r
-\r
-  case 11:\r
-    Status = CHECK_VALUE (Smbios->Type11->Hdr.Length, 0x05);\r
-    break;\r
-\r
-  case 12:\r
-    Status = CHECK_VALUE (Smbios->Type12->Hdr.Length, 0x05);\r
-    break;\r
-\r
-  case 13:\r
-    Status = CHECK_VALUE (Smbios->Type13->Hdr.Length, 0x16);\r
-    break;\r
-\r
-  case 16:\r
-    Status = CHECK_VALUE (Smbios->Type16->Hdr.Length, 0x0F);\r
-    break;\r
-\r
-  case 19:\r
-    Status = CHECK_VALUE (Smbios->Type19->Hdr.Length, 0x0F);\r
-    break;\r
-\r
-  case 20:\r
-    Status = CHECK_VALUE (Smbios->Type20->Hdr.Length, 0x13);\r
-    break;\r
-\r
-  case 32:\r
-    //\r
-    // Because EFI_SUCCESS == 0,\r
-    // So errors added up is also error.\r
-    //\r
-    Status = CHECK_VALUE (Smbios->Type32->Reserved[0], 0x00) +\r
-      CHECK_VALUE (Smbios->Type32->Reserved[1], 0x00) +\r
-      CHECK_VALUE (Smbios->Type32->Reserved[2], 0x00) +\r
-      CHECK_VALUE (Smbios->Type32->Reserved[3], 0x00) +\r
-      CHECK_VALUE (Smbios->Type32->Reserved[4], 0x00) +\r
-      CHECK_VALUE (Smbios->Type32->Reserved[5], 0x00);\r
-    break;\r
-\r
-  default:\r
-    Status = DMI_BAD_PARAMETER;\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Get a string from the smbios information.\r
-\r
-  @param[in] Smbios         The pointer to the smbios information.\r
-  @param[in] StringNumber   The index to the string to get.\r
-  @param[out] Buffer        The buffer to fill with the string when retrieved.\r
-**/\r
-VOID\r
-SmbiosGetPendingString (\r
-  IN  SMBIOS_STRUCTURE_POINTER      *Smbios,\r
-  IN  UINT16                        StringNumber,\r
-  OUT CHAR8                         *Buffer\r
-  )\r
-{\r
-  CHAR8 *String;\r
-  if (Buffer == NULL) {\r
-    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUF_SPEC_WHEN_STRUCT), gShellDebug1HiiHandle);\r
-    return ;\r
-  }\r
-  //\r
-  // Get string and copy to buffer.\r
-  // Caller should provide the buffer.\r
-  //\r
-  String = LibGetSmbiosString (Smbios, StringNumber);\r
-  if (String != NULL) {\r
-    CopyMem (Buffer, String, AsciiStrLen(String));\r
-  } else {\r
-    Buffer = NULL;\r
-  }\r
-}\r