]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add SMBIOS 64-bit support for SMBIOS 3.0.
authorElvin Li <elvin.li@intel.com>
Mon, 16 Mar 2015 02:41:48 +0000 (02:41 +0000)
committerli-elvin <li-elvin@Edk2>
Mon, 16 Mar 2015 02:41:48 +0000 (02:41 +0000)
Add SMBIOS 64-bit entry point and 64-bit table support for SMBIOS 3.0.
Introduce PcdSmbiosEntryPointProvideMethod to produce 32-bit or 64-bit
SMBIOS table.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Elvin Li <elvin.li@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17051 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.uni
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf

index 02b2c25d88be925e1e91cb0b17692ccd305f9b4c..c00319a7f35aa8989d1daf4eaadf5b8a46795214 100644 (file)
   # @Prompt SMBIOS version.\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion|0x0300|UINT16|0x00010055\r
 \r
+  ## SMBIOS Docrev field in SMBIOS 3.0 (64-bit) Entry Point Structure.\r
+  # @Prompt SMBIOS Docrev field in SMBIOS 3.0 (64-bit) Entry Point Structure.\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0|UINT8|0x0001006A\r
+\r
+  ## SMBIOS produce method.\r
+  #  BIT0 set indicates 32-bit entry point and table are produced.<BR>\r
+  #  BIT1 set indicates 64-bit entry point and table are produced.<BR>\r
+  # @Prompt The policy to produce SMBIOS entry point and table.\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosEntryPointProvideMethod|0x3|UINT32|0x00010069\r
+\r
   ## This PCD specifies the additional pad size in FPDT Basic Boot Performance Table for\r
   #  the extension FPDT boot records received after ReadyToBoot and before ExitBootService.\r
   # @Prompt Pad size for extension FPDT boot records.\r
index 10e89cb5a196e40f9ab7c3ba5083b4fa098a9397..1aab112223d928e103a2ad90c3f6ba9225fcbafa 100644 (file)
Binary files a/MdeModulePkg/MdeModulePkg.uni and b/MdeModulePkg/MdeModulePkg.uni differ
index c0128f088f9e12a5fd69e86f35f7a857248a81f6..43d78a6a07951136087fa4c0416881ffe513ad13 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 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
@@ -22,7 +22,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 SMBIOS_INSTANCE mPrivateData;\r
 \r
-UINTN mPreAllocatedPages = 0;\r
+UINTN mPreAllocatedPages      = 0;\r
+UINTN mPre64BitAllocatedPages = 0;\r
 \r
 //\r
 // Chassis for SMBIOS entry point structure that is to be installed into EFI system config table.\r
@@ -104,8 +105,55 @@ SMBIOS_TABLE_ENTRY_POINT EntryPointStructureData = {
   0\r
 };\r
 \r
