Blame 0002-OvmfPkg-SmbiosPlatformDxe-install-patch-default-lega.patch

Gerd Hoffmann b0c3af
From 26146b77f6d54c44fbb984bacf8bf31683e8d477 Mon Sep 17 00:00:00 2001
Gerd Hoffmann b0c3af
From: Laszlo Ersek <lersek@redhat.com>
Gerd Hoffmann b0c3af
Date: Wed, 5 Jun 2013 10:25:13 +0200
Gerd Hoffmann b0c3af
Subject: [PATCH 2/3] OvmfPkg/SmbiosPlatformDxe: install+patch default legacy
Gerd Hoffmann b0c3af
 type0 table (X86)
Gerd Hoffmann b0c3af
Gerd Hoffmann b0c3af
Contributed-under: TianoCore Contribution Agreement 1.0
Gerd Hoffmann b0c3af
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Gerd Hoffmann b0c3af
---
Gerd Hoffmann b0c3af
 OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c          |   5 +-
Gerd Hoffmann b0c3af
 OvmfPkg/SmbiosPlatformDxe/QemuLegacyInternal.h  |  30 ++++
Gerd Hoffmann b0c3af
 OvmfPkg/SmbiosPlatformDxe/QemuType0.c           | 180 ++++++++++++++++++++++++
Gerd Hoffmann b0c3af
 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf |   1 +
Gerd Hoffmann b0c3af
 4 files changed, 215 insertions(+), 1 deletion(-)
Gerd Hoffmann b0c3af
 create mode 100644 OvmfPkg/SmbiosPlatformDxe/QemuType0.c
Gerd Hoffmann b0c3af
Gerd Hoffmann b0c3af
diff --git a/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c b/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c
Gerd Hoffmann b0c3af
index 9c57558..ed75a01 100644
Gerd Hoffmann b0c3af
--- a/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c
Gerd Hoffmann b0c3af
@@ -628,7 +628,10 @@ InstallDefaultTables (
Gerd Hoffmann b0c3af
   IN OUT BUILD_CONTEXT       *Context
Gerd Hoffmann b0c3af
   )
Gerd Hoffmann b0c3af
 {
Gerd Hoffmann b0c3af
-  return EFI_SUCCESS;
Gerd Hoffmann b0c3af
+  EFI_STATUS Status;
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  Status = InstallSmbiosType0 (Smbios, ProducerHandle, Context);
Gerd Hoffmann b0c3af
+  return Status;
Gerd Hoffmann b0c3af
 }
Gerd Hoffmann b0c3af
 
Gerd Hoffmann b0c3af
 
Gerd Hoffmann b0c3af
diff --git a/OvmfPkg/SmbiosPlatformDxe/QemuLegacyInternal.h b/OvmfPkg/SmbiosPlatformDxe/QemuLegacyInternal.h
Gerd Hoffmann b0c3af
index 8613407..ca776b5 100644
Gerd Hoffmann b0c3af
--- a/OvmfPkg/SmbiosPlatformDxe/QemuLegacyInternal.h
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/QemuLegacyInternal.h
Gerd Hoffmann b0c3af
@@ -218,4 +218,34 @@ PatchSmbiosUnformatted (
Gerd Hoffmann b0c3af
   IN  UINT8               *TableBase
Gerd Hoffmann b0c3af
   );
