]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / SmbiosPlatformDxe / SmbiosPlatformDxe.c
index ac48fb720819292092c6eba44cd9aaa7fef6db22..94249d3ff1b0fb21363af713f0c37dbfc970f72d 100644 (file)
@@ -2,55 +2,65 @@
   This driver installs SMBIOS information for OVMF\r
 \r
   Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>\r
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 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
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
-#include "SmbiosPlatformDxe.h"\r
-\r
-\r
-/**\r
-  Validates the SMBIOS entry point structure\r
+#include <IndustryStandard/SmBios.h>          // SMBIOS_TABLE_TYPE0\r
+#include <Library/DebugLib.h>                 // ASSERT_EFI_ERROR()\r
+#include <Library/UefiBootServicesTableLib.h> // gBS\r
+#include <Protocol/Smbios.h>                  // EFI_SMBIOS_PROTOCOL\r
 \r
-  @param  EntryPointStructure  SMBIOS entry point structure\r
-\r
-  @retval TRUE   The entry point structure is valid\r
-  @retval FALSE  The entry point structure is not valid\r
-\r
-**/\r
-BOOLEAN\r
-IsEntryPointStructureValid (\r
-  IN SMBIOS_TABLE_ENTRY_POINT  *EntryPointStructure\r
-  )\r
-{\r
-  UINTN                     Index;\r
-  UINT8                     Length;\r
-  UINT8                     Checksum;\r
-  UINT8                     *BytePtr;\r
-\r
-  BytePtr = (UINT8*) EntryPointStructure;\r
-  Length = EntryPointStructure->EntryPointLength;\r
-  Checksum = 0;\r
-\r
-  for (Index = 0; Index < Length; Index++) {\r
-    Checksum = Checksum + (UINT8) BytePtr[Index];\r
-  }\r
-\r
-  if (Checksum != 0) {\r
-    return FALSE;\r
-  } else {\r
-    return TRUE;\r
-  }\r
-}\r
+#include "SmbiosPlatformDxe.h"\r
 \r
+#define TYPE0_STRINGS \\r
+  "EFI Development Kit II / OVMF\0"     /* Vendor */ \\r
+  "0.0.0\0"                             /* BiosVersion */ \\r
+  "02/06/2015\0"                        /* BiosReleaseDate */\r
+//\r
+// Type definition and contents of the default Type 0 SMBIOS table.\r
+//\r
+#pragma pack(1)\r
+typedef struct {\r
+  SMBIOS_TABLE_TYPE0    Base;\r
+  UINT8                 Strings[sizeof (TYPE0_STRINGS)];\r
+} OVMF_TYPE0;\r
+#pragma pack()\r
+\r
+STATIC CONST OVMF_TYPE0  mOvmfDefaultType0 = {\r
+  {\r
+    // SMBIOS_STRUCTURE Hdr\r
+    {\r
+      EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type\r
+      sizeof (SMBIOS_TABLE_TYPE0),      // UINT8 Length\r
+    },\r
+    1,      // SMBIOS_TABLE_STRING       Vendor\r
+    2,      // SMBIOS_TABLE_STRING       BiosVersion\r
+    0xE800, // UINT16                    BiosSegment\r
+    3,      // SMBIOS_TABLE_STRING       BiosReleaseDate\r
+    0,      // UINT8                     BiosSize\r
+    {      // MISC_BIOS_CHARACTERISTICS BiosCharacteristics\r
+      0,   // Reserved                                      :2\r
+      0,   // Unknown                                       :1\r
+      1,   // BiosCharacteristicsNotSupported               :1\r
+           // Remaining BiosCharacteristics bits left unset :60\r
+    },\r
+    {      // BIOSCharacteristicsExtensionBytes[2]\r
+      0,   // BiosReserved\r
+      0x1C // SystemReserved = VirtualMachineSupported |\r
+           //                  UefiSpecificationSupported |\r
+           //                  TargetContentDistributionEnabled\r
+    },\r
+    0,     // UINT8                     SystemBiosMajorRelease\r
+    0,     // UINT8                     SystemBiosMinorRelease\r
+    0xFF,  // UINT8                     EmbeddedControllerFirmwareMajorRelease\r
+    0xFF   // UINT8                     EmbeddedControllerFirmwareMinorRelease\r
+  },\r
+  // Text strings (unformatted area)\r
+  TYPE0_STRINGS\r
+};\r
 \r
 /**\r
   Get SMBIOS record length.\r
@@ -60,7 +70,7 @@ IsEntryPointStructureValid (
 **/\r
 UINTN\r
 SmbiosTableLength (\r
-  IN SMBIOS_STRUCTURE_POINTER SmbiosTable\r
+  IN SMBIOS_STRUCTURE_POINTER  SmbiosTable\r
   )\r
 {\r
   CHAR8  *AChar;\r
@@ -72,99 +82,86 @@ SmbiosTableLength (
   // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)\r
   //\r
   while ((*AChar != 0) || (*(AChar + 1) != 0)) {\r
-    AChar ++;\r
+    AChar++;\r
   }\r
+\r
   Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);\r
 \r
   return Length;\r
 }\r
 \r
