]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/LibSmbiosView.c
ShellPkg: ShellCommands/SetVar: Make '-rt' imply '-bs'
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / LibSmbiosView.c
index 22a8065a0153c83fc996a9b1ed1989dd4d6f2d8f..23a46d3fe1116a0c6d4ae153d4f8b0b63e55dc56 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   API for SMBIOS table.\r
 \r
-  Copyright (c) 2005 - 2010, 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
 \r
 #include "../UefiShellDebug1CommandsLib.h"\r
-#include <Guid/Smbios.h>\r
-#include "LIbSmbios.h"\r
+#include <Guid/SmBios.h>\r
 #include "LibSmbiosView.h"\r
-#include "smbiosview.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
+/**\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
 LibSmbiosInit (\r
   VOID\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-    Init the SMBIOS VIEW API's environment.\r
-\r
-  Arguments:\r
-    None\r
-\r
-Returns:\r
-    EFI_SUCCESS       - Successful to init the SMBIOS VIEW Lib\r
-    Others            - Cannot get SMBIOS Table\r
-\r
-**/\r
 {\r
   EFI_STATUS  Status;\r
 \r
@@ -73,6 +64,9 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Cleanup the Smbios information.\r
+**/\r
 VOID\r
 LibSmbiosCleanup (\r
   VOID\r
@@ -88,110 +82,108 @@ LibSmbiosCleanup (
   mInit = 0;\r
 }\r
 \r
+/**\r
+  Get the entry point structure for the table.\r
+\r
+  @param[out] EntryPointStructure  The pointer to populate.\r
+**/\r
 VOID\r
 LibSmbiosGetEPS (\r
-  SMBIOS_STRUCTURE_TABLE **pEntryPointStructure\r
+  OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure\r
   )\r
 {\r
   //\r
   // return SMBIOS Table address\r
   //\r
-  *pEntryPointStructure = mSmbiosTable;\r
+  *EntryPointStructure = mSmbiosTable;\r
 }\r
 \r
-VOID\r
-LibSmbiosGetStructHead (\r
-  SMBIOS_STRUCTURE_POINTER *pHead\r
-  )\r
-{\r
-  //\r
-  // return SMBIOS structure table address\r
-  //\r
-  pHead = mSmbiosStruct;\r
-}\r
+/**\r
+  Return SMBIOS string for the given string number.\r
 \r
-EFI_STATUS\r
-LibGetSmbiosInfo (\r
-  OUT CHAR8   *dmiBIOSRevision,\r
-  OUT UINT16  *NumStructures,\r
-  OUT UINT16  *StructureSize,\r
-  OUT UINT32  *dmiStorageBase,\r
-  OUT UINT16  *dmiStorageSize\r
-  )\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
-Routine Description:\r
-    Get SMBIOS Information.\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
-  Arguments:\r
-    dmiBIOSRevision   - Revision of the SMBIOS Extensions.\r
-    NumStructures     - Max. Number of Structures the BIOS will return.\r
-    StructureSize     - Size of largest SMBIOS Structure.\r
-    dmiStorageBase    - 32-bit physical base address for memory mapped SMBIOS data.\r
-    dmiStorageSize    - Size of the memory-mapped SMBIOS data.\r
+  ASSERT (Smbios != NULL);\r
 \r
-  Returns:\r
-    DMI_SUCCESS                 - successful.\r
-    DMI_FUNCTION_NOT_SUPPORTED  - Does not support SMBIOS calling interface capability.\r
+  //\r
+  // Skip over formatted section\r
+  //\r
+  String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r
 \r
-**/\r
-{\r
   //\r
-  // If no SMIBOS table, unsupported.\r
+  // Look through unformated section\r
   //\r
-  if (mSmbiosTable == NULL) {\r
-    return DMI_FUNCTION_NOT_SUPPORTED;\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
-  *dmiBIOSRevision  = mSmbiosTable->SmbiosBcdRevision;\r
-  *NumStructures    = mSmbiosTable->NumberOfSmbiosStructures;\r
-  *StructureSize    = mSmbiosTable->MaxStructureSize;\r
-  *dmiStorageBase   = mSmbiosTable->TableAddress;\r
-  *dmiStorageSize   = mSmbiosTable->TableLength;\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 DMI_SUCCESS;\r
+  return NULL;\r
 }\r
 \r
-EFI_STATUS\r
-LibGetSmbiosStructure (\r
-  IN  OUT UINT16  *Handle,\r
-  IN  OUT UINT8   *Buffer,\r
-  OUT UINT16      *Length\r
-  )\r
-/*++\r
-\r
-  Routine Description:\r
-    Get SMBIOS structure given the Handle,copy data to the Buffer,\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
-  Arguments:\r
-    Handle:         - 0xFFFF: get the first structure\r
-                    - Others: get a structure according to this value.\r
-    Buffter:        - The pointer to the caller's memory buffer.\r
-    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
-  Returns:\r
-    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
-    DMI_INVALID_HANDLE  - Buffer not contain the requiring structure data\r
-                        - Handle is updated with next structure handle or\r
-                          0xFFFF(end-of-list).\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
+  OUT UINT8       **Buffer,\r
+  OUT UINT16      *Length\r
+  )\r
 {\r
   SMBIOS_STRUCTURE_POINTER  Smbios;\r
   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
@@ -209,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
@@ -226,124 +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
-EFI_STATUS\r
-SmbiosCheckStructure (\r
-  IN  SMBIOS_STRUCTURE_POINTER *Smbios\r
-  )\r
-/*++\r
-\r
-  Routine Description:\r
-    Check the structure to see if it is legal.\r
-\r
-  Arguments:\r
-    Smbios    - Pointer to the structure that will be checked.\r
-\r
-  Returns:\r
-    DMI_SUCCESS     - Structure data is legal.\r
-    DMI_BAD_PARAMETER - Structure data contains bad parameter\r
-\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
-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