Gerd Hoffmann b0c3af
 
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+/**
Gerd Hoffmann b0c3af
+  Install default (fallback) table for SMBIOS Type 0.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  In case QEMU has provided no Type 0 SMBIOS table in whole, prepare one here,
Gerd Hoffmann b0c3af
+  patch it with any referring saved patches, and install it.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  @param[in]     Smbios          The EFI_SMBIOS_PROTOCOL instance used for
Gerd Hoffmann b0c3af
+                                 installing SMBIOS tables.
Gerd Hoffmann b0c3af
+  @param[in]     ProducerHandle  Passed on to Smbios->Add(), ProducerHandle
Gerd Hoffmann b0c3af
+                                 tracks the origin of installed SMBIOS tables.
Gerd Hoffmann b0c3af
+  @param[in,out] Context         The BUILD_CONTEXT object tracking installed
Gerd Hoffmann b0c3af
+                                 tables and saved patches.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  @retval EFI_SUCCESS  A Type 0 table has already been installed from the
Gerd Hoffmann b0c3af
+                       SMBIOS firmware configuration blob.
Gerd Hoffmann b0c3af
+  @retval EFI_SUCCESS  No Type 0 table was installed previously, and installing
Gerd Hoffmann b0c3af
+                       the default here has succeeded.
Gerd Hoffmann b0c3af
+  @return              Error codes from the PATCH_FORMATTED() and
Gerd Hoffmann b0c3af
+                       PATCH_UNFORMATTED() macros, except EFI_NOT_FOUND, which
Gerd Hoffmann b0c3af
+                       is only an informative result of theirs.
Gerd Hoffmann b0c3af
+**/
Gerd Hoffmann b0c3af
+EFI_STATUS
Gerd Hoffmann b0c3af
+EFIAPI
Gerd Hoffmann b0c3af
+InstallSmbiosType0 (
Gerd Hoffmann b0c3af
+  IN     EFI_SMBIOS_PROTOCOL *Smbios,
Gerd Hoffmann b0c3af
+  IN     EFI_HANDLE          ProducerHandle,
Gerd Hoffmann b0c3af
+  IN OUT BUILD_CONTEXT       *Context
Gerd Hoffmann b0c3af
+  );
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
 #endif
