]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
If setting variable in Runtime and there has been a same GUID and name variable exist...
[mirror_edk2.git] / MdeModulePkg / Universal / SmbiosDxe / SmbiosDxe.c
index 56ece92c9a37129f5c13345eb85d680480f6f6f5..2d0be7cd51485f6696573725f6dc4cfebbd382e0 100644 (file)
@@ -2,7 +2,7 @@
   This code produces the Smbios protocol. It also responsible for constructing \r
   SMBIOS table into system table.\r
   \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
@@ -103,6 +103,7 @@ SMBIOS_TABLE_ENTRY_POINT EntryPointStructureData = {
 };\r
 \r
 \r
+\r
 /**\r
 \r
   Get the full size of SMBIOS structure including optional strings that follow the formatted structure.\r
@@ -126,7 +127,7 @@ GetSmbiosStructureSize (
   )\r
 {\r
   UINTN  FullSize;\r
-  UINT8  StrLen;\r
+  UINTN  StrLen;\r
   INT8*  CharInStr;\r
   \r
   if (Size == NULL || NumberOfStrings == NULL) {\r
@@ -263,7 +264,7 @@ GetAvailableSmbiosHandle (
 \r
   Private = SMBIOS_INSTANCE_FROM_THIS (This);\r
   Head = &Private->AllocatedHandleListHead;\r
-  for (AvailableHandle = 1; AvailableHandle < MaxSmbiosHandle; AvailableHandle++) {\r
+  for (AvailableHandle = 0; AvailableHandle < MaxSmbiosHandle; AvailableHandle++) {\r
     if (!CheckSmbiosHandleExistance(Head, AvailableHandle)) {\r
       *Handle = AvailableHandle;\r
       return EFI_SUCCESS;\r
@@ -280,8 +281,8 @@ GetAvailableSmbiosHandle (
   @param  This                  The EFI_SMBIOS_PROTOCOL instance.\r
   @param  ProducerHandle        The handle of the controller or driver associated with the SMBIOS information. NULL\r
                                 means no handle.\r
-  @param  SmbiosHandle          On entry, if non-zero, the handle of the SMBIOS record. If zero, then a unique handle\r
-                                will be assigned to the SMBIOS record. If the SMBIOS handle is already in use\r
+  @param  SmbiosHandle          On entry, the handle of the SMBIOS record to add. If FFFEh, then a unique handle\r
+                                will be assigned to the SMBIOS record. If the SMBIOS handle is already in use,\r
                                 EFI_ALREADY_STARTED is returned and the SMBIOS record is not updated.\r
   @param  Record                The data for the fixed portion of the SMBIOS record. The format of the record is\r
                                 determined by EFI_SMBIOS_TABLE_HEADER.Type. The size of the formatted area is defined \r
@@ -324,14 +325,14 @@ SmbiosAdd (
   // Check whether SmbiosHandle is already in use\r
   //\r
   Head = &Private->AllocatedHandleListHead;\r
-  if (*SmbiosHandle != 0 && CheckSmbiosHandleExistance(Head, *SmbiosHandle)) {\r
+  if (*SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED && CheckSmbiosHandleExistance(Head, *SmbiosHandle)) {\r
     return EFI_ALREADY_STARTED;\r
   }\r
 \r
   //\r
-  // when SmbiosHandle is zero, an available handle will be assigned\r
+  // when SmbiosHandle is 0xFFFE, an available handle will be assigned\r
   //\r
-  if (*SmbiosHandle == 0) {\r
+  if (*SmbiosHandle == SMBIOS_HANDLE_PI_RESERVED) {\r
     Status = GetAvailableSmbiosHandle(This, SmbiosHandle);\r
     if (EFI_ERROR(Status)) {\r
       return Status;\r
@@ -433,7 +434,7 @@ SmbiosAdd (
 \r
   @retval EFI_SUCCESS           SmbiosHandle had its StringNumber String updated.\r
   @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist.\r
-  @retval EFI_UNSUPPORTED       String was not added since it's longer than 64 significant characters.\r
+  @retval EFI_UNSUPPORTED       String was not added because it is longer than the SMBIOS Table supports.\r
   @retval EFI_NOT_FOUND         The StringNumber.is not valid for this SMBIOS record.\r
 \r
 **/\r
