]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.c
OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones
[mirror_edk2.git] / OvmfPkg / Library / SmbiosVersionLib / DetectSmbiosVersionLib.c
1 /** @file
2
3 A hook-in library for MdeModulePkg/Universal/SmbiosDxe, in order to set
4 gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion (and possibly other PCDs)
5 just before SmbiosDxe consumes them.
6
7 Copyright (C) 2013, 2015, Red Hat, Inc.
8 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
9
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 #include <IndustryStandard/SmBios.h>
15
16 #include <Base.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/PcdLib.h>
20 #include <Library/QemuFwCfgLib.h>
21
22 typedef union {
23 SMBIOS_TABLE_ENTRY_POINT V2;
24 SMBIOS_TABLE_3_0_ENTRY_POINT V3;
25 } QEMU_SMBIOS_ANCHOR;
26
27 RETURN_STATUS
28 EFIAPI
29 DetectSmbiosVersion (
30 VOID
31 )
32 {
33 FIRMWARE_CONFIG_ITEM Anchor, Tables;
34 UINTN AnchorSize, TablesSize;
35 QEMU_SMBIOS_ANCHOR QemuAnchor;
36 UINT16 SmbiosVersion;
37 RETURN_STATUS PcdStatus;
38
39 if (PcdGetBool (PcdQemuSmbiosValidated)) {
40 //
41 // Some other module, linked against this library, has already performed
42 // the task at hand. This should never happen, but it's easy to handle;
43 // just exit early.
44 //
45 return RETURN_SUCCESS;
46 }
47
48 if (RETURN_ERROR (QemuFwCfgFindFile (
49 "etc/smbios/smbios-anchor", &Anchor, &AnchorSize)) ||
50 RETURN_ERROR (QemuFwCfgFindFile (
51 "etc/smbios/smbios-tables", &Tables, &TablesSize)) ||
52 TablesSize == 0) {
53 return RETURN_SUCCESS;
54 }
55
56 QemuFwCfgSelectItem (Anchor);
57
58 switch (AnchorSize) {
59 case sizeof QemuAnchor.V2:
60 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);
61
62 if (QemuAnchor.V2.MajorVersion != 2 ||
63 QemuAnchor.V2.TableLength != TablesSize ||
64 CompareMem (QemuAnchor.V2.AnchorString, "_SM_", 4) != 0 ||
65 CompareMem (QemuAnchor.V2.IntermediateAnchorString, "_DMI_", 5) != 0) {
66 return RETURN_SUCCESS;
67 }
68 SmbiosVersion = (UINT16)(QemuAnchor.V2.MajorVersion << 8 |
69 QemuAnchor.V2.MinorVersion);
70 break;
71
72 case sizeof QemuAnchor.V3:
73 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);
74
75 if (QemuAnchor.V3.MajorVersion != 3 ||
76 QemuAnchor.V3.TableMaximumSize != TablesSize ||
77 CompareMem (QemuAnchor.V3.AnchorString, "_SM3_", 5) != 0) {
78 return RETURN_SUCCESS;
79 }
80 SmbiosVersion = (UINT16)(QemuAnchor.V3.MajorVersion << 8 |
81 QemuAnchor.V3.MinorVersion);
82
83 DEBUG ((DEBUG_INFO, "%a: SMBIOS 3.x DocRev from QEMU: 0x%02x\n",
84 __FUNCTION__, QemuAnchor.V3.DocRev));
85 PcdStatus = PcdSet8S (PcdSmbiosDocRev, QemuAnchor.V3.DocRev);
86 ASSERT_RETURN_ERROR (PcdStatus);
87 break;
88
89 default:
90 return RETURN_SUCCESS;
91 }
92
93 DEBUG ((DEBUG_INFO, "%a: SMBIOS version from QEMU: 0x%04x\n", __FUNCTION__,
94 SmbiosVersion));
95 PcdStatus = PcdSet16S (PcdSmbiosVersion, SmbiosVersion);
96 ASSERT_RETURN_ERROR (PcdStatus);
97
98 //
99 // SMBIOS platform drivers can now fetch and install
100 // "etc/smbios/smbios-tables" from QEMU.
101 //
102 PcdStatus = PcdSetBoolS (PcdQemuSmbiosValidated, TRUE);
103 ASSERT_RETURN_ERROR (PcdStatus);
104 return RETURN_SUCCESS;
105 }