]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SmbiosPlatformDxe/Qemu.c
CorebootPayloadPkg: Use extra braces to prevent gcc compile fail
[mirror_edk2.git] / OvmfPkg / SmbiosPlatformDxe / Qemu.c
1 /** @file
2 Find and extract QEMU SMBIOS data from fw_cfg.
3
4 Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
5
6 This program and the accompanying materials are licensed and made
7 available under the terms and conditions of the BSD License which
8 accompanies this distribution. The full text of the license may
9 be found at http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 **/
14
15 #include "SmbiosPlatformDxe.h"
16 #include <Library/QemuFwCfgLib.h>
17 #include <Library/MemoryAllocationLib.h>
18
19 /**
20 Locates and extracts the QEMU SMBIOS data if present in fw_cfg
21
22 @return Address of extracted QEMU SMBIOS data
23
24 **/
25 UINT8 *
26 GetQemuSmbiosTables (
27 VOID
28 )
29 {
30 SMBIOS_TABLE_ENTRY_POINT QemuAnchor;
31 FIRMWARE_CONFIG_ITEM Anchor, Tables;
32 UINTN AnchorSize, TablesSize;
33 UINT8 *QemuTables;
34
35 if (EFI_ERROR (QemuFwCfgFindFile (
36 "etc/smbios/smbios-anchor", &Anchor, &AnchorSize)) ||
37 EFI_ERROR (QemuFwCfgFindFile (
38 "etc/smbios/smbios-tables", &Tables, &TablesSize)) ||
39 AnchorSize != sizeof (QemuAnchor) ||
40 TablesSize == 0) {
41 return NULL;
42 }
43
44 //
45 // We copy the entry point structure to perform some additional checks,
46 // but discard it upon return.
47 //
48 QemuFwCfgSelectItem (Anchor);
49 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);
50
51 if (AsciiStrnCmp ((CHAR8 *)QemuAnchor.AnchorString, "_SM_", 4) ||
52 AsciiStrnCmp ((CHAR8 *)QemuAnchor.IntermediateAnchorString, "_DMI_", 5) ||
53 TablesSize != QemuAnchor.TableLength) {
54 return NULL;
55 }
56
57 QemuTables = AllocatePool (TablesSize);
58 if (QemuTables == NULL) {
59 return NULL;
60 }
61
62 QemuFwCfgSelectItem (Tables);
63 QemuFwCfgReadBytes (TablesSize, QemuTables);
64
65 return QemuTables;
66 }