]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/LibSmbiosView.c
ShellPkg: Update header file including style
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / LibSmbiosView.c
index 9e995683d0e6f2505c708bc1403a36a7ce6dca9e..edfdcc9b2ac02d33e244a9eda72b08140abf265d 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 - 2015, 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
     \r
 \r
-#include "../UefiShellDebug1CommandsLib.h"\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 UINT8                    m64Init       = 0;\r
+STATIC SMBIOS_TABLE_ENTRY_POINT     *mSmbiosTable   = NULL;\r
+STATIC SMBIOS_TABLE_3_0_ENTRY_POINT *mSmbios64BitTable = NULL;\r
 STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;\r
 STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;\r
+STATIC SMBIOS_STRUCTURE_POINTER m_Smbios64BitStruct;\r
+STATIC SMBIOS_STRUCTURE_POINTER *mSmbios64BitStruct = &m_Smbios64BitStruct;\r
 \r
 /**\r
   Init the SMBIOS VIEW API's environment.\r
@@ -48,7 +51,6 @@ LibSmbiosInit (
   Status = GetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID**)&mSmbiosTable);\r
 \r
   if (mSmbiosTable == NULL) {\r
-    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle);\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -65,6 +67,46 @@ LibSmbiosInit (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Init the SMBIOS VIEW API's environment.\r
+\r
+  @retval EFI_SUCCESS  Successful to init the SMBIOS VIEW Lib.\r
+**/\r
+EFI_STATUS\r
+LibSmbios64BitInit (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Init only once\r
+  //\r
+  if (m64Init == 1) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Get SMBIOS table from System Configure table\r
+  //\r
+  Status = GetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID**)&mSmbios64BitTable);\r
+\r
+  if (mSmbios64BitTable == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), gShellDebug1HiiHandle, Status);\r
+    return Status;\r
+  }\r
+  //\r
+  // Init SMBIOS structure table address\r
+  //\r
+  mSmbios64BitStruct->Raw  = (UINT8 *) (UINTN) (mSmbios64BitTable->TableAddress);\r
+\r
+  m64Init               = 1;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Cleanup the Smbios information.\r
 **/\r
@@ -83,6 +125,24 @@ LibSmbiosCleanup (
   mInit = 0;\r
 }\r
 \r
+/**\r
+  Cleanup the Smbios information.\r
+**/\r
+VOID\r
+LibSmbios64BitCleanup (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Release resources\r
+  //\r
+  if (mSmbios64BitTable != NULL) {\r
+    mSmbios64BitTable = NULL;\r
+  }\r
+\r
+  m64Init = 0;\r
+}\r
+\r
 /**\r
   Get the entry point structure for the table.\r
 \r
@@ -90,7 +150,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 +160,93 @@ LibSmbiosGetEPS (
 }\r
 \r
 /**\r
-    Get SMBIOS structure given the Handle,copy data to the Buffer,\r
+  Get the entry point structure for the table.\r
+\r
+  @param[out] EntryPointStructure  The pointer to populate.\r
+**/\r
+VOID\r
+LibSmbios64BitGetEPS (\r
+  OUT SMBIOS_TABLE_3_0_ENTRY_POINT **EntryPointStructure\r
+  )\r
+{\r
+  //\r
+  // return SMBIOS Table address\r
+  //\r
+  *EntryPointStructure = mSmbios64BitTable;\r
+}\r
+\r
+/**\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 +254,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 +278,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 +295,79 @@ 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
+    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] Smbios    - Pointer to the structure that will be checked.\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   Handle is updated with next structure handle or\r
+                          0xFFFF(end-of-list).\r
 \r
-  @retval DMI_SUCCESS           Structure data is legal.\r
-  @retval DMI_BAD_PARAMETER     Structure data contains bad parameter.\r
+    @retval DMI_INVALID_HANDLE  Handle is updated with first structure handle or\r
+                                0xFFFF(end-of-list).\r
 **/\r
 EFI_STATUS\r
-SmbiosCheckStructure (\r
-  IN  SMBIOS_STRUCTURE_POINTER *Smbios\r
+LibGetSmbios64BitStructure (\r
+  IN  OUT UINT16  *Handle,\r
+  OUT UINT8       **Buffer,\r
+  OUT UINT16      *Length\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
+  SMBIOS_STRUCTURE_POINTER  Smbios;\r
+  SMBIOS_STRUCTURE_POINTER  SmbiosEnd;\r
+  UINT8                     *Raw;\r
 \r
-  case 16:\r
-    Status = CHECK_VALUE (Smbios->Type16->Hdr.Length, 0x0F);\r
-    break;\r
+  if (*Handle == INVALID_HANDLE) {\r
+    *Handle = mSmbios64BitStruct->Hdr->Handle;\r
+    return DMI_INVALID_HANDLE;\r
+  }\r
 \r
-  case 19:\r
-    Status = CHECK_VALUE (Smbios->Type19->Hdr.Length, 0x0F);\r
-    break;\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
-  case 20:\r
-    Status = CHECK_VALUE (Smbios->Type20->Hdr.Length, 0x13);\r
-    break;\r
+  *Length     = 0;\r
+  Smbios.Hdr  = mSmbios64BitStruct->Hdr;\r
 \r
-  case 32:\r
+  SmbiosEnd.Raw = Smbios.Raw + mSmbios64BitTableLength;\r
+  while (Smbios.Raw < SmbiosEnd.Raw) {\r
+    if (Smbios.Hdr->Handle == *Handle) {\r
+      Raw = Smbios.Raw;\r
+      //\r
+      // Walk to next structure\r
+      //\r
+      LibGetSmbiosString (&Smbios, (UINT16) (-1));\r
+      //\r
+      // Length = Next structure head - this structure head\r
+      //\r
+      *Length = (UINT16) (Smbios.Raw - Raw);\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 = INVALID_HANDLE;\r
+      }\r
+      return DMI_SUCCESS;\r
+    }\r
     //\r
-    // Because EFI_SUCCESS == 0,\r
-    // So errors added up is also error.\r
+    // Walk to next structure\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
+    LibGetSmbiosString (&Smbios, (UINT16) (-1));\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
+  *Handle = INVALID_HANDLE;\r
+  return DMI_INVALID_HANDLE;\r
 }\r