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.
7 Copyright (C) 2013, 2015, Red Hat, Inc.
8 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <IndustryStandard/SmBios.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/PcdLib.h>
20 #include <Library/QemuFwCfgLib.h>
23 SMBIOS_TABLE_ENTRY_POINT V2
;
24 SMBIOS_TABLE_3_0_ENTRY_POINT V3
;
33 FIRMWARE_CONFIG_ITEM Anchor
, Tables
;
34 UINTN AnchorSize
, TablesSize
;
35 QEMU_SMBIOS_ANCHOR QemuAnchor
;
37 RETURN_STATUS PcdStatus
;
39 if (PcdGetBool (PcdQemuSmbiosValidated
)) {
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;
45 return RETURN_SUCCESS
;
48 if (RETURN_ERROR (QemuFwCfgFindFile (
49 "etc/smbios/smbios-anchor", &Anchor
, &AnchorSize
)) ||
50 RETURN_ERROR (QemuFwCfgFindFile (
51 "etc/smbios/smbios-tables", &Tables
, &TablesSize
)) ||
53 return RETURN_SUCCESS
;
56 QemuFwCfgSelectItem (Anchor
);
59 case sizeof QemuAnchor
.V2
:
60 QemuFwCfgReadBytes (AnchorSize
, &QemuAnchor
);
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
;
68 SmbiosVersion
= (UINT16
)(QemuAnchor
.V2
.MajorVersion
<< 8 |
69 QemuAnchor
.V2
.MinorVersion
);
72 case sizeof QemuAnchor
.V3
:
73 QemuFwCfgReadBytes (AnchorSize
, &QemuAnchor
);
75 if (QemuAnchor
.V3
.MajorVersion
!= 3 ||
76 QemuAnchor
.V3
.TableMaximumSize
!= TablesSize
||
77 CompareMem (QemuAnchor
.V3
.AnchorString
, "_SM3_", 5) != 0) {
78 return RETURN_SUCCESS
;
80 SmbiosVersion
= (UINT16
)(QemuAnchor
.V3
.MajorVersion
<< 8 |
81 QemuAnchor
.V3
.MinorVersion
);
83 DEBUG ((EFI_D_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
);
90 return RETURN_SUCCESS
;
93 DEBUG ((EFI_D_INFO
, "%a: SMBIOS version from QEMU: 0x%04x\n", __FUNCTION__
,
95 PcdStatus
= PcdSet16S (PcdSmbiosVersion
, SmbiosVersion
);
96 ASSERT_RETURN_ERROR (PcdStatus
);
99 // SMBIOS platform drivers can now fetch and install
100 // "etc/smbios/smbios-tables" from QEMU.
102 PcdStatus
= PcdSetBoolS (PcdQemuSmbiosValidated
, TRUE
);
103 ASSERT_RETURN_ERROR (PcdStatus
);
104 return RETURN_SUCCESS
;