Gerd Hoffmann b0c3af
diff --git a/OvmfPkg/SmbiosPlatformDxe/QemuType0.c b/OvmfPkg/SmbiosPlatformDxe/QemuType0.c
Gerd Hoffmann b0c3af
new file mode 100644
Gerd Hoffmann b0c3af
index 0000000..9ec5d76
Gerd Hoffmann b0c3af
--- /dev/null
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/QemuType0.c
Gerd Hoffmann b0c3af
@@ -0,0 +1,180 @@
Gerd Hoffmann b0c3af
+/** @file
Gerd Hoffmann b0c3af
+  Install the default Type 0 SMBIOS table if QEMU doesn't provide one through
Gerd Hoffmann b0c3af
+  the firmware configuration interface.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  Copyright (C) 2013, Red Hat, Inc.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  This program and the accompanying materials are licensed and made available
Gerd Hoffmann b0c3af
+  under the terms and conditions of the BSD License which accompanies this
Gerd Hoffmann b0c3af
+  distribution.  The full text of the license may be found at
Gerd Hoffmann b0c3af
+  http://opensource.org/licenses/bsd-license.php
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
Gerd Hoffmann b0c3af
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Gerd Hoffmann b0c3af
+**/
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+#include "QemuLegacyInternal.h"
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+//
Gerd Hoffmann b0c3af
+// Text strings (unformatted area) for the default Tpe 0 SMBIOS table.
Gerd Hoffmann b0c3af
+//
Gerd Hoffmann b0c3af
+// All possible strings must be provided because Smbios->UpdateString() can
Gerd Hoffmann b0c3af
+// only update existing strings, it can't introduce new ones.
Gerd Hoffmann b0c3af
+//
Gerd Hoffmann b0c3af
+#define OVMF_TYPE0_STRINGS                                        \
Gerd Hoffmann b0c3af
+          "EFI Development Kit II / OVMF\0" /* Vendor */          \
Gerd Hoffmann b0c3af
+          "0.1\0"                           /* BiosVersion */     \
Gerd Hoffmann b0c3af
+          "06/03/2013\0"                    /* BiosReleaseDate */
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+//
Gerd Hoffmann b0c3af
+// Type definition and contents of the default Type 0 SMBIOS table.
Gerd Hoffmann b0c3af
+//
Gerd Hoffmann b0c3af
+#pragma pack(1)
Gerd Hoffmann b0c3af
+OVMF_SMBIOS (0);
Gerd Hoffmann b0c3af
+#pragma pack()
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+STATIC CONST OVMF_TYPE0 mOvmfType0 = {
Gerd Hoffmann b0c3af
+  {
Gerd Hoffmann b0c3af
+    // SMBIOS_STRUCTURE Hdr
Gerd Hoffmann b0c3af
+    {
Gerd Hoffmann b0c3af
+      EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
Gerd Hoffmann b0c3af
+      sizeof (SMBIOS_TABLE_TYPE0)       // UINT8 Length
Gerd Hoffmann b0c3af
+    },
Gerd Hoffmann b0c3af
+    1,     // SMBIOS_TABLE_STRING       Vendor
Gerd Hoffmann b0c3af
+    2,     // SMBIOS_TABLE_STRING       BiosVersion
Gerd Hoffmann b0c3af
+    0xE800,// UINT16                    BiosSegment
Gerd Hoffmann b0c3af
+    3,     // SMBIOS_TABLE_STRING       BiosReleaseDate
Gerd Hoffmann b0c3af
+    0,     // UINT8                     BiosSize
Gerd Hoffmann b0c3af
+    { 0 }, // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
Gerd Hoffmann b0c3af
+    { 0 }, // UINT8                     BIOSCharacteristicsExtensionBytes[2]
Gerd Hoffmann b0c3af
+    0,     // UINT8                     SystemBiosMajorRelease
Gerd Hoffmann b0c3af
+    1,     // UINT8                     SystemBiosMinorRelease
Gerd Hoffmann b0c3af
+    0xFF,  // UINT8                     EmbeddedControllerFirmwareMajorRelease
Gerd Hoffmann b0c3af
+    0xFF   // UINT8                     EmbeddedControllerFirmwareMinorRelease
Gerd Hoffmann b0c3af
+  },
Gerd Hoffmann b0c3af
+  OVMF_TYPE0_STRINGS
Gerd Hoffmann b0c3af
+};
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+/**
Gerd Hoffmann b0c3af
+  Install default (fallback) table for SMBIOS Type 0.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  In case QEMU has provided no Type 0 SMBIOS table in whole, prepare one here,
Gerd Hoffmann b0c3af
+  patch it with any referring saved patches, and install it.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  @param[in]     Smbios          The EFI_SMBIOS_PROTOCOL instance used for
Gerd Hoffmann b0c3af
+                                 installing SMBIOS tables.
Gerd Hoffmann b0c3af
+  @param[in]     ProducerHandle  Passed on to Smbios->Add(), ProducerHandle
Gerd Hoffmann b0c3af
+                                 tracks the origin of installed SMBIOS tables.
Gerd Hoffmann b0c3af
+  @param[in,out] Context         The BUILD_CONTEXT object tracking installed
Gerd Hoffmann b0c3af
+                                 tables and saved patches.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  @retval EFI_SUCCESS  A Type 0 table has already been installed from the
Gerd Hoffmann b0c3af
+                       SMBIOS firmware configuration blob.
Gerd Hoffmann b0c3af
+  @retval EFI_SUCCESS  No Type 0 table was installed previously, and installing
Gerd Hoffmann b0c3af
+                       the default here has succeeded.
Gerd Hoffmann b0c3af
+  @return              Error codes from the PATCH_FORMATTED() and
Gerd Hoffmann b0c3af
+                       PATCH_UNFORMATTED() macros, except EFI_NOT_FOUND, which
Gerd Hoffmann b0c3af
+                       is only an informative result of theirs.
Gerd Hoffmann b0c3af
+**/
Gerd Hoffmann b0c3af
+EFI_STATUS
Gerd Hoffmann b0c3af
+EFIAPI
Gerd Hoffmann b0c3af
+InstallSmbiosType0 (
Gerd Hoffmann b0c3af
+  IN     EFI_SMBIOS_PROTOCOL *Smbios,
Gerd Hoffmann b0c3af
+  IN     EFI_HANDLE          ProducerHandle,
Gerd Hoffmann b0c3af
+  IN OUT BUILD_CONTEXT       *Context
Gerd Hoffmann b0c3af
+  )
Gerd Hoffmann b0c3af
+{
Gerd Hoffmann b0c3af
+  TABLE_CONTEXT                       *Table;
Gerd Hoffmann b0c3af
+  OVMF_TYPE0                          OvmfType0;
Gerd Hoffmann b0c3af
+  MISC_BIOS_CHARACTERISTICS_EXTENSION *Ext;
Gerd Hoffmann b0c3af
+  EFI_STATUS                          Status;
Gerd Hoffmann b0c3af
+  EFI_SMBIOS_HANDLE                   SmbiosHandle;
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  Table = &Context->Table[0];
Gerd Hoffmann b0c3af
+  if (Table->Installed) {
Gerd Hoffmann b0c3af
+    return EFI_SUCCESS;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  CopyMem (&OvmfType0, &mOvmfType0, sizeof OvmfType0);
Gerd Hoffmann b0c3af
+  Ext = (VOID *) &OvmfType0.Base.BIOSCharacteristicsExtensionBytes[0];
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  OvmfType0.Base.BiosCharacteristics.BiosCharacteristicsNotSupported = 1;
Gerd Hoffmann b0c3af
+  Ext->SystemReserved.UefiSpecificationSupported = 1;
Gerd Hoffmann b0c3af
+  Ext->SystemReserved.VirtualMachineSupported    = 1;
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  //
Gerd Hoffmann b0c3af
+  // Default contents ready. Formatted fields must be patched before installing
Gerd Hoffmann b0c3af
+  // the table, while strings in the unformatted area will be patched
Gerd Hoffmann b0c3af
+  // afterwards.
Gerd Hoffmann b0c3af
+  //
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0, BiosSegment);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0, BiosSize);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0, BiosCharacteristics);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0,
Gerd Hoffmann b0c3af
+             BIOSCharacteristicsExtensionBytes);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0, SystemBiosMajorRelease);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0, SystemBiosMinorRelease);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0,
Gerd Hoffmann b0c3af
+             EmbeddedControllerFirmwareMajorRelease);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 0, &OvmfType0,
Gerd Hoffmann b0c3af
+             EmbeddedControllerFirmwareMinorRelease);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  //
Gerd Hoffmann b0c3af
+  // Install SMBIOS table with patched formatted area and default strings.
Gerd Hoffmann b0c3af
+  //
Gerd Hoffmann b0c3af
+  SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
Gerd Hoffmann b0c3af
+  Status = Smbios->Add (Smbios, ProducerHandle, &SmbiosHandle,
Gerd Hoffmann b0c3af
+                     (EFI_SMBIOS_TABLE_HEADER *) &OvmfType0);
Gerd Hoffmann b0c3af
+  if (EFI_ERROR (Status)) {
Gerd Hoffmann b0c3af
+    DEBUG ((DEBUG_ERROR, "%a: Smbios->Add(): %r\n", __FUNCTION__, Status));
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Table->Installed = TRUE;
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  //
Gerd Hoffmann b0c3af
+  // Patch strings in the unformatted area of the installed table.
Gerd Hoffmann b0c3af
+  //
Gerd Hoffmann b0c3af
+  Status = PATCH_UNFORMATTED (Smbios, SmbiosHandle, Context, 0, &OvmfType0,
Gerd Hoffmann b0c3af
+             Vendor);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_UNFORMATTED (Smbios, SmbiosHandle, Context, 0, &OvmfType0,
Gerd Hoffmann b0c3af
+             BiosVersion);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  Status = PATCH_UNFORMATTED (Smbios, SmbiosHandle, Context, 0, &OvmfType0,
Gerd Hoffmann b0c3af
+             BiosReleaseDate);
Gerd Hoffmann b0c3af
+  if (Status != EFI_NOT_FOUND && Status != EFI_SUCCESS) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+  return EFI_SUCCESS;
Gerd Hoffmann b0c3af
+}
Gerd Hoffmann b0c3af
diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
Gerd Hoffmann b0c3af
index 8c9f43c..3483b9c 100644
Gerd Hoffmann b0c3af
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
Gerd Hoffmann b0c3af
@@ -37,6 +37,7 @@
Gerd Hoffmann b0c3af
 [Sources.IA32, Sources.X64]
Gerd Hoffmann b0c3af
   X86Xen.c
Gerd Hoffmann b0c3af
   QemuLegacy.c
Gerd Hoffmann b0c3af
+  QemuType0.c
Gerd Hoffmann b0c3af
 
Gerd Hoffmann b0c3af
 [Sources.ARM, Sources.AARCH64]
Gerd Hoffmann b0c3af
   ArmXen.c
Gerd Hoffmann b0c3af
-- 
Gerd Hoffmann b0c3af
1.8.3.1
Gerd Hoffmann b0c3af