]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
Program SD Cards into 4-bit mode (support for this is required in the spec). This...
[mirror_edk2.git] / MdeModulePkg / Universal / SmbiosDxe / SmbiosDxe.c
index 03b8b244629b2f529f13a1ee0e0c4da454b14073..f9ad65e14b9436909d011b56d3afd425970d1c24 100644 (file)
@@ -2,8 +2,8 @@
   This code produces the Smbios protocol. It also responsible for constructing \r
   SMBIOS table into system table.\r
   \r
-Copyright (c) 2009, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2009 - 2010, 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
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -45,13 +45,13 @@ SMBIOS_TABLE_ENTRY_POINT EntryPointStructureData = {
   //\r
   0x1f,\r
   //\r
-  // MajorVersion: 2 (Version 2.4)\r
+  // MajorVersion\r
   //\r
-  0x02,\r
+  (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) >> 8),\r
   //\r
-  // MinorVersion: 4 (Version 2.4)\r
+  // MinorVersion\r
   //\r
-  0x04,\r
+  (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) & 0x00ff),\r
   //\r
   // MaxStructureSize, TO BE FILLED\r
   //\r
@@ -141,7 +141,6 @@ GetSmbiosStructureSize (
   //\r
   while (*CharInStr != 0 || *(CharInStr+1) != 0) { \r
     if (*CharInStr == 0) {\r
-      *NumberOfStrings += 1;\r
       *Size += 1;\r
       CharInStr++;\r
     }\r
@@ -160,12 +159,9 @@ GetSmbiosStructureSize (
     //\r
     CharInStr += StrLen;\r
     *Size += StrLen;\r
-    \r
-  }\r
-\r
-  if (*NumberOfStrings > 0) {\r
     *NumberOfStrings += 1;\r
   }\r
+\r
   //\r
   // count ending two zeros.\r
   //\r
@@ -358,12 +354,12 @@ SmbiosAdd (
   //\r
   // Allocate internal buffer\r
   //\r
-  SmbiosEntry = AllocatePool (TotalSize);\r
+  SmbiosEntry = AllocateZeroPool (TotalSize);\r
   if (SmbiosEntry == NULL) {\r
     EfiReleaseLock (&Private->DataLock);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  HandleEntry = AllocatePool (sizeof(SMBIOS_HANDLE_ENTRY));\r
+  HandleEntry = AllocateZeroPool (sizeof(SMBIOS_HANDLE_ENTRY));\r
   if (HandleEntry == NULL) {\r
     EfiReleaseLock (&Private->DataLock);\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -372,12 +368,10 @@ SmbiosAdd (
   //\r
   // Build Handle Entry and insert into linked list\r
   //\r
-  ZeroMem(HandleEntry, sizeof(SMBIOS_HANDLE_ENTRY));\r
   HandleEntry->Signature     = SMBIOS_HANDLE_ENTRY_SIGNATURE;\r
   HandleEntry->SmbiosHandle  = *SmbiosHandle;\r
   InsertTailList(&Private->AllocatedHandleListHead, &HandleEntry->Link);\r
 \r
-  ZeroMem (SmbiosEntry, TotalSize);\r
   InternalRecord  = (EFI_SMBIOS_RECORD_HEADER *) (SmbiosEntry + 1);\r
   Raw     = (VOID *) (InternalRecord + 1);\r
 \r
@@ -513,6 +507,11 @@ SmbiosUpdateString (
         } \r
       }\r
 \r
+      if (*StrStart == 0) {\r
+        StrStart ++;\r
+        TargetStrOffset ++;\r
+      }\r
+      \r
       //\r
       // Now we get the string target\r
       //\r
@@ -528,14 +527,13 @@ SmbiosUpdateString (
       // Re-allocate buffer is needed.\r
       //\r
       NewEntrySize = SmbiosEntry->RecordSize + InputStrLen - TargetStrLen;\r
-      ResizedSmbiosEntry = AllocatePool (NewEntrySize);\r
+      ResizedSmbiosEntry = AllocateZeroPool (NewEntrySize);\r
 \r
       if (ResizedSmbiosEntry == NULL) {\r
         EfiReleaseLock (&Private->DataLock);\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
 \r
-      ZeroMem (ResizedSmbiosEntry, NewEntrySize);\r
       InternalRecord  = (EFI_SMBIOS_RECORD_HEADER *) (ResizedSmbiosEntry + 1);\r
       Raw     = (VOID *) (InternalRecord + 1);\r
 \r
@@ -551,9 +549,11 @@ SmbiosUpdateString (
       //\r
       // Copy smbios structure and optional strings.\r
       //\r
-      CopyMem (Raw, SmbiosEntry->RecordHeader + 1, sizeof(EFI_SMBIOS_TABLE_HEADER) + TargetStrOffset);\r
-      CopyMem ((VOID*)((UINTN)Raw + sizeof(EFI_SMBIOS_TABLE_HEADER) + TargetStrOffset), String, InputStrLen + 1);\r
-      AsciiStrCpy((CHAR8*)((UINTN)Raw + sizeof(EFI_SMBIOS_TABLE_HEADER) + TargetStrOffset + InputStrLen + 1), (CHAR8*)Record + Record->Length + TargetStrOffset + TargetStrLen + 1);\r
+      CopyMem (Raw, SmbiosEntry->RecordHeader + 1, Record->Length + TargetStrOffset);\r
+      CopyMem ((VOID*)((UINTN)Raw + Record->Length + TargetStrOffset), String, InputStrLen + 1);\r
+      CopyMem ((CHAR8*)((UINTN)Raw + Record->Length + TargetStrOffset + InputStrLen + 1),\r
+               (CHAR8*)Record + Record->Length + TargetStrOffset + TargetStrLen + 1,\r
+               SmbiosEntry->RecordHeader->RecordSize - sizeof (EFI_SMBIOS_RECORD_HEADER) - Record->Length - TargetStrOffset - TargetStrLen - 1);\r
 \r
       //\r
       // Insert new record\r
@@ -811,7 +811,7 @@ SmbiosCreateTable (
   //\r
   // Free the original image\r
   //\r
-  if (EntryPointStructure->TableAddress) {\r
+  if (EntryPointStructure->TableAddress != 0) {\r
     FreePages (\r
           (VOID*)(UINTN)EntryPointStructure->TableAddress,\r
           EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength)\r
@@ -822,8 +822,8 @@ SmbiosCreateTable (
   //\r
   // Locate smbios protocol to traverse smbios records.\r
   //\r
-  gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &SmbiosProtocol);\r
-  \r
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &SmbiosProtocol);\r
+  ASSERT_EFI_ERROR (Status);\r
   ASSERT (SmbiosProtocol != NULL);\r
 \r
   //\r
@@ -851,7 +851,7 @@ SmbiosCreateTable (
       //\r
       // Record NumberOfSmbiosStructures, TableLength and MaxStructureSize\r
       //\r
-      EntryPointStructure->NumberOfSmbiosStructures++;\r
+      EntryPointStructure->NumberOfSmbiosStructures ++;\r
       EntryPointStructure->TableLength = (UINT16) (EntryPointStructure->TableLength + RecordSize);\r
       if (RecordSize > EntryPointStructure->MaxStructureSize) {\r
         EntryPointStructure->MaxStructureSize = (UINT16) RecordSize;\r
@@ -997,8 +997,8 @@ SmbiosDriverEntryPoint (
   mPrivateData.Smbios.UpdateString      = SmbiosUpdateString;\r
   mPrivateData.Smbios.Remove            = SmbiosRemove;\r
   mPrivateData.Smbios.GetNext           = SmbiosGetNext;\r
-  mPrivateData.Smbios.MajorVersion      = SMBIOS_MAJOR_VERSION;\r
-  mPrivateData.Smbios.MinorVersion      = SMBIOS_MINOR_VERSION;\r
+  mPrivateData.Smbios.MajorVersion      = (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) >> 8);\r
+  mPrivateData.Smbios.MinorVersion      = (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) & 0x00ff);\r
 \r
   InitializeListHead (&mPrivateData.DataListHead);\r
   InitializeListHead (&mPrivateData.AllocatedHandleListHead);\r