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