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