]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/SmbiosVersionLib/DetectSmbiosVersionLib.c
OvmfPkg: SmbiosPlatformDxe: eliminate duplicate entry point validation
[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
30} QEMU_SMBIOS_ANCHOR;\r
31\r
32RETURN_STATUS\r
33EFIAPI\r
34DetectSmbiosVersion (\r
35 VOID\r
36 )\r
37{\r
38 FIRMWARE_CONFIG_ITEM Anchor, Tables;\r
39 UINTN AnchorSize, TablesSize;\r
40 QEMU_SMBIOS_ANCHOR QemuAnchor;\r
41 UINT16 SmbiosVersion;\r
42\r
92dc0bb2
LE
43 if (PcdGetBool (PcdQemuSmbiosValidated)) {\r
44 //\r
45 // Some other module, linked against this library, has already performed\r
46 // the task at hand. This should never happen, but it's easy to handle;\r
47 // just exit early.\r
48 //\r
49 return RETURN_SUCCESS;\r
50 }\r
51\r
b265ed92
LE
52 if (RETURN_ERROR (QemuFwCfgFindFile (\r
53 "etc/smbios/smbios-anchor", &Anchor, &AnchorSize)) ||\r
54 RETURN_ERROR (QemuFwCfgFindFile (\r
55 "etc/smbios/smbios-tables", &Tables, &TablesSize)) ||\r
56 TablesSize == 0) {\r
57 return RETURN_SUCCESS;\r
58 }\r
59\r
60 QemuFwCfgSelectItem (Anchor);\r
61\r
62 switch (AnchorSize) {\r
63 case sizeof QemuAnchor.V2:\r
64 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);\r
65\r
66 if (QemuAnchor.V2.MajorVersion != 2 ||\r
67 QemuAnchor.V2.TableLength != TablesSize ||\r
68 CompareMem (QemuAnchor.V2.AnchorString, "_SM_", 4) != 0 ||\r
69 CompareMem (QemuAnchor.V2.IntermediateAnchorString, "_DMI_", 5) != 0) {\r
70 return RETURN_SUCCESS;\r
71 }\r
72 SmbiosVersion = (UINT16)(QemuAnchor.V2.MajorVersion << 8 |\r
73 QemuAnchor.V2.MinorVersion);\r
74 break;\r
75\r
76 default:\r
77 return RETURN_SUCCESS;\r
78 }\r
79\r
80 DEBUG ((EFI_D_INFO, "%a: SMBIOS version from QEMU: 0x%04x\n", __FUNCTION__,\r
81 SmbiosVersion));\r
82 PcdSet16 (PcdSmbiosVersion, SmbiosVersion);\r
83\r
92dc0bb2
LE
84 //\r
85 // SMBIOS platform drivers can now fetch and install\r
86 // "etc/smbios/smbios-tables" from QEMU.\r
87 //\r
88 PcdSetBool (PcdQemuSmbiosValidated, TRUE);\r
b265ed92
LE
89 return RETURN_SUCCESS;\r
90}\r