2 This driver installs SMBIOS information for OVMF
4 Copyright (c) 2020, Rebecca Cran <rebecca@bsdio.com>
5 Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
6 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "SmbiosPlatformDxe.h"
14 #define TYPE0_STRINGS \
15 "EFI Development Kit II / OVMF\0" /* Vendor */ \
16 "0.0.0\0" /* BiosVersion */ \
17 "02/06/2015\0" /* BiosReleaseDate */
19 // Type definition and contents of the default Type 0 SMBIOS table.
23 SMBIOS_TABLE_TYPE0 Base
;
24 UINT8 Strings
[sizeof (TYPE0_STRINGS
)];
28 STATIC CONST OVMF_TYPE0 mOvmfDefaultType0
= {
30 // SMBIOS_STRUCTURE Hdr
32 EFI_SMBIOS_TYPE_BIOS_INFORMATION
, // UINT8 Type
33 sizeof (SMBIOS_TABLE_TYPE0
), // UINT8 Length
35 1, // SMBIOS_TABLE_STRING Vendor
36 2, // SMBIOS_TABLE_STRING BiosVersion
37 0xE800, // UINT16 BiosSegment
38 3, // SMBIOS_TABLE_STRING BiosReleaseDate
40 { // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
43 1, // BiosCharacteristicsNotSupported :1
44 // Remaining BiosCharacteristics bits left unset :60
46 { // BIOSCharacteristicsExtensionBytes[2]
48 0x1C // SystemReserved = VirtualMachineSupported |
49 // UefiSpecificationSupported |
50 // TargetContentDistributionEnabled
52 0, // UINT8 SystemBiosMajorRelease
53 0, // UINT8 SystemBiosMinorRelease
54 0xFF, // UINT8 EmbeddedControllerFirmwareMajorRelease
55 0xFF // UINT8 EmbeddedControllerFirmwareMinorRelease
57 // Text strings (unformatted area)
62 Validates the SMBIOS entry point structure
64 @param EntryPointStructure SMBIOS entry point structure
66 @retval TRUE The entry point structure is valid
67 @retval FALSE The entry point structure is not valid
71 IsEntryPointStructureValid (
72 IN SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
80 BytePtr
= (UINT8
*)EntryPointStructure
;
81 Length
= EntryPointStructure
->EntryPointLength
;
84 for (Index
= 0; Index
< Length
; Index
++) {
85 Checksum
= Checksum
+ (UINT8
)BytePtr
[Index
];
96 Get SMBIOS record length.
98 @param SmbiosTable SMBIOS pointer.
103 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
109 AChar
= (CHAR8
*)(SmbiosTable
.Raw
+ SmbiosTable
.Hdr
->Length
);
112 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
114 while ((*AChar
!= 0) || (*(AChar
+ 1) != 0)) {
118 Length
= ((UINTN
)AChar
- (UINTN
)SmbiosTable
.Raw
+ 2);
124 Install all structures from the given SMBIOS structures block
126 @param Smbios SMBIOS protocol
127 @param TableAddress SMBIOS tables starting address
131 InstallAllStructures (
132 IN EFI_SMBIOS_PROTOCOL
*Smbios
,
133 IN UINT8
*TableAddress
137 SMBIOS_STRUCTURE_POINTER SmbiosTable
;
138 EFI_SMBIOS_HANDLE SmbiosHandle
;
139 BOOLEAN NeedSmbiosType0
;
141 SmbiosTable
.Raw
= TableAddress
;
142 if (SmbiosTable
.Raw
== NULL
) {
143 return EFI_INVALID_PARAMETER
;
146 NeedSmbiosType0
= TRUE
;
148 while (SmbiosTable
.Hdr
->Type
!= 127) {
150 // Log the SMBIOS data for this structure
152 SmbiosHandle
= SmbiosTable
.Hdr
->Handle
;
153 Status
= Smbios
->Add (
157 (EFI_SMBIOS_TABLE_HEADER
*)SmbiosTable
.Raw
159 ASSERT_EFI_ERROR (Status
);
161 if (SmbiosTable
.Hdr
->Type
== 0) {
162 NeedSmbiosType0
= FALSE
;
166 // Get the next structure address
168 SmbiosTable
.Raw
= (UINT8
*)(SmbiosTable
.Raw
+ SmbiosTableLength (SmbiosTable
));
171 if (NeedSmbiosType0
) {
173 // Add OVMF default Type 0 (BIOS Information) table
175 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
176 Status
= Smbios
->Add (
180 (EFI_SMBIOS_TABLE_HEADER
*)&mOvmfDefaultType0
182 ASSERT_EFI_ERROR (Status
);
189 Installs SMBIOS information for OVMF
191 @param ImageHandle Module's image handle
192 @param SystemTable Pointer of EFI_SYSTEM_TABLE
194 @retval EFI_SUCCESS Smbios data successfully installed
195 @retval Other Smbios data was not installed
200 SmbiosTablePublishEntry (
201 IN EFI_HANDLE ImageHandle
,
202 IN EFI_SYSTEM_TABLE
*SystemTable
206 EFI_SMBIOS_PROTOCOL
*Smbios
;
207 SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
;
208 UINT8
*SmbiosTables
= NULL
;
211 // Find the SMBIOS protocol
213 Status
= gBS
->LocateProtocol (
214 &gEfiSmbiosProtocolGuid
,
218 if (EFI_ERROR (Status
)) {
223 // Add bhyve SMBIOS data
225 EntryPointStructure
= GetBhyveSmbiosTables ();
226 if (EntryPointStructure
!= NULL
) {
227 SmbiosTables
= (UINT8
*)(UINTN
)EntryPointStructure
->TableAddress
;
230 if (SmbiosTables
!= NULL
) {
231 Status
= InstallAllStructures (Smbios
, SmbiosTables
);
234 // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):
236 if (EntryPointStructure
== NULL
) {
237 FreePool (SmbiosTables
);