]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
OvmfPkg: introduce EnrollDefaultKeys application
[mirror_edk2.git] / OvmfPkg / SmbiosPlatformDxe / SmbiosPlatformDxe.c
1 /** @file
2 This driver installs SMBIOS information for OVMF
3
4 Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
5 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include "SmbiosPlatformDxe.h"
12
13 #define TYPE0_STRINGS \
14 "EFI Development Kit II / OVMF\0" /* Vendor */ \
15 "0.0.0\0" /* BiosVersion */ \
16 "02/06/2015\0" /* BiosReleaseDate */
17 //
18 // Type definition and contents of the default Type 0 SMBIOS table.
19 //
20 #pragma pack(1)
21 typedef struct {
22 SMBIOS_TABLE_TYPE0 Base;
23 UINT8 Strings[sizeof(TYPE0_STRINGS)];
24 } OVMF_TYPE0;
25 #pragma pack()
26
27 STATIC CONST OVMF_TYPE0 mOvmfDefaultType0 = {
28 {
29 // SMBIOS_STRUCTURE Hdr
30 {
31 EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
32 sizeof (SMBIOS_TABLE_TYPE0), // UINT8 Length
33 },
34 1, // SMBIOS_TABLE_STRING Vendor
35 2, // SMBIOS_TABLE_STRING BiosVersion
36 0xE800,// UINT16 BiosSegment
37 3, // SMBIOS_TABLE_STRING BiosReleaseDate
38 0, // UINT8 BiosSize
39 { // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
40 0, // Reserved :2
41 0, // Unknown :1
42 1, // BiosCharacteristicsNotSupported :1
43 // Remaining BiosCharacteristics bits left unset :60
44 },
45 { // BIOSCharacteristicsExtensionBytes[2]
46 0, // BiosReserved
47 0x1C // SystemReserved = VirtualMachineSupported |
48 // UefiSpecificationSupported |
49 // TargetContentDistributionEnabled
50 },
51 0, // UINT8 SystemBiosMajorRelease
52 0, // UINT8 SystemBiosMinorRelease
53 0xFF, // UINT8 EmbeddedControllerFirmwareMajorRelease
54 0xFF // UINT8 EmbeddedControllerFirmwareMinorRelease
55 },
56 // Text strings (unformatted area)
57 TYPE0_STRINGS
58 };
59
60
61 /**
62 Get SMBIOS record length.
63
64 @param SmbiosTable SMBIOS pointer.
65
66 **/
67 UINTN
68 SmbiosTableLength (
69 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
70 )
71 {
72 CHAR8 *AChar;
73 UINTN Length;
74
75 AChar = (CHAR8 *)(SmbiosTable.Raw + SmbiosTable.Hdr->Length);
76
77 //
78 // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
79 //
80 while ((*AChar != 0) || (*(AChar + 1) != 0)) {
81 AChar ++;
82 }
83 Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);
84
85 return Length;
86 }
87
88
89 /**
90 Install all structures from the given SMBIOS structures block
91
92 @param Smbios SMBIOS protocol
93 @param TableAddress SMBIOS tables starting address
94
95 **/
96 EFI_STATUS
97 InstallAllStructures (
98 IN EFI_SMBIOS_PROTOCOL *Smbios,
99 IN UINT8 *TableAddress
100 )
101 {
102 EFI_STATUS Status;
103 SMBIOS_STRUCTURE_POINTER SmbiosTable;
104 EFI_SMBIOS_HANDLE SmbiosHandle;
105 BOOLEAN NeedSmbiosType0;
106
107 SmbiosTable.Raw = TableAddress;
108 if (SmbiosTable.Raw == NULL) {
109 return EFI_INVALID_PARAMETER;
110 }
111
112 NeedSmbiosType0 = TRUE;
113
114 while (SmbiosTable.Hdr->Type != 127) {
115 //
116 // Log the SMBIOS data for this structure
117 //
118 SmbiosHandle = SmbiosTable.Hdr->Handle;
119 Status = Smbios->Add (
120 Smbios,
121 NULL,
122 &SmbiosHandle,
123 (EFI_SMBIOS_TABLE_HEADER*) SmbiosTable.Raw
124 );
125 ASSERT_EFI_ERROR (Status);
126
127 if (SmbiosTable.Hdr->Type == 0) {
128 NeedSmbiosType0 = FALSE;
129 }
130
131 //
132 // Get the next structure address
133 //
134 SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));
135 }
136
137 if (NeedSmbiosType0) {
138 //
139 // Add OVMF default Type 0 (BIOS Information) table
140 //
141 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
142 Status = Smbios->Add (
143 Smbios,
144 NULL,
145 &SmbiosHandle,
146 (EFI_SMBIOS_TABLE_HEADER*) &mOvmfDefaultType0
147 );
148 ASSERT_EFI_ERROR (Status);
149 }
150
151 return EFI_SUCCESS;
152 }
153
154
155 /**
156 Installs SMBIOS information for OVMF
157
158 @param ImageHandle Module's image handle
159 @param SystemTable Pointer of EFI_SYSTEM_TABLE
160
161 @retval EFI_SUCCESS Smbios data successfully installed
162 @retval Other Smbios data was not installed
163
164 **/
165 EFI_STATUS
166 EFIAPI
167 SmbiosTablePublishEntry (
168 IN EFI_HANDLE ImageHandle,
169 IN EFI_SYSTEM_TABLE *SystemTable
170 )
171 {
172 EFI_STATUS Status;
173 EFI_SMBIOS_PROTOCOL *Smbios;
174 SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure;
175 UINT8 *SmbiosTables;
176
177 //
178 // Find the SMBIOS protocol
179 //
180 Status = gBS->LocateProtocol (
181 &gEfiSmbiosProtocolGuid,
182 NULL,
183 (VOID**)&Smbios
184 );
185 if (EFI_ERROR (Status)) {
186 return Status;
187 }
188
189 //
190 // Add Xen or QEMU SMBIOS data if found
191 //
192 EntryPointStructure = GetXenSmbiosTables ();
193 if (EntryPointStructure != NULL) {
194 SmbiosTables = (UINT8*)(UINTN)EntryPointStructure->TableAddress;
195 } else {
196 SmbiosTables = GetQemuSmbiosTables ();
197 }
198
199 if (SmbiosTables != NULL) {
200 Status = InstallAllStructures (Smbios, SmbiosTables);
201
202 //
203 // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):
204 //
205 if (EntryPointStructure == NULL) {
206 FreePool (SmbiosTables);
207 }
208 }
209
210 return Status;
211 }