render / rpms / edk2

Forked from rpms/edk2 3 months ago
Clone

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

Gerd Hoffmann b0c3af
From 1b10131728dd1cff48ef1ce46820d89f21708852 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:28:09 +0200
Gerd Hoffmann b0c3af
Subject: [PATCH 3/3] OvmfPkg/SmbiosPlatformDxe: install+patch default legacy
Gerd Hoffmann b0c3af
 type1 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/QemuType1.c           | 178 ++++++++++++++++++++++++
Gerd Hoffmann b0c3af
 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf |   1 +
Gerd Hoffmann b0c3af
 4 files changed, 214 insertions(+)
Gerd Hoffmann b0c3af
 create mode 100644 OvmfPkg/SmbiosPlatformDxe/QemuType1.c
Gerd Hoffmann b0c3af
Gerd Hoffmann b0c3af
diff --git a/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c b/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c
Gerd Hoffmann b0c3af
index ed75a01..6507cc0 100644
Gerd Hoffmann b0c3af
--- a/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/QemuLegacy.c
Gerd Hoffmann b0c3af
@@ -631,6 +631,11 @@ InstallDefaultTables (
Gerd Hoffmann b0c3af
   EFI_STATUS Status;
Gerd Hoffmann b0c3af
 
Gerd Hoffmann b0c3af
   Status = InstallSmbiosType0 (Smbios, ProducerHandle, Context);
Gerd Hoffmann b0c3af
+  if (EFI_ERROR (Status)) {
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  Status = InstallSmbiosType1 (Smbios, ProducerHandle, Context);
Gerd Hoffmann b0c3af
   return Status;
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 ca776b5..4a2e824 100644
Gerd Hoffmann b0c3af
--- a/OvmfPkg/SmbiosPlatformDxe/QemuLegacyInternal.h
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/QemuLegacyInternal.h
Gerd Hoffmann b0c3af
@@ -248,4 +248,34 @@ InstallSmbiosType0 (
Gerd Hoffmann b0c3af
   IN OUT BUILD_CONTEXT       *Context
Gerd Hoffmann b0c3af
   );
Gerd Hoffmann b0c3af
 
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+/**
Gerd Hoffmann b0c3af
+  Install default (fallback) table for SMBIOS Type 1.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  In case QEMU has provided no Type 1 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 1 table has already been installed from the
Gerd Hoffmann b0c3af
+                       SMBIOS firmware configuration blob.
Gerd Hoffmann b0c3af
+  @retval EFI_SUCCESS  No Type 1 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
+InstallSmbiosType1 (
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/QemuType1.c b/OvmfPkg/SmbiosPlatformDxe/QemuType1.c
Gerd Hoffmann b0c3af
new file mode 100644
Gerd Hoffmann b0c3af
index 0000000..ff48164
Gerd Hoffmann b0c3af
--- /dev/null
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/QemuType1.c
Gerd Hoffmann b0c3af
@@ -0,0 +1,178 @@
Gerd Hoffmann b0c3af
+/** @file
Gerd Hoffmann b0c3af
+  Install the default Type 1 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 1 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_TYPE1_STRINGS                            \
Gerd Hoffmann b0c3af
+          "QEMU\0"                 /* Manufacturer */ \
Gerd Hoffmann b0c3af
+          "QEMU Virtual Machine\0" /* ProductName */  \
Gerd Hoffmann b0c3af
+          "n/a\0"                  /* Version */      \
Gerd Hoffmann b0c3af
+          "n/a\0"                  /* SerialNumber */ \
Gerd Hoffmann b0c3af
+          "n/a\0"                  /* SKUNumber */    \
Gerd Hoffmann b0c3af
+          "n/a\0"                  /* Family */
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+//
Gerd Hoffmann b0c3af
+// Type definition and contents of the default Type 1 SMBIOS table.
Gerd Hoffmann b0c3af
+//
Gerd Hoffmann b0c3af
+#pragma pack(1)
Gerd Hoffmann b0c3af
+OVMF_SMBIOS (1);
Gerd Hoffmann b0c3af
+#pragma pack()
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+STATIC CONST OVMF_TYPE1 mOvmfType1 = {
Gerd Hoffmann b0c3af
+  {
Gerd Hoffmann b0c3af
+    // SMBIOS_STRUCTURE Hdr
Gerd Hoffmann b0c3af
+    {
Gerd Hoffmann b0c3af
+      EFI_SMBIOS_TYPE_SYSTEM_INFORMATION, // UINT8 Type
Gerd Hoffmann b0c3af
+      sizeof (SMBIOS_TABLE_TYPE1)         // UINT8 Length
Gerd Hoffmann b0c3af
+    },
Gerd Hoffmann b0c3af
+    1,                           // SMBIOS_TABLE_STRING Manufacturer
Gerd Hoffmann b0c3af
+    2,                           // SMBIOS_TABLE_STRING ProductName
Gerd Hoffmann b0c3af
+    3,                           // SMBIOS_TABLE_STRING Version
Gerd Hoffmann b0c3af
+    4,                           // SMBIOS_TABLE_STRING SerialNumber
Gerd Hoffmann b0c3af
+    { 0 },                       // GUID                Uuid
Gerd Hoffmann b0c3af
+    SystemWakeupTypePowerSwitch, // UINT8               WakeUpType
Gerd Hoffmann b0c3af
+    5,                           // SMBIOS_TABLE_STRING SKUNumber
Gerd Hoffmann b0c3af
+    6,                           // SMBIOS_TABLE_STRING Family
Gerd Hoffmann b0c3af
+  },
Gerd Hoffmann b0c3af
+  OVMF_TYPE1_STRINGS
Gerd Hoffmann b0c3af
+};
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+/**
Gerd Hoffmann b0c3af
+  Install default (fallback) table for SMBIOS Type 1.
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  In case QEMU has provided no Type 1 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 1 table has already been installed from the
Gerd Hoffmann b0c3af
+                       SMBIOS firmware configuration blob.
Gerd Hoffmann b0c3af
+  @retval EFI_SUCCESS  No Type 1 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
+InstallSmbiosType1 (
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_TYPE1        OvmfType1;
Gerd Hoffmann b0c3af
+  EFI_STATUS        Status;
Gerd Hoffmann b0c3af
+  EFI_SMBIOS_HANDLE SmbiosHandle;
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  Table = &Context->Table[1];
Gerd Hoffmann b0c3af
+  if (Table->Installed) {
Gerd Hoffmann b0c3af
+    return EFI_SUCCESS;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  CopyMem (&OvmfType1, &mOvmfType1, sizeof OvmfType1);
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  QemuFwCfgSelectItem (QemuFwCfgItemSystemUuid);
Gerd Hoffmann b0c3af
+  OvmfType1.Base.Uuid.Data1 = SwapBytes32 (QemuFwCfgRead32 ());
Gerd Hoffmann b0c3af
+  OvmfType1.Base.Uuid.Data2 = SwapBytes16 (QemuFwCfgRead16 ());
Gerd Hoffmann b0c3af
+  OvmfType1.Base.Uuid.Data3 = SwapBytes16 (QemuFwCfgRead16 ());
Gerd Hoffmann b0c3af
+  QemuFwCfgReadBytes (sizeof OvmfType1.Base.Uuid.Data4,
Gerd Hoffmann b0c3af
+    &OvmfType1.Base.Uuid.Data4);
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, 1, &OvmfType1, Uuid);
Gerd Hoffmann b0c3af
+  switch (Status) {
Gerd Hoffmann b0c3af
+  case EFI_NOT_FOUND:
Gerd Hoffmann b0c3af
+    break;
Gerd Hoffmann b0c3af
+  case EFI_SUCCESS:
Gerd Hoffmann b0c3af
+    OvmfType1.Base.Uuid.Data1 = SwapBytes32 (OvmfType1.Base.Uuid.Data1);
Gerd Hoffmann b0c3af
+    OvmfType1.Base.Uuid.Data2 = SwapBytes16 (OvmfType1.Base.Uuid.Data2);
Gerd Hoffmann b0c3af
+    OvmfType1.Base.Uuid.Data3 = SwapBytes16 (OvmfType1.Base.Uuid.Data3);
Gerd Hoffmann b0c3af
+    break;
Gerd Hoffmann b0c3af
+  default:
Gerd Hoffmann b0c3af
+    return Status;
Gerd Hoffmann b0c3af
+  }
Gerd Hoffmann b0c3af
+
Gerd Hoffmann b0c3af
+  Status = PATCH_FORMATTED (Context, 1, &OvmfType1, WakeUpType);
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 *) &OvmfType1);
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, 1, &OvmfType1,
Gerd Hoffmann b0c3af
+             Manufacturer);
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, 1, &OvmfType1,
Gerd Hoffmann b0c3af
+             ProductName);
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, 1, &OvmfType1,
Gerd Hoffmann b0c3af
+             Version);
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, 1, &OvmfType1,
Gerd Hoffmann b0c3af
+             SerialNumber);
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, 1, &OvmfType1,
Gerd Hoffmann b0c3af
+             SKUNumber);
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, 1, &OvmfType1,
Gerd Hoffmann b0c3af
+             Family);
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 3483b9c..1f7dfca 100644
Gerd Hoffmann b0c3af
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
Gerd Hoffmann b0c3af
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
Gerd Hoffmann b0c3af
@@ -38,6 +38,7 @@
Gerd Hoffmann b0c3af
   X86Xen.c
Gerd Hoffmann b0c3af
   QemuLegacy.c
Gerd Hoffmann b0c3af
   QemuType0.c
Gerd Hoffmann b0c3af
+  QemuType1.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