TianoCore EDK2 master
Loading...
Searching...
No Matches
DetectSmbiosVersionLib.c
Go to the documentation of this file.
1
15
16#include <Base.h>
18#include <Library/DebugLib.h>
19#include <Library/PcdLib.h>
21
22typedef union {
26
27RETURN_STATUS
28EFIAPI
29DetectSmbiosVersion (
30 VOID
31 )
32{
33 FIRMWARE_CONFIG_ITEM Anchor, Tables;
34 UINTN AnchorSize, TablesSize;
35 QEMU_SMBIOS_ANCHOR QemuAnchor;
36 UINT16 SmbiosVersion;
37 RETURN_STATUS PcdStatus;
38
39 if (PcdGetBool (PcdQemuSmbiosValidated)) {
40 //
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;
43 // just exit early.
44 //
45 return RETURN_SUCCESS;
46 }
47
48 if (RETURN_ERROR (
50 "etc/smbios/smbios-anchor",
51 &Anchor,
52 &AnchorSize
53 )
54 ) ||
57 "etc/smbios/smbios-tables",
58 &Tables,
59 &TablesSize
60 )
61 ) ||
62 (TablesSize == 0))
63 {
64 return RETURN_SUCCESS;
65 }
66
67 QemuFwCfgSelectItem (Anchor);
68
69 switch (AnchorSize) {
70 case sizeof QemuAnchor.V2:
71 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);
72
73 if ((QemuAnchor.V2.MajorVersion != 2) ||
74 (QemuAnchor.V2.TableLength != TablesSize) ||
75 (CompareMem (QemuAnchor.V2.AnchorString, "_SM_", 4) != 0) ||
76 (CompareMem (QemuAnchor.V2.IntermediateAnchorString, "_DMI_", 5) != 0))
77 {
78 return RETURN_SUCCESS;
79 }
80
81 SmbiosVersion = (UINT16)(QemuAnchor.V2.MajorVersion << 8 |
82 QemuAnchor.V2.MinorVersion);
83 break;
84
85 case sizeof QemuAnchor.V3:
86 QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);
87
88 if ((QemuAnchor.V3.MajorVersion != 3) ||
89 (QemuAnchor.V3.TableMaximumSize != TablesSize) ||
90 (CompareMem (QemuAnchor.V3.AnchorString, "_SM3_", 5) != 0))
91 {
92 return RETURN_SUCCESS;
93 }
94
95 SmbiosVersion = (UINT16)(QemuAnchor.V3.MajorVersion << 8 |
96 QemuAnchor.V3.MinorVersion);
97
98 DEBUG ((
99 DEBUG_INFO,
100 "%a: SMBIOS 3.x DocRev from QEMU: 0x%02x\n",
101 __func__,
102 QemuAnchor.V3.DocRev
103 ));
104 PcdStatus = PcdSet8S (PcdSmbiosDocRev, QemuAnchor.V3.DocRev);
105 ASSERT_RETURN_ERROR (PcdStatus);
106 break;
107
108 default:
109 return RETURN_SUCCESS;
110 }
111
112 DEBUG ((
113 DEBUG_INFO,
114 "%a: SMBIOS version from QEMU: 0x%04x\n",
115 __func__,
116 SmbiosVersion
117 ));
118 PcdStatus = PcdSet16S (PcdSmbiosVersion, SmbiosVersion);
119 ASSERT_RETURN_ERROR (PcdStatus);
120
121 //
122 // SMBIOS platform drivers can now fetch and install
123 // "etc/smbios/smbios-tables" from QEMU.
124 //
125 PcdStatus = PcdSetBoolS (PcdQemuSmbiosValidated, TRUE);
126 ASSERT_RETURN_ERROR (PcdStatus);
127 return RETURN_SUCCESS;
128}
UINT64 UINTN
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define RETURN_SUCCESS
Definition: Base.h:1066
#define TRUE
Definition: Base.h:301
#define ASSERT_RETURN_ERROR(StatusParameter)
Definition: DebugLib.h:493
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdSetBoolS(TokenName, Value)
Definition: PcdLib.h:549
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
#define PcdSet8S(TokenName, Value)
Definition: PcdLib.h:469
#define PcdSet16S(TokenName, Value)
Definition: PcdLib.h:483
RETURN_STATUS EFIAPI QemuFwCfgFindFile(IN CONST CHAR8 *Name, OUT FIRMWARE_CONFIG_ITEM *Item, OUT UINTN *Size)
Definition: QemuFwCfgLib.c:250
VOID EFIAPI QemuFwCfgReadBytes(IN UINTN Size, IN VOID *Buffer OPTIONAL)
Definition: QemuFwCfgNull.c:66
VOID EFIAPI QemuFwCfgSelectItem(IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem)
Definition: QemuFwCfgLib.c:33