-\r
-\r
+SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30EntryPointStructure    = NULL;\r
+SMBIOS_TABLE_3_0_ENTRY_POINT Smbios30EntryPointStructureData = {\r
+  //\r
+  // AnchorString _SM3_\r
+  //\r
+  {\r
+    0x5f,\r
+    0x53,\r
+    0x4d,\r
+    0x33,\r
+    0x5f,\r
+  },\r
+  //\r
+  // EntryPointStructureChecksum,TO BE FILLED\r
+  //\r
+  0,\r
+  //\r
+  // EntryPointLength\r
+  //\r
+  0x18,\r
+  //\r
+  // MajorVersion\r
+  //\r
+  0,\r
+  //\r
+  // MinorVersion\r
+  //\r
+  0,\r
+  //\r
+  // DocRev\r
+  //\r
+  0,\r
+  //\r
+  // EntryPointRevision\r
+  //\r
+  0x01,\r
+  //\r
+  // Reserved\r
+  //\r
+  0,\r
+  //\r
+  // TableMaximumSize,TO BE FILLED\r
+  //\r
+  0,\r
+  //\r
+  // TableAddress,TO BE FILLED\r
+  //\r
+  0\r
+};\r
 /**\r
 \r
   Get the full size of SMBIOS structure including optional strings that follow the formatted structure.\r
@@ -153,7 +201,7 @@ GetSmbiosStructureSize (
 \r
     if (This->MajorVersion < 2 || (This->MajorVersion == 2 && This->MinorVersion < 7)){\r
       MaxLen = SMBIOS_STRING_MAX_LENGTH;\r
-    } else {\r
+    } else if (This->MajorVersion < 3) {\r
       //\r
       // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string.\r
       // However, the length of the entire structure table (including all strings) must be reported\r
@@ -161,6 +209,12 @@ GetSmbiosStructureSize (
       // which is a WORD field limited to 65,535 bytes.\r
       //\r
       MaxLen = SMBIOS_TABLE_MAX_LENGTH;\r
+    } else {\r
+      //\r
+      // SMBIOS 3.0 defines the Structure table maximum size as DWORD field limited to 0xFFFFFFFF bytes.\r
+      // Locate the end of string as long as possible.\r
+      //\r
+      MaxLen = SMBIOS_3_0_TABLE_MAX_LENGTH;\r
     }\r
 \r
     for (StrLen = 0 ; StrLen < MaxLen; StrLen++) {\r
@@ -319,6 +373,8 @@ SmbiosAdd (
   EFI_SMBIOS_HANDLE           MaxSmbiosHandle;\r
   SMBIOS_HANDLE_ENTRY         *HandleEntry;\r
   EFI_SMBIOS_RECORD_HEADER    *InternalRecord;\r
+  BOOLEAN                     Smbios32BitTable;\r
+  BOOLEAN                     Smbios64BitTable;\r
   \r
   if (SmbiosHandle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -359,11 +415,44 @@ SmbiosAdd (
     return Status;\r
   }\r
 \r
-  if (EntryPointStructure->TableLength + StructureSize > SMBIOS_TABLE_MAX_LENGTH) {\r
+  Smbios32BitTable = FALSE;\r
+  Smbios64BitTable = FALSE;\r
+  if ((This->MajorVersion < 0x3) || \r
+      ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT0) == BIT0))) {\r
     //\r
-    // The length of the entire structure table (including all strings) must be reported\r
+    // For SMBIOS 32-bit table, the length of the entire structure table (including all strings) must be reported\r
     // in the Structure Table Length field of the SMBIOS Structure Table Entry Point,\r
-    // which is a WORD field limited to 65,535 bytes.\r
+    // which is a WORD field limited to 65,535 bytes. So the max size of 32-bit table should not exceed 65,535 bytes.\r
+    //\r
+    if ((EntryPointStructure != NULL) && \r
+        (EntryPointStructure->TableLength + StructureSize > SMBIOS_TABLE_MAX_LENGTH)) {\r
+      DEBUG ((EFI_D_INFO, "SmbiosAdd: Total length exceeds max 32-bit table length with type = %d size = 0x%x\n", Record->Type, StructureSize));\r
+    } else {\r
+      Smbios32BitTable = TRUE;\r
+      DEBUG ((EFI_D_INFO, "SmbiosAdd: Smbios type %d with size 0x%x is added to 32-bit table\n", Record->Type, StructureSize));\r
+    }\r
+  }\r
+  \r
+  //\r
+  // For SMBIOS 3.0, Structure table maximum size in Entry Point structure is DWORD field limited to 0xFFFFFFFF bytes.\r
+  //\r
+  if ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT1) == BIT1)) {\r
+    //\r
+    // For SMBIOS 64-bit table, Structure table maximum size in SMBIOS 3.0 (64-bit) Entry Point\r
+    // is a DWORD field limited to 0xFFFFFFFF bytes. So the max size of 64-bit table should not exceed 0xFFFFFFFF bytes.\r
+    //\r
+    if ((Smbios30EntryPointStructure != NULL) && \r
+        (Smbios30EntryPointStructure->TableMaximumSize + StructureSize > SMBIOS_3_0_TABLE_MAX_LENGTH)) {\r
+      DEBUG ((EFI_D_INFO, "SmbiosAdd: Total length exceeds max 64-bit table length with type = %d size = 0x%x\n", Record->Type, StructureSize));\r
+    } else {\r
+      DEBUG ((EFI_D_INFO, "SmbiosAdd: Smbios type %d with size 0x%x is added to 64-bit table\n", Record->Type, StructureSize));\r
+      Smbios64BitTable = TRUE;\r
+    }\r
+  }\r
+\r
+  if ((!Smbios32BitTable) && (!Smbios64BitTable)) {\r
+    //\r
+    // If both 32-bit and 64-bit table are not updated, quit\r
     //\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -417,6 +506,8 @@ SmbiosAdd (
   SmbiosEntry->Signature    = EFI_SMBIOS_ENTRY_SIGNATURE;\r
   SmbiosEntry->RecordHeader = InternalRecord;\r
   SmbiosEntry->RecordSize   = TotalSize;\r
+  SmbiosEntry->Smbios32BitTable = Smbios32BitTable;\r
+  SmbiosEntry->Smbios64BitTable = Smbios64BitTable;\r
   InsertTailList (&Private->DataListHead, &SmbiosEntry->Link);\r
 \r
   CopyMem (Raw, Record, StructureSize);\r
@@ -428,7 +519,7 @@ SmbiosAdd (
   // configuration table, so other UEFI drivers can get SMBIOS table from\r
   // configuration table without depending on PI SMBIOS protocol.\r
   //\r
-  SmbiosTableConstruction ();\r
+  SmbiosTableConstruction (Smbios32BitTable, Smbios64BitTable);\r
   \r
   //\r
   // Leave critical section\r
@@ -500,7 +591,7 @@ SmbiosUpdateString (
     if (InputStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
       return EFI_UNSUPPORTED;\r
     }\r
-  } else {\r
+  } else if (This->MajorVersion < 3) {\r
     //\r
     // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string.\r
     // However, the length of the entire structure table (including all strings) must be reported \r
@@ -510,6 +601,14 @@ SmbiosUpdateString (
     if (InputStrLen > SMBIOS_TABLE_MAX_LENGTH) {\r
       return EFI_UNSUPPORTED;\r
     }\r
+  } else {\r
+    if (InputStrLen > SMBIOS_3_0_TABLE_MAX_LENGTH) {\r
+      //\r
+      // SMBIOS 3.0 defines the Structure table maximum size as DWORD field limited to 0xFFFFFFFF bytes.\r
+      // The input string length should not exceed 0xFFFFFFFF bytes.\r
+      // \r
+      return EFI_UNSUPPORTED;\r
+    }\r
   }\r
 \r
   Private = SMBIOS_INSTANCE_FROM_THIS (This);\r
@@ -573,17 +672,47 @@ SmbiosUpdateString (
         // configuration table, so other UEFI drivers can get SMBIOS table from\r
         // configuration table without depending on PI SMBIOS protocol.\r
         //\r
-        SmbiosTableConstruction ();\r
+        SmbiosTableConstruction (SmbiosEntry->Smbios32BitTable, SmbiosEntry->Smbios64BitTable);\r
         EfiReleaseLock (&Private->DataLock);\r
         return EFI_SUCCESS;\r
       }\r
+      \r
+      SmbiosEntry->Smbios32BitTable = FALSE;\r
+      SmbiosEntry->Smbios64BitTable = FALSE;\r
+      if ((This->MajorVersion < 0x3) || \r
+          ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT0) == BIT0))) {\r
+        //\r
+        // 32-bit table is produced, check the valid length.\r
+        //\r
+        if ((EntryPointStructure != NULL) && \r
+            (EntryPointStructure->TableLength + InputStrLen - TargetStrLen > SMBIOS_TABLE_MAX_LENGTH)) {\r
+          //\r
+          // The length of the entire structure table (including all strings) must be reported\r
+          // in the Structure Table Length field of the SMBIOS Structure Table Entry Point,\r
+          // which is a WORD field limited to 65,535 bytes.\r
+          //\r
+          DEBUG ((EFI_D_INFO, "SmbiosUpdateString: Total length exceeds max 32-bit table length\n"));\r
+        } else {\r
+          DEBUG ((EFI_D_INFO, "SmbiosUpdateString: New smbios record add to 32-bit table\n"));\r
+          SmbiosEntry->Smbios32BitTable = TRUE;\r
+        }\r
+      } \r
 \r
-      if (EntryPointStructure->TableLength + InputStrLen - TargetStrLen > SMBIOS_TABLE_MAX_LENGTH) {\r
+      if ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT1) == BIT1)) {\r
         //\r
-        // The length of the entire structure table (including all strings) must be reported\r
-        // in the Structure Table Length field of the SMBIOS Structure Table Entry Point,\r
-        // which is a WORD field limited to 65,535 bytes.\r
+        // 64-bit table is produced, check the valid length.\r
         //\r
+        if ((Smbios30EntryPointStructure != NULL) && \r
+            (Smbios30EntryPointStructure->TableMaximumSize + InputStrLen - TargetStrLen > SMBIOS_3_0_TABLE_MAX_LENGTH)) {\r
+          DEBUG ((EFI_D_INFO, "SmbiosUpdateString: Total length exceeds max 64-bit table length\n"));\r
+        } else {\r
+          DEBUG ((EFI_D_INFO, "SmbiosUpdateString: New smbios record add to 64-bit table\n"));\r
+          SmbiosEntry->Smbios64BitTable = TRUE;\r
+        }\r
+      }\r
+\r
+      if ((!SmbiosEntry->Smbios32BitTable) && (!SmbiosEntry->Smbios64BitTable)) {\r
+        EfiReleaseLock (&Private->DataLock);\r
         return EFI_UNSUPPORTED;\r
       }\r
 \r
@@ -626,6 +755,8 @@ SmbiosUpdateString (
       ResizedSmbiosEntry->Signature    = EFI_SMBIOS_ENTRY_SIGNATURE;\r
       ResizedSmbiosEntry->RecordHeader = InternalRecord;\r
       ResizedSmbiosEntry->RecordSize   = NewEntrySize;\r
+      ResizedSmbiosEntry->Smbios32BitTable = SmbiosEntry->Smbios32BitTable;\r
+      ResizedSmbiosEntry->Smbios64BitTable = SmbiosEntry->Smbios64BitTable;\r
       InsertTailList (Link->ForwardLink, &ResizedSmbiosEntry->Link);\r
 \r
       //\r
@@ -639,7 +770,7 @@ SmbiosUpdateString (
       // configuration table, so other UEFI drivers can get SMBIOS table from\r
       // configuration table without depending on PI SMBIOS protocol.\r
       //\r
-      SmbiosTableConstruction ();\r
+      SmbiosTableConstruction (ResizedSmbiosEntry->Smbios32BitTable, ResizedSmbiosEntry->Smbios64BitTable);\r
       EfiReleaseLock (&Private->DataLock);\r
       return EFI_SUCCESS;\r
     }\r
@@ -702,7 +833,6 @@ SmbiosRemove (
       // Remove specified smobios record from DataList\r
       //\r
       RemoveEntryList(Link);\r
-      FreePool(SmbiosEntry);\r
       // \r
       // Remove this handle from AllocatedHandleList\r
       //\r
@@ -721,7 +851,17 @@ SmbiosRemove (
       // configuration table, so other UEFI drivers can get SMBIOS table from\r
       // configuration table without depending on PI SMBIOS protocol.\r
       //\r
-      SmbiosTableConstruction ();\r
+      if (SmbiosEntry->Smbios32BitTable) {\r
+        DEBUG ((EFI_D_INFO, "SmbiosRemove: remove from 32-bit table\n"));\r
+      }\r
+      if (SmbiosEntry->Smbios64BitTable) {\r
+        DEBUG ((EFI_D_INFO, "SmbiosRemove: remove from 64-bit table\n"));\r
+      }\r
+      //\r
+      // Update the whole SMBIOS table again based on which table the removed SMBIOS record is in.\r
+      //\r
+      SmbiosTableConstruction (SmbiosEntry->Smbios32BitTable, SmbiosEntry->Smbios64BitTable);\r
+      FreePool(SmbiosEntry);\r
       EfiReleaseLock (&Private->DataLock);\r
       return EFI_SUCCESS;\r
     }\r
@@ -889,7 +1029,6 @@ GetNextSmbiosRecord (
   @param  TableEntryPointStructure   On exit, points to the SMBIOS entrypoint structure.\r
                                 \r
   @retval EFI_SUCCESS                Structure created sucessfully.\r
-  @retval EFI_NOT_READY              Some of The SMBIOS records was not available yet.\r
   @retval EFI_OUT_OF_RESOURCES       No enough memory.\r
   \r
 **/\r
