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