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 | RETURN_STATUS PcdStatus;
|
---|
44 |
|
---|
45 | if (PcdGetBool (PcdQemuSmbiosValidated)) {
|
---|
46 | //
|
---|
47 | // Some other module, linked against this library, has already performed
|
---|
48 | // the task at hand. This should never happen, but it's easy to handle;
|
---|
49 | // just exit early.
|
---|
50 | //
|
---|
51 | return RETURN_SUCCESS;
|
---|
52 | }
|
---|
53 |
|
---|
54 | if (RETURN_ERROR (QemuFwCfgFindFile (
|
---|
55 | "etc/smbios/smbios-anchor", &Anchor, &AnchorSize)) ||
|
---|
56 | RETURN_ERROR (QemuFwCfgFindFile (
|
---|
57 | "etc/smbios/smbios-tables", &Tables, &TablesSize)) ||
|
---|
58 | TablesSize == 0) {
|
---|
59 | return RETURN_SUCCESS;
|
---|
60 | }
|
---|
61 |
|
---|
62 | QemuFwCfgSelectItem (Anchor);
|
---|
63 |
|
---|
64 | switch (AnchorSize) {
|
---|
65 | case sizeof QemuAnchor.V2:
|
---|
66 | QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);
|
---|
67 |
|
---|
68 | if (QemuAnchor.V2.MajorVersion != 2 ||
|
---|
69 | QemuAnchor.V2.TableLength != TablesSize ||
|
---|
70 | CompareMem (QemuAnchor.V2.AnchorString, "_SM_", 4) != 0 ||
|
---|
71 | CompareMem (QemuAnchor.V2.IntermediateAnchorString, "_DMI_", 5) != 0) {
|
---|
72 | return RETURN_SUCCESS;
|
---|
73 | }
|
---|
74 | SmbiosVersion = (UINT16)(QemuAnchor.V2.MajorVersion << 8 |
|
---|
75 | QemuAnchor.V2.MinorVersion);
|
---|
76 | break;
|
---|
77 |
|
---|
78 | case sizeof QemuAnchor.V3:
|
---|
79 | QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);
|
---|
80 |
|
---|
81 | if (QemuAnchor.V3.MajorVersion != 3 ||
|
---|
82 | QemuAnchor.V3.TableMaximumSize != TablesSize ||
|
---|
83 | CompareMem (QemuAnchor.V3.AnchorString, "_SM3_", 5) != 0) {
|
---|
84 | return RETURN_SUCCESS;
|
---|
85 | }
|
---|
86 | SmbiosVersion = (UINT16)(QemuAnchor.V3.MajorVersion << 8 |
|
---|
87 | QemuAnchor.V3.MinorVersion);
|
---|
88 |
|
---|
89 | DEBUG ((EFI_D_INFO, "%a: SMBIOS 3.x DocRev from QEMU: 0x%02x\n",
|
---|
90 | __FUNCTION__, QemuAnchor.V3.DocRev));
|
---|
91 | PcdStatus = PcdSet8S (PcdSmbiosDocRev, QemuAnchor.V3.DocRev);
|
---|
92 | ASSERT_RETURN_ERROR (PcdStatus);
|
---|
93 | break;
|
---|
94 |
|
---|
95 | default:
|
---|
96 | return RETURN_SUCCESS;
|
---|
97 | }
|
---|
98 |
|
---|
99 | DEBUG ((EFI_D_INFO, "%a: SMBIOS version from QEMU: 0x%04x\n", __FUNCTION__,
|
---|
100 | SmbiosVersion));
|
---|
101 | PcdStatus = PcdSet16S (PcdSmbiosVersion, SmbiosVersion);
|
---|
102 | ASSERT_RETURN_ERROR (PcdStatus);
|
---|
103 |
|
---|
104 | //
|
---|
105 | // SMBIOS platform drivers can now fetch and install
|
---|
106 | // "etc/smbios/smbios-tables" from QEMU.
|
---|
107 | //
|
---|
108 | PcdStatus = PcdSetBoolS (PcdQemuSmbiosValidated, TRUE);
|
---|
109 | ASSERT_RETURN_ERROR (PcdStatus);
|
---|
110 | return RETURN_SUCCESS;
|
---|
111 | }
|
---|