-\r
 /**\r
   Install all structures from the given SMBIOS structures block\r
 \r
-  @param  Smbios               SMBIOS protocol\r
-  @param  EntryPointStructure  SMBIOS entry point structures block\r
+  @param  TableAddress         SMBIOS tables starting address\r
 \r
 **/\r
 EFI_STATUS\r
 InstallAllStructures (\r
-  IN EFI_SMBIOS_PROTOCOL       *Smbios,\r
-  IN SMBIOS_TABLE_ENTRY_POINT  *EntryPointStructure\r
+  IN UINT8  *TableAddress\r
   )\r
 {\r
+  EFI_SMBIOS_PROTOCOL       *Smbios;\r
   EFI_STATUS                Status;\r
   SMBIOS_STRUCTURE_POINTER  SmbiosTable;\r
   EFI_SMBIOS_HANDLE         SmbiosHandle;\r
+  BOOLEAN                   NeedSmbiosType0;\r
+\r
+  //\r
+  // Find the SMBIOS protocol\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiSmbiosProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&Smbios\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
-  SmbiosTable.Raw = (UINT8*)(UINTN) EntryPointStructure->TableAddress;\r
+  SmbiosTable.Raw = TableAddress;\r
   if (SmbiosTable.Raw == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  NeedSmbiosType0 = TRUE;\r
+\r
   while (SmbiosTable.Hdr->Type != 127) {\r
     //\r
     // Log the SMBIOS data for this structure\r
     //\r
     SmbiosHandle = SmbiosTable.Hdr->Handle;\r
-    Status = Smbios->Add (\r
-                       Smbios,\r
-                       NULL,\r
-                       &SmbiosHandle,\r
-                       (EFI_SMBIOS_TABLE_HEADER*) SmbiosTable.Raw\r
-                       );\r
+    Status       = Smbios->Add (\r
+                             Smbios,\r
+                             NULL,\r
+                             &SmbiosHandle,\r
+                             (EFI_SMBIOS_TABLE_HEADER *)SmbiosTable.Raw\r
+                             );\r
     ASSERT_EFI_ERROR (Status);\r
 \r
+    if (SmbiosTable.Hdr->Type == 0) {\r
+      NeedSmbiosType0 = FALSE;\r
+    }\r
+\r
     //\r
     // Get the next structure address\r
     //\r
     SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));\r
   }\r
 \r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
-  Installs SMBIOS information for OVMF\r
-\r
-  @param ImageHandle     Module's image handle\r
-  @param SystemTable     Pointer of EFI_SYSTEM_TABLE\r
-\r
-  @retval EFI_SUCCESS    Smbios data successfully installed\r
-  @retval Other          Smbios data was not installed\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SmbiosTablePublishEntry (\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS                Status;\r
-  EFI_SMBIOS_PROTOCOL       *Smbios;\r
-  SMBIOS_TABLE_ENTRY_POINT  *EntryPointStructure;\r
-\r
-  //\r
-  // Find the SMBIOS protocol\r
-  //\r
-  Status = gBS->LocateProtocol (\r
-                  &gEfiSmbiosProtocolGuid,\r
-                  NULL,\r
-                  (VOID**)&Smbios\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Add Xen SMBIOS data if found\r
-  //\r
-  EntryPointStructure = GetXenSmbiosTables ();\r
-  if (EntryPointStructure != NULL) {\r
-    Status = InstallAllStructures (Smbios, EntryPointStructure);\r
+  if (NeedSmbiosType0) {\r
+    //\r
+    // Add OVMF default Type 0 (BIOS Information) table\r
+    //\r
+    SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
+    Status       = Smbios->Add (\r
+                             Smbios,\r
+                             NULL,\r
+                             &SmbiosHandle,\r
+                             (EFI_SMBIOS_TABLE_HEADER *)&mOvmfDefaultType0\r
+                             );\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r