2 This driver installs SMBIOS information for OVMF
4 Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
5 Copyright (c) 2011 - 2015, 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"
19 #define TYPE0_STRINGS \
20 "EFI Development Kit II / OVMF\0" /* Vendor */ \
21 "0.0.0\0" /* BiosVersion */ \
22 "02/06/2015\0" /* BiosReleaseDate */
24 // Type definition and contents of the default Type 0 SMBIOS table.
28 SMBIOS_TABLE_TYPE0 Base
;
29 UINT8 Strings
[sizeof(TYPE0_STRINGS
)];
33 STATIC CONST OVMF_TYPE0 mOvmfDefaultType0
= {
35 // SMBIOS_STRUCTURE Hdr
37 EFI_SMBIOS_TYPE_BIOS_INFORMATION
, // UINT8 Type
38 sizeof (SMBIOS_TABLE_TYPE0
), // UINT8 Length
40 1, // SMBIOS_TABLE_STRING Vendor
41 2, // SMBIOS_TABLE_STRING BiosVersion
42 0xE800,// UINT16 BiosSegment
43 3, // SMBIOS_TABLE_STRING BiosReleaseDate
45 { // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
48 1, // BiosCharacteristicsNotSupported :1
49 // Remaining BiosCharacteristics bits left unset :60
51 { // BIOSCharacteristicsExtensionBytes[2]
53 0x1C // SystemReserved = VirtualMachineSupported |
54 // UefiSpecificationSupported |
55 // TargetContentDistributionEnabled
57 0, // UINT8 SystemBiosMajorRelease
58 0, // UINT8 SystemBiosMinorRelease
59 0xFF, // UINT8 EmbeddedControllerFirmwareMajorRelease
60 0xFF // UINT8 EmbeddedControllerFirmwareMinorRelease
62 // Text strings (unformatted area)
68 Validates the SMBIOS entry point structure
70 @param EntryPointStructure SMBIOS entry point structure
72 @retval TRUE The entry point structure is valid
73 @retval FALSE The entry point structure is not valid
77 IsEntryPointStructureValid (
78 IN SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
86 BytePtr
= (UINT8
*) EntryPointStructure
;
87 Length
= EntryPointStructure
->EntryPointLength
;
90 for (Index
= 0; Index
< Length
; Index
++) {
91 Checksum
= Checksum
+ (UINT8
) BytePtr
[Index
];
103 Get SMBIOS record length.
105 @param SmbiosTable SMBIOS pointer.
110 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
116 AChar
= (CHAR8
*)(SmbiosTable
.Raw
+ SmbiosTable
.Hdr
->Length
);
119 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
121 while ((*AChar
!= 0) || (*(AChar
+ 1) != 0)) {
124 Length
= ((UINTN
)AChar
- (UINTN
)SmbiosTable
.Raw
+ 2);
131 Install all structures from the given SMBIOS structures block
133 @param Smbios SMBIOS protocol
134 @param TableAddress SMBIOS tables starting address
138 InstallAllStructures (
139 IN EFI_SMBIOS_PROTOCOL
*Smbios
,
140 IN UINT8
*TableAddress
144 SMBIOS_STRUCTURE_POINTER SmbiosTable
;
145 EFI_SMBIOS_HANDLE SmbiosHandle
;
146 BOOLEAN NeedSmbiosType0
;
148 SmbiosTable
.Raw
= TableAddress
;
149 if (SmbiosTable
.Raw
== NULL
) {
150 return EFI_INVALID_PARAMETER
;
153 NeedSmbiosType0
= TRUE
;
155 while (SmbiosTable
.Hdr
->Type
!= 127) {
157 // Log the SMBIOS data for this structure
159 SmbiosHandle
= SmbiosTable
.Hdr
->Handle
;
160 Status
= Smbios
->Add (
164 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosTable
.Raw
166 ASSERT_EFI_ERROR (Status
);
168 if (SmbiosTable
.Hdr
->Type
== 0) {
169 NeedSmbiosType0
= FALSE
;
173 // Get the next structure address
175 SmbiosTable
.Raw
= (UINT8
*)(SmbiosTable
.Raw
+ SmbiosTableLength (SmbiosTable
));
178 if (NeedSmbiosType0
) {
180 // Add OVMF default Type 0 (BIOS Information) table
182 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
183 Status
= Smbios
->Add (
187 (EFI_SMBIOS_TABLE_HEADER
*) &mOvmfDefaultType0
189 ASSERT_EFI_ERROR (Status
);
197 Installs SMBIOS information for OVMF
199 @param ImageHandle Module's image handle
200 @param SystemTable Pointer of EFI_SYSTEM_TABLE
202 @retval EFI_SUCCESS Smbios data successfully installed
203 @retval Other Smbios data was not installed
208 SmbiosTablePublishEntry (
209 IN EFI_HANDLE ImageHandle
,
210 IN EFI_SYSTEM_TABLE
*SystemTable
214 EFI_SMBIOS_PROTOCOL
*Smbios
;
215 SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
;
219 // Find the SMBIOS protocol
221 Status
= gBS
->LocateProtocol (
222 &gEfiSmbiosProtocolGuid
,
226 if (EFI_ERROR (Status
)) {
231 // Add Xen or QEMU SMBIOS data if found
233 EntryPointStructure
= GetXenSmbiosTables ();
234 if (EntryPointStructure
!= NULL
) {
235 SmbiosTables
= (UINT8
*)(UINTN
)EntryPointStructure
->TableAddress
;
237 SmbiosTables
= GetQemuSmbiosTables ();
240 if (SmbiosTables
!= NULL
) {
241 Status
= InstallAllStructures (Smbios
, SmbiosTables
);
244 // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):
246 if (EntryPointStructure
== NULL
) {
247 FreePool (SmbiosTables
);