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