summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/SmbiosPlatformDxe/Qemu.c
blob: 4dae4b0b98f1d37cc3c51da79fa337b325f0b7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/** @file
  Find and extract QEMU SMBIOS data from fw_cfg.

  Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>

  SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Library/DebugLib.h>            // ASSERT_EFI_ERROR()
#include <Library/MemoryAllocationLib.h> // AllocatePool()
#include <Library/PcdLib.h>              // PcdGetBool()
#include <Library/QemuFwCfgLib.h>        // QemuFwCfgFindFile()

#include "SmbiosPlatformDxe.h"

/**
  Locates and extracts the QEMU SMBIOS data if present in fw_cfg

  @return                 Address of extracted QEMU SMBIOS data

**/
UINT8 *
GetQemuSmbiosTables (
  VOID
  )
{
  EFI_STATUS            Status;
  FIRMWARE_CONFIG_ITEM  Tables;
  UINTN                 TablesSize;
  UINT8                 *QemuTables;

  if (!PcdGetBool (PcdQemuSmbiosValidated)) {
    return NULL;
  }

  Status = QemuFwCfgFindFile (
             "etc/smbios/smbios-tables",
             &Tables,
             &TablesSize
             );
  ASSERT_EFI_ERROR (Status);
  ASSERT (TablesSize > 0);

  QemuTables = AllocatePool (TablesSize);
  if (QemuTables == NULL) {
    return NULL;
  }

  QemuFwCfgSelectItem (Tables);
  QemuFwCfgReadBytes (TablesSize, QemuTables);

  return QemuTables;
}

/**
  Installs SMBIOS information for OVMF

  @param ImageHandle     Module's image handle
  @param SystemTable     Pointer of EFI_SYSTEM_TABLE

  @retval EFI_SUCCESS    Smbios data successfully installed
  @retval Other          Smbios data was not installed

**/
EFI_STATUS
EFIAPI
SmbiosTablePublishEntry (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS  Status;
  UINT8       *SmbiosTables;

  Status = EFI_NOT_FOUND;
  //
  // Add QEMU SMBIOS data if found
  //
  SmbiosTables = GetQemuSmbiosTables ();
  if (SmbiosTables != NULL) {
    Status = InstallAllStructures (SmbiosTables);
    FreePool (SmbiosTables);
  }

  return Status;
}