@@ -913,6 +1052,45 @@ SmbiosCreateTable (
   Status            = EFI_SUCCESS;\r
   BufferPointer     = NULL;\r
 \r
+  if (EntryPointStructure == NULL) {\r
+    //\r
+    // Initialize the EntryPointStructure with initial values.\r
+    // It should be done only once.\r
+    // Allocate memory (below 4GB).\r
+    //\r
+    DEBUG ((EFI_D_INFO, "SmbiosCreateTable: Initialize 32-bit entry point structure\n"));\r
+    EntryPointStructureData.MajorVersion  = mPrivateData.Smbios.MajorVersion;\r
+    EntryPointStructureData.MinorVersion  = mPrivateData.Smbios.MinorVersion;\r
+    EntryPointStructureData.SmbiosBcdRevision = (UINT8) ((PcdGet16 (PcdSmbiosVersion) >> 4) & 0xf0) | (UINT8) (PcdGet16 (PcdSmbiosVersion) & 0x0f);\r
+    PhysicalAddress = 0xffffffff;\r
+    Status = gBS->AllocatePages (\r
+                    AllocateMaxAddress,\r
+                    EfiRuntimeServicesData,\r
+                    EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT)),\r
+                    &PhysicalAddress\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "SmbiosCreateTable () could not allocate EntryPointStructure < 4GB\n"));\r
+      Status = gBS->AllocatePages (\r
+                      AllocateAnyPages,\r
+                      EfiRuntimeServicesData,\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
+    \r
+    CopyMem (\r
+      EntryPointStructure,\r
+      &EntryPointStructureData,\r
+      sizeof (SMBIOS_TABLE_ENTRY_POINT)\r
+      );\r
+  }\r
+\r
   //\r
   // Get Smbios protocol to traverse SMBIOS records.\r
   //\r
