]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.c
OvmfPkg/TlsAuthConfigLib: configure trusted cipher suites for HTTPS boot
[mirror_edk2.git] / OvmfPkg / Library / SmbiosVersionLib / DetectSmbiosVersionLib.c
CommitLineData
b265ed92
LE
1/** @file\r
2\r
3 A hook-in library for MdeModulePkg/Universal/SmbiosDxe, in order to set\r
4 gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion (and possibly other PCDs)\r
5 just before SmbiosDxe consumes them.\r
6\r
7 Copyright (C) 2013, 2015, Red Hat, Inc.\r
8 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
9\r
10 This program and the accompanying materials are licensed and made available\r
11 under the terms and conditions of the BSD License which accompanies this\r
12 distribution. The full text of the license may be found at\r
13 http://opensource.org/licenses/bsd-license.php\r
14\r
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
16 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
20#include <IndustryStandard/SmBios.h>\r
21\r
22#include <Base.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/DebugLib.h>\r
25#include <Library/PcdLib.h>\r
26#include <Library/QemuFwCfgLib.h>\r
27\r
28typedef union {\r
29 SMBIOS_TABLE_ENTRY_POINT V2;\r
c3db5a8c 30 SMBIOS_TABLE_3_0_ENTRY_POINT V3;\r
b265ed92
LE
31} QEMU_SMBIOS_ANCHOR;\r
32\r
33RETURN_STATUS\r
34EFIAPI\r
35DetectSmbiosVersion (\r
36 VOID\r
37 )\r
38{\r
39 FIRMWARE_CONFIG_ITEM Anchor, Tables;\r
40 UINTN AnchorSize, TablesSize;\r
41 QEMU_SMBIOS_ANCHOR QemuAnchor;\r
42 UINT16 SmbiosVersion;\r
ae23afb4 43 RETURN_STATUS PcdStatus;\r
b265ed92 44\r
92dc0bb2
LE
45 if (PcdGetBool (PcdQemuSmbiosValidated)) {\r
46 //\r
47 // Some other module, linked against this library, has already performed\r
48 // the task at hand. This should never happen, but it's easy to handle;\r
49 // just exit early.\r
50 //\r
51 return RETURN_SUCCESS;\r
52 }\r
53\r
b265ed92
LE
54 if (RETURN_ERROR (QemuFwCfgFindFile (\r
55 "etc/smbios/smbios-anchor", &Anchor, &AnchorSize)) ||\r
56 RETURN_ERROR (QemuFwCfgFindFile (\r
57 "etc/smbios/smbios-tables", &Tables, &TablesSize)) ||\r
58 TablesSize == 0) {\r
59 return RETURN_SUCCESS;\r
60 }\r
61\r
62 QemuFwCfgSelectItem (Anchor);\r
63\r
64 switch (AnchorSize) {\r
65 case sizeof QemuAnchor.V2:\r
66 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);\r
67\r
68 if (QemuAnchor.V2.MajorVersion != 2 ||\r
69 QemuAnchor.V2.TableLength != TablesSize ||\r
70 CompareMem (QemuAnchor.V2.AnchorString, "_SM_", 4) != 0 ||\r
71 CompareMem (QemuAnchor.V2.IntermediateAnchorString, "_DMI_", 5) != 0) {\r
72 return RETURN_SUCCESS;\r
73 }\r
74 SmbiosVersion = (UINT16)(QemuAnchor.V2.MajorVersion << 8 |\r
75 QemuAnchor.V2.MinorVersion);\r
76 break;\r
77\r
c3db5a8c
LE
78 case sizeof QemuAnchor.V3:\r
79 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);\r
80\r
81 if (QemuAnchor.V3.MajorVersion != 3 ||\r
82 QemuAnchor.V3.TableMaximumSize != TablesSize ||\r
83 CompareMem (QemuAnchor.V3.AnchorString, "_SM3_", 5) != 0) {\r
84 return RETURN_SUCCESS;\r
85 }\r
86 SmbiosVersion = (UINT16)(QemuAnchor.V3.MajorVersion << 8 |\r
87 QemuAnchor.V3.MinorVersion);\r
88\r
89 DEBUG ((EFI_D_INFO, "%a: SMBIOS 3.x DocRev from QEMU: 0x%02x\n",\r
90 __FUNCTION__, QemuAnchor.V3.DocRev));\r
ae23afb4
LE
91 PcdStatus = PcdSet8S (PcdSmbiosDocRev, QemuAnchor.V3.DocRev);\r
92 ASSERT_RETURN_ERROR (PcdStatus);\r
c3db5a8c
LE
93 break;\r
94\r
b265ed92
LE
95 default:\r
96 return RETURN_SUCCESS;\r
97 }\r
98\r
99 DEBUG ((EFI_D_INFO, "%a: SMBIOS version from QEMU: 0x%04x\n", __FUNCTION__,\r
100 SmbiosVersion));\r
ae23afb4
LE
101 PcdStatus = PcdSet16S (PcdSmbiosVersion, SmbiosVersion);\r
102 ASSERT_RETURN_ERROR (PcdStatus);\r
b265ed92 103\r
92dc0bb2
LE
104 //\r
105 // SMBIOS platform drivers can now fetch and install\r
106 // "etc/smbios/smbios-tables" from QEMU.\r
107 //\r
ae23afb4
LE
108 PcdStatus = PcdSetBoolS (PcdQemuSmbiosValidated, TRUE);\r
109 ASSERT_RETURN_ERROR (PcdStatus);\r
b265ed92
LE
110 return RETURN_SUCCESS;\r
111}\r