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 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <IndustryStandard/SmBios.h> // SMBIOS_TABLE_TYPE0
12 #include <Library/DebugLib.h> // ASSERT_EFI_ERROR()
13 #include <Library/MemoryAllocationLib.h> // FreePool()
14 #include <Library/UefiBootServicesTableLib.h> // gBS
15 #include <Protocol/Smbios.h> // EFI_SMBIOS_PROTOCOL
17 #include "SmbiosPlatformDxe.h"
18 #include "XenSmbiosPlatformDxe.h"
20 #define TYPE0_STRINGS \
21 "EFI Development Kit II / OVMF\0" /* Vendor */ \
22 "0.0.0\0" /* BiosVersion */ \
23 "02/06/2015\0" /* BiosReleaseDate */
25 // Type definition and contents of the default Type 0 SMBIOS table.
29 SMBIOS_TABLE_TYPE0 Base
;
30 UINT8 Strings
[sizeof(TYPE0_STRINGS
)];
34 STATIC CONST OVMF_TYPE0 mOvmfDefaultType0
= {
36 // SMBIOS_STRUCTURE Hdr
38 EFI_SMBIOS_TYPE_BIOS_INFORMATION
, // UINT8 Type
39 sizeof (SMBIOS_TABLE_TYPE0
), // UINT8 Length
41 1, // SMBIOS_TABLE_STRING Vendor
42 2, // SMBIOS_TABLE_STRING BiosVersion
43 0xE800,// UINT16 BiosSegment
44 3, // SMBIOS_TABLE_STRING BiosReleaseDate
46 { // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
49 1, // BiosCharacteristicsNotSupported :1
50 // Remaining BiosCharacteristics bits left unset :60
52 { // BIOSCharacteristicsExtensionBytes[2]
54 0x1C // SystemReserved = VirtualMachineSupported |
55 // UefiSpecificationSupported |
56 // TargetContentDistributionEnabled
58 0, // UINT8 SystemBiosMajorRelease
59 0, // UINT8 SystemBiosMinorRelease
60 0xFF, // UINT8 EmbeddedControllerFirmwareMajorRelease
61 0xFF // UINT8 EmbeddedControllerFirmwareMinorRelease
63 // Text strings (unformatted area)
69 Get SMBIOS record length.
71 @param SmbiosTable SMBIOS pointer.
76 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
82 AChar
= (CHAR8
*)(SmbiosTable
.Raw
+ SmbiosTable
.Hdr
->Length
);
85 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
87 while ((*AChar
!= 0) || (*(AChar
+ 1) != 0)) {
90 Length
= ((UINTN
)AChar
- (UINTN
)SmbiosTable
.Raw
+ 2);
97 Install all structures from the given SMBIOS structures block
99 @param TableAddress SMBIOS tables starting address
103 InstallAllStructures (
104 IN UINT8
*TableAddress
107 EFI_SMBIOS_PROTOCOL
*Smbios
;
109 SMBIOS_STRUCTURE_POINTER SmbiosTable
;
110 EFI_SMBIOS_HANDLE SmbiosHandle
;
111 BOOLEAN NeedSmbiosType0
;
114 // Find the SMBIOS protocol
116 Status
= gBS
->LocateProtocol (
117 &gEfiSmbiosProtocolGuid
,
121 if (EFI_ERROR (Status
)) {
125 SmbiosTable
.Raw
= TableAddress
;
126 if (SmbiosTable
.Raw
== NULL
) {
127 return EFI_INVALID_PARAMETER
;
130 NeedSmbiosType0
= TRUE
;
132 while (SmbiosTable
.Hdr
->Type
!= 127) {
134 // Log the SMBIOS data for this structure
136 SmbiosHandle
= SmbiosTable
.Hdr
->Handle
;
137 Status
= Smbios
->Add (
141 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosTable
.Raw
143 ASSERT_EFI_ERROR (Status
);
145 if (SmbiosTable
.Hdr
->Type
== 0) {
146 NeedSmbiosType0
= FALSE
;
150 // Get the next structure address
152 SmbiosTable
.Raw
= (UINT8
*)(SmbiosTable
.Raw
+ SmbiosTableLength (SmbiosTable
));
155 if (NeedSmbiosType0
) {
157 // Add OVMF default Type 0 (BIOS Information) table
159 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
160 Status
= Smbios
->Add (
164 (EFI_SMBIOS_TABLE_HEADER
*) &mOvmfDefaultType0
166 ASSERT_EFI_ERROR (Status
);
174 Installs SMBIOS information for OVMF
176 @param ImageHandle Module's image handle
177 @param SystemTable Pointer of EFI_SYSTEM_TABLE
179 @retval EFI_SUCCESS Smbios data successfully installed
180 @retval Other Smbios data was not installed
185 SmbiosTablePublishEntry (
186 IN EFI_HANDLE ImageHandle
,
187 IN EFI_SYSTEM_TABLE
*SystemTable
191 SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
;
194 Status
= EFI_NOT_FOUND
;
196 // Add Xen or QEMU SMBIOS data if found
198 EntryPointStructure
= GetXenSmbiosTables ();
199 if (EntryPointStructure
!= NULL
) {
200 SmbiosTables
= (UINT8
*)(UINTN
)EntryPointStructure
->TableAddress
;
202 SmbiosTables
= GetQemuSmbiosTables ();
205 if (SmbiosTables
!= NULL
) {
206 Status
= InstallAllStructures (SmbiosTables
);
209 // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):
211 if (EntryPointStructure
== NULL
) {
212 FreePool (SmbiosTables
);