@@ -932,7 +1110,7 @@ SmbiosCreateTable (
   do {\r
     Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord);\r
                                \r
-    if (Status == EFI_SUCCESS) {\r
+    if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios32BitTable)) {\r
       GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr);\r
       //\r
       // Record NumberOfSmbiosStructures, TableLength and MaxStructureSize\r
@@ -962,12 +1140,13 @@ SmbiosCreateTable (
 \r
   if ((UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength) > mPreAllocatedPages) {\r
     //\r
-    // If new SMBIOS talbe size exceeds the original pre-allocated page, \r
+    // If new SMBIOS table size exceeds the previous allocated page, \r
     // it is time to re-allocate memory (below 4GB).\r
     // \r
+    DEBUG ((EFI_D_ERROR, "SmbiosCreateTable() re-allocate SMBIOS 32-bit table\n"));\r
     if (EntryPointStructure->TableAddress != 0) {\r
       //\r
-      // Free the original pre-allocated page\r
+      // Free the previous allocated page\r
       //      \r
       FreePages (\r
             (VOID*)(UINTN)EntryPointStructure->TableAddress,\r
@@ -1003,7 +1182,7 @@ SmbiosCreateTable (
   do {\r
     Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord);\r
 \r
-    if (Status == EFI_SUCCESS) {\r
+    if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios32BitTable)) {\r
       GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr);\r
       CopyMem (BufferPointer, SmbiosRecord, RecordSize);\r
       BufferPointer = BufferPointer + RecordSize;\r
@@ -1035,20 +1214,201 @@ SmbiosCreateTable (
 }\r
 \r
 /**\r
-  Create SMBIOS Table and install it to the System Table.\r
+  Assembles SMBIOS 64-bit table from the SMBIOS protocol. Produce Table\r
+  Entry Point and return the pointer to it.\r
+\r
+  @param  TableEntryPointStructure   On exit, points to the SMBIOS entrypoint structure.\r
+\r
+  @retval EFI_SUCCESS                Structure created sucessfully.\r
+  @retval EFI_OUT_OF_RESOURCES       No enough memory.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmbiosCreate64BitTable (\r
+  OUT VOID    **TableEntryPointStructure\r
+  )\r
+{\r
+  UINT8                           *BufferPointer;\r
+  UINTN                           RecordSize;\r
+  UINTN                           NumOfStr;\r
+  EFI_STATUS                      Status;\r
+  EFI_SMBIOS_HANDLE               SmbiosHandle;\r
+  EFI_SMBIOS_PROTOCOL             *SmbiosProtocol;\r
+  EFI_PHYSICAL_ADDRESS            PhysicalAddress;\r
+  EFI_SMBIOS_TABLE_HEADER         *SmbiosRecord;\r
+  EFI_SMBIOS_TABLE_END_STRUCTURE  EndStructure;\r
+  EFI_SMBIOS_ENTRY                *CurrentSmbiosEntry;\r
+  \r
+  Status            = EFI_SUCCESS;\r
+  BufferPointer     = NULL;\r
+\r
+  if (Smbios30EntryPointStructure == NULL) {\r
+    //\r
+    // Initialize the Smbios30EntryPointStructure with initial values.\r
+    // It should be done only once.\r
+    // Allocate memory at any address.\r
+    //\r
+    DEBUG ((EFI_D_INFO, "SmbiosCreateTable: Initialize 64-bit entry point structure\n"));\r
+    Smbios30EntryPointStructureData.MajorVersion  = mPrivateData.Smbios.MajorVersion;\r
+    Smbios30EntryPointStructureData.MinorVersion  = mPrivateData.Smbios.MinorVersion;\r
+    Smbios30EntryPointStructureData.DocRev        = PcdGet8 (PcdSmbiosDocRev);\r
+    Status = gBS->AllocatePages (\r
+                    AllocateAnyPages,\r
+                    EfiRuntimeServicesData,\r
+                    EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT)),\r
+                    &PhysicalAddress\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "SmbiosCreate64BitTable() could not allocate Smbios30EntryPointStructure\n"));\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    \r
+    Smbios30EntryPointStructure = (SMBIOS_TABLE_3_0_ENTRY_POINT *) (UINTN) PhysicalAddress;\r
+    \r
+    CopyMem (\r
+      Smbios30EntryPointStructure,\r
+      &Smbios30EntryPointStructureData,\r
+      sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT)\r
+      );\r
+  }\r
+\r
+  //\r
+  // Get Smbios protocol to traverse SMBIOS records.\r
+  //\r
+  SmbiosProtocol = &mPrivateData.Smbios;\r
+  Smbios30EntryPointStructure->TableMaximumSize = 0;\r
+\r
+  //\r
+  // Calculate EPS Table Length\r
+  //\r
+  CurrentSmbiosEntry = NULL;\r
+  do {\r
+    Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord);\r
+                               \r
+    if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios64BitTable)) {\r
+      GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr);\r
+      //\r
+      // Record TableMaximumSize\r
+      //\r
+      Smbios30EntryPointStructure->TableMaximumSize = (UINT32) (Smbios30EntryPointStructure->TableMaximumSize + RecordSize);\r
+    }\r
+  } while (!EFI_ERROR(Status));\r
+\r
+  //\r
+  // Create End-Of-Table structure\r
+  //\r
+  GetMaxSmbiosHandle(SmbiosProtocol, &SmbiosHandle);\r
+  EndStructure.Header.Type = EFI_SMBIOS_TYPE_END_OF_TABLE;\r
+  EndStructure.Header.Length = (UINT8) sizeof (EFI_SMBIOS_TABLE_HEADER);\r
+  EndStructure.Header.Handle = SmbiosHandle;\r
+  EndStructure.Tailing[0] = 0;\r
+  EndStructure.Tailing[1] = 0;\r
+  Smbios30EntryPointStructure->TableMaximumSize = (UINT32) (Smbios30EntryPointStructure->TableMaximumSize + sizeof (EndStructure));\r
+\r
+  if ((UINTN) EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize) > mPre64BitAllocatedPages) {\r
+    //\r
+    // If new SMBIOS table size exceeds the previous allocated page, \r
+    // it is time to re-allocate memory at anywhere.\r
+    //\r
+    DEBUG ((EFI_D_ERROR, "SmbiosCreate64BitTable() re-allocate SMBIOS 64-bit table\n"));\r
+    if (Smbios30EntryPointStructure->TableAddress != 0) {\r
+      //\r
+      // Free the previous allocated page\r
+      //      \r
+      FreePages (\r
+            (VOID*)(UINTN)Smbios30EntryPointStructure->TableAddress,\r
+            mPre64BitAllocatedPages\r
+            );\r
+      Smbios30EntryPointStructure->TableAddress = 0;\r
+      mPre64BitAllocatedPages = 0;\r
+    }\r
+\r
+    Status = gBS->AllocatePages (\r
+                    AllocateAnyPages,\r
+                    EfiRuntimeServicesData,\r
+                    EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize),\r
+                    &PhysicalAddress\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "SmbiosCreateTable() could not allocate SMBIOS 64-bit table\n"));\r
+      Smbios30EntryPointStructure->TableAddress = 0;\r
+      return EFI_OUT_OF_RESOURCES;\r
+    } else {\r
+      Smbios30EntryPointStructure->TableAddress = PhysicalAddress;\r
+      mPre64BitAllocatedPages = EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Assemble the tables\r
+  //\r
+  ASSERT (Smbios30EntryPointStructure->TableAddress != 0);\r
+  BufferPointer = (UINT8 *) (UINTN) Smbios30EntryPointStructure->TableAddress;\r
+  CurrentSmbiosEntry = NULL;\r
+  do {\r
+    Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord);\r
+\r
+    if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios64BitTable)) {\r
+      //\r
+      // This record can be added to 64-bit table\r
+      //\r
+      GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr);\r
+      CopyMem (BufferPointer, SmbiosRecord, RecordSize);\r
+      BufferPointer = BufferPointer + RecordSize;\r
+    }\r
+  } while (!EFI_ERROR(Status));\r
+\r
+  //\r
+  // Assemble End-Of-Table structure\r
+  //\r
+  CopyMem (BufferPointer, &EndStructure, sizeof (EndStructure));\r
+\r
+  //\r
+  // Fixup checksums in the Entry Point Structure\r
+  //\r
+  Smbios30EntryPointStructure->EntryPointStructureChecksum = 0;\r
+  Smbios30EntryPointStructure->EntryPointStructureChecksum =\r
+    CalculateCheckSum8 ((UINT8 *) Smbios30EntryPointStructure, Smbios30EntryPointStructure->EntryPointLength);\r
+\r
+  //\r
+  // Returns the pointer\r
+  //\r
+  *TableEntryPointStructure = Smbios30EntryPointStructure;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Create Smbios Table and installs the Smbios Table to the System Table.\r
+  \r
+  @param  Smbios32BitTable    The flag to update 32-bit table.\r
+  @param  Smbios64BitTable    The flag to update 64-bit table.\r
+\r
 **/\r
 VOID\r
 EFIAPI\r
 SmbiosTableConstruction (\r
-  VOID\r
+  BOOLEAN     Smbios32BitTable,\r
+  BOOLEAN     Smbios64BitTable\r
   )\r
 {\r
   UINT8       *Eps;\r
+  UINT8       *Eps64Bit;\r
   EFI_STATUS  Status;\r
 \r
-  Status = SmbiosCreateTable ((VOID **) &Eps);\r
-  if (!EFI_ERROR (Status)) {\r
-    gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, Eps);\r
+  if (Smbios32BitTable) {\r
+    Status = SmbiosCreateTable ((VOID **) &Eps);\r
+    if (!EFI_ERROR (Status)) {\r
+      gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, Eps);\r
+    }\r
+  }\r
+\r
+  if (Smbios64BitTable) {\r
+    Status = SmbiosCreate64BitTable ((VOID **) &Eps64Bit);\r
+    if (!EFI_ERROR (Status)) {\r
+      gBS->InstallConfigurationTable (&gEfiSmbios3TableGuid, Eps64Bit);\r
+    }\r
   }\r
 }\r
 \r
@@ -1071,7 +1431,6 @@ SmbiosDriverEntryPoint (
   )\r
 {\r
   EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  PhysicalAddress;\r
 \r
   mPrivateData.Signature                = SMBIOS_INSTANCE_SIGNATURE;\r
   mPrivateData.Smbios.Add               = SmbiosAdd;\r
@@ -1080,72 +1439,10 @@ SmbiosDriverEntryPoint (
   mPrivateData.Smbios.GetNext           = SmbiosGetNext;\r
   mPrivateData.Smbios.MajorVersion      = (UINT8) (PcdGet16 (PcdSmbiosVersion) >> 8);\r
   mPrivateData.Smbios.MinorVersion      = (UINT8) (PcdGet16 (PcdSmbiosVersion) & 0x00ff);\r
-  EntryPointStructureData.MajorVersion  = mPrivateData.Smbios.MajorVersion;\r
-  EntryPointStructureData.MinorVersion  = mPrivateData.Smbios.MinorVersion;\r
-  EntryPointStructureData.SmbiosBcdRevision = (UINT8) ((PcdGet16 (PcdSmbiosVersion) >> 4) & 0xf0) | (UINT8) (PcdGet16 (PcdSmbiosVersion) & 0x0f);\r
 \r
   InitializeListHead (&mPrivateData.DataListHead);\r
   InitializeListHead (&mPrivateData.AllocatedHandleListHead);\r
   EfiInitializeLock (&mPrivateData.DataLock, TPL_NOTIFY);\r
-\r
-  //\r
-  // Initialize the EntryPointStructure with initial values.\r
-  // Allocate memory (below 4GB).\r
-  //\r
-  PhysicalAddress = 0xffffffff;\r
-  Status = gBS->AllocatePages (\r
-                  AllocateMaxAddress,\r
-                  EfiRuntimeServicesData,\r
-                  EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT)),\r
-                  &PhysicalAddress\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "SmbiosDriverEntryPoint() could not allocate EntryPointStructure < 4GB\n"));\r
-    Status = gBS->AllocatePages (\r
-                    AllocateAnyPages,\r
-                    EfiRuntimeServicesData,\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
-  \r
-  CopyMem (\r
-    EntryPointStructure,\r
-    &EntryPointStructureData,\r
-    sizeof (SMBIOS_TABLE_ENTRY_POINT)\r
-    );\r
-\r
-  //\r
-  // Pre-allocate 1 page for SMBIOS table below 4GB.\r
-  // SMBIOS table will be updated when new SMBIOS type is added or \r
-  // existing SMBIOS type is updated. If the total size of SMBIOS table exceeds 1 page,\r
-  // we will re-allocate new memory when creating whole SMBIOS table.\r
-  //\r
-  PhysicalAddress = 0xffffffff;\r
-  Status = gBS->AllocatePages (\r
-                  AllocateMaxAddress,\r
-                  EfiRuntimeServicesData,\r
-                  1,\r
-                  &PhysicalAddress\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "SmbiosDriverEntryPoint() could not allocate SMBIOS table < 4GB\n"));\r
-    EntryPointStructure->TableAddress = 0;\r
-  } else {\r
-    EntryPointStructure->TableAddress = (UINT32) PhysicalAddress;\r
-    mPreAllocatedPages = 1;\r
-  }\r
-\r
-  //\r
-  // Init TableLength to the length of End-Of-Table structure for SmbiosAdd() called at the first time\r
-  // to check the TableLength limitation.\r
-  //\r
-  EntryPointStructure->TableLength  = sizeof (EFI_SMBIOS_TABLE_END_STRUCTURE);\r
   \r
   //\r
   // Make a new handle and install the protocol\r
index e81b543672f655646a0066a4bcd17957da959f8a..f87c8de8ca07f7a66e0e2a7dac3ff6bca7bdbc7c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This code supports the implementation of the Smbios protocol\r
   \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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
@@ -38,6 +38,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 #define SMBIOS_TABLE_MAX_LENGTH 0xFFFF\r
 \r
+//\r
+// For SMBIOS 3.0, Structure table maximum size in Entry Point structure is DWORD field limited to 0xFFFFFFFF bytes.\r
+//\r
+#define SMBIOS_3_0_TABLE_MAX_LENGTH 0xFFFFFFFF\r
+\r
 #define SMBIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('S', 'B', 'i', 's')\r
 typedef struct {\r
   UINT32                Signature;\r
@@ -89,6 +94,11 @@ typedef struct {
   LIST_ENTRY                Link;\r
   EFI_SMBIOS_RECORD_HEADER  *RecordHeader;\r
   UINTN                     RecordSize;\r
+  //\r
+  // Indicate which table this record is added to.\r
+  //\r
+  BOOLEAN                   Smbios32BitTable;\r
+  BOOLEAN                   Smbios64BitTable;\r
 } EFI_SMBIOS_ENTRY;\r
 \r
 #define SMBIOS_ENTRY_FROM_LINK(link)  CR (link, EFI_SMBIOS_ENTRY, Link, EFI_SMBIOS_ENTRY_SIGNATURE)\r
@@ -117,11 +127,16 @@ typedef struct {
 \r
 /**\r
   Create Smbios Table and installs the Smbios Table to the System Table.\r
+  \r
+  @param  Smbios32BitTable    The flag to update 32-bit table.\r
+  @param  Smbios64BitTable    The flag to update 64-bit table.\r
+  \r
 **/\r
 VOID\r
 EFIAPI\r
 SmbiosTableConstruction (\r
-  VOID\r
+  BOOLEAN     Smbios32BitTable,\r
+  BOOLEAN     Smbios64BitTable\r
   );\r
 \r
 #endif\r
index 4e48bfc3efc00d331f2a88ab995f4b2e17a5c16d..cabc9d7791b42ec6ea5cb6bb7162a793067939e9 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This driver initializes and installs the SMBIOS protocol, constructs SMBIOS table into system configuration table.\r
 #\r
-# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
   gEfiSmbiosProtocolGuid                            ## PRODUCES\r
   \r
 [Guids]\r
-  gEfiSmbiosTableGuid                               ## PRODUCES ## SystemTable\r
+  gEfiSmbiosTableGuid                               ## SOMETIMES_PRODUCES ## SystemTable\r
+  gEfiSmbios3TableGuid                              ## SOMETIMES_PRODUCES ## SystemTable\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion   ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev    ## SOMETIMES_CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosEntryPointProvideMethod   ## CONSUMES\r
 \r
 [Depex]\r
   TRUE\r