@@ -710,8 +711,8 @@ SmbiosRemove (
 \r
   @param  This                  The EFI_SMBIOS_PROTOCOL instance.\r
   @param  SmbiosHandle          On entry, points to the previous handle of the SMBIOS record. On exit, points to the\r
-                                next SMBIOS record handle. If it is zero on entry, then the first SMBIOS record\r
-                                handle will be returned. If it returns zero on exit, then there are no more SMBIOS records.\r
+                                next SMBIOS record handle. If it is FFFEh on entry, then the first SMBIOS record\r
+                                handle will be returned. If it returns FFFEh on exit, then there are no more SMBIOS records.\r
   @param  Type                  On entry it means return the next SMBIOS record of type Type. If a NULL is passed in \r
                                 this functionally it ignored. Type is not modified by the GetNext() function.\r
   @param  Record                On exit, points to the SMBIOS Record consisting of the formatted area followed by\r
@@ -752,9 +753,9 @@ SmbiosGetNext (
     SmbiosTableHeader = (EFI_SMBIOS_TABLE_HEADER*)(SmbiosEntry->RecordHeader + 1); \r
 \r
     //\r
-    // If SmbiosHandle is zero, the first matched SMBIOS record handle will be returned\r
+    // If SmbiosHandle is 0xFFFE, the first matched SMBIOS record handle will be returned\r
     //\r
-    if (*SmbiosHandle == 0) {\r
+    if (*SmbiosHandle == SMBIOS_HANDLE_PI_RESERVED) {\r
       if ((Type != NULL) && (*Type != SmbiosTableHeader->Type)) {\r
         continue;  \r
       }\r
@@ -790,7 +791,7 @@ SmbiosGetNext (
     }\r
   }\r
 \r
-  *SmbiosHandle = 0;\r
+  *SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
   return EFI_NOT_FOUND;\r
   \r
 }\r
@@ -889,7 +890,11 @@ SmbiosCreateTable (
   //\r
   SmbiosProtocol = &mPrivateData.Smbios;\r
 \r
-  PreAllocatedPages = EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength);\r
+  if (EntryPointStructure->TableAddress == 0) {\r
+    PreAllocatedPages = 0;\r
+  } else {\r
+    PreAllocatedPages = EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength);\r
+  }\r
 \r
   //\r
   // Make some statistics about all the structures\r
@@ -933,7 +938,7 @@ SmbiosCreateTable (
     EntryPointStructure->MaxStructureSize = (UINT16) sizeof (EndStructure);\r
   }\r
 \r
-  if (EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength) > PreAllocatedPages) {\r
+  if ((UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength) > PreAllocatedPages) {\r
     //\r
     // If new SMBIOS talbe size exceeds the original pre-allocated page, \r
     // it is time to re-allocate memory (below 4GB).\r
@@ -957,14 +962,18 @@ SmbiosCreateTable (
                     &PhysicalAddress\r
                     );\r
     if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "SmbiosCreateTable() could not allocate SMBIOS table < 4GB\n"));\r
+      EntryPointStructure->TableAddress = 0;\r
       return EFI_OUT_OF_RESOURCES;\r
+    } else {\r
+      EntryPointStructure->TableAddress = (UINT32) PhysicalAddress;\r
     }\r
-    EntryPointStructure->TableAddress = (UINT32) PhysicalAddress;\r
   }\r
   \r
   //\r
   // Assemble the tables\r
   //\r
+  ASSERT (EntryPointStructure->TableAddress != 0);\r
   BufferPointer = (UINT8 *) (UINTN) EntryPointStructure->TableAddress;\r
   CurrentSmbiosEntry = NULL;\r
   do {\r
@@ -985,6 +994,9 @@ SmbiosCreateTable (
   //\r
   // Fixup checksums in the Entry Point Structure\r
   //\r
+  EntryPointStructure->IntermediateChecksum = 0;\r
+  EntryPointStructure->EntryPointStructureChecksum = 0;\r
+\r
   EntryPointStructure->IntermediateChecksum =\r
     CalculateCheckSum8 ((UINT8 *) EntryPointStructure + 0x10, EntryPointStructure->EntryPointLength - 0x10);\r
   EntryPointStructure->EntryPointStructureChecksum =\r
@@ -1061,7 +1073,16 @@ SmbiosDriverEntryPoint (
                   &PhysicalAddress\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    DEBUG ((EFI_D_ERROR, "SmbiosDriverEntryPoint() could not allocate EntryPointStructure < 4GB\n"));\r
+    Status = gBS->AllocatePages (\r
+                    AllocateAnyPages,\r
+                    EfiReservedMemoryType,\r
+                    EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT)),\r
+                    &PhysicalAddress\r
+                    );\r
+   if (EFI_ERROR (Status)) {   \r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
   }\r
 \r
   EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) (UINTN) PhysicalAddress;\r
@@ -1086,14 +1107,14 @@ SmbiosDriverEntryPoint (
                   &PhysicalAddress\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePages ((VOID*) EntryPointStructure, EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT)));\r
-    EntryPointStructure = NULL;\r
-    return EFI_OUT_OF_RESOURCES;\r
+    DEBUG ((EFI_D_ERROR, "SmbiosDriverEntryPoint() could not allocate SMBIOS table < 4GB\n"));\r
+    EntryPointStructure->TableAddress = 0;\r
+    EntryPointStructure->TableLength  = 0;\r
+  } else {\r
+    EntryPointStructure->TableAddress = (UINT32) PhysicalAddress;\r
+    EntryPointStructure->TableLength  = EFI_PAGES_TO_SIZE (1);\r
   }\r
-\r
-  EntryPointStructure->TableAddress = (UINT32) PhysicalAddress;\r
-  EntryPointStructure->TableLength  = EFI_PAGES_TO_SIZE (1);\r
-\r
+  \r
   //\r
   // Make a new handle and install the protocol\r
   //\r