2 This driver installs SMBIOS information for OVMF
4 Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
5 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "SmbiosPlatformDxe.h"
21 Validates the SMBIOS entry point structure
23 @param EntryPointStructure SMBIOS entry point structure
25 @retval TRUE The entry point structure is valid
26 @retval FALSE The entry point structure is not valid
30 IsEntryPointStructureValid (
31 IN SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
39 BytePtr
= (UINT8
*) EntryPointStructure
;
40 Length
= EntryPointStructure
->EntryPointLength
;
43 for (Index
= 0; Index
< Length
; Index
++) {
44 Checksum
= Checksum
+ (UINT8
) BytePtr
[Index
];
56 Get SMBIOS record length.
58 @param SmbiosTable SMBIOS pointer.
63 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
69 AChar
= (CHAR8
*)(SmbiosTable
.Raw
+ SmbiosTable
.Hdr
->Length
);
72 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
74 while ((*AChar
!= 0) || (*(AChar
+ 1) != 0)) {
77 Length
= ((UINTN
)AChar
- (UINTN
)SmbiosTable
.Raw
+ 2);
84 Install all structures from the given SMBIOS structures block
86 @param Smbios SMBIOS protocol
87 @param TableAddress SMBIOS tables starting address
91 InstallAllStructures (
92 IN EFI_SMBIOS_PROTOCOL
*Smbios
,
93 IN UINT8
*TableAddress
97 SMBIOS_STRUCTURE_POINTER SmbiosTable
;
98 EFI_SMBIOS_HANDLE SmbiosHandle
;
100 SmbiosTable
.Raw
= TableAddress
;
101 if (SmbiosTable
.Raw
== NULL
) {
102 return EFI_INVALID_PARAMETER
;
105 while (SmbiosTable
.Hdr
->Type
!= 127) {
107 // Log the SMBIOS data for this structure
109 SmbiosHandle
= SmbiosTable
.Hdr
->Handle
;
110 Status
= Smbios
->Add (
114 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosTable
.Raw
116 ASSERT_EFI_ERROR (Status
);
119 // Get the next structure address
121 SmbiosTable
.Raw
= (UINT8
*)(SmbiosTable
.Raw
+ SmbiosTableLength (SmbiosTable
));
129 Installs SMBIOS information for OVMF
131 @param ImageHandle Module's image handle
132 @param SystemTable Pointer of EFI_SYSTEM_TABLE
134 @retval EFI_SUCCESS Smbios data successfully installed
135 @retval Other Smbios data was not installed
140 SmbiosTablePublishEntry (
141 IN EFI_HANDLE ImageHandle
,
142 IN EFI_SYSTEM_TABLE
*SystemTable
146 EFI_SMBIOS_PROTOCOL
*Smbios
;
147 SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
;
151 // Find the SMBIOS protocol
153 Status
= gBS
->LocateProtocol (
154 &gEfiSmbiosProtocolGuid
,
158 if (EFI_ERROR (Status
)) {
163 // Add Xen or QEMU SMBIOS data if found
165 EntryPointStructure
= GetXenSmbiosTables ();
166 if (EntryPointStructure
!= NULL
) {
167 SmbiosTables
= (UINT8
*)(UINTN
)EntryPointStructure
->TableAddress
;
169 SmbiosTables
= GetQemuSmbiosTables ();
172 if (SmbiosTables
!= NULL
) {
173 Status
= InstallAllStructures (Smbios
, SmbiosTables
);
176 // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):
178 if (EntryPointStructure
== NULL
) {
179 FreePool (SmbiosTables
);