revert to older version as /Zm option for "ml" can not work well.
[edk2.git] / DuetPkg / DataHubGenDxe / DataHubGen.c
blob3878b74fc53ae48d5d90287ee0bb42fb9fb7c9a0
1 /** @file
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 Module Name:
14 DataHubGen.c
16 Abstract:
18 **/
20 #include "DataHubGen.h"
21 EFI_HII_DATABASE_PROTOCOL *gHiiDatabase;
23 extern UINT8 DataHubGenDxeStrings[];
25 EFI_DATA_HUB_PROTOCOL *gDataHub;
26 EFI_HII_HANDLE gStringHandle;
28 VOID *
29 GetSmbiosTablesFromHob (
30 VOID
33 EFI_PHYSICAL_ADDRESS *Table;
34 EFI_PEI_HOB_POINTERS GuidHob;
36 // Get Hob List
38 GuidHob.Raw = GetHobList ();
39 GuidHob.Raw = GetNextGuidHob (&gEfiSmbiosTableGuid, GuidHob.Raw);
40 if (GuidHob.Raw != NULL) {
41 Table = GET_GUID_HOB_DATA (GuidHob.Guid);
42 if (Table != NULL) {
43 return (VOID *)(UINTN)*Table;
47 return NULL;
50 EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader = {
51 EFI_PROCESSOR_SUBCLASS_VERSION, // Version
52 sizeof (EFI_SUBCLASS_TYPE1_HEADER), // Header Size
53 0, // Instance, Initialize later
54 EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance
55 0 // RecordType, Initialize later
58 VOID
59 InstallProcessorDataHub (
60 IN VOID *Smbios
63 EFI_STATUS Status;
64 SMBIOS_STRUCTURE_POINTER SmbiosTable;
65 EFI_CPU_DATA_RECORD DataRecord;
66 CHAR8 *AString;
67 CHAR16 *UString;
68 STRING_REF Token;
71 // Processor info (TYPE 4)
72 //
73 SmbiosTable = GetSmbiosTableFromType ((SMBIOS_TABLE_ENTRY_POINT *)Smbios, 4, 0);
74 if (SmbiosTable.Raw == NULL) {
75 DEBUG ((EFI_D_ERROR, "SmbiosTable: Type 4 (Processor Info) not found!\n"));
76 return ;
80 // Record Header
82 CopyMem (&DataRecord, &mCpuDataRecordHeader, sizeof (DataRecord.DataRecordHeader));
85 // Record Type 1
87 DataRecord.DataRecordHeader.RecordType = ProcessorCoreFrequencyRecordType;
88 DataRecord.VariableRecord.ProcessorCoreFrequency.Value = SmbiosTable.Type4->CurrentSpeed;
89 DataRecord.VariableRecord.ProcessorCoreFrequency.Exponent = 6;
91 Status = gDataHub->LogData (
92 gDataHub,
93 &gEfiProcessorSubClassGuid,
94 &gEfiMiscProducerGuid,
95 EFI_DATA_RECORD_CLASS_DATA,
96 &DataRecord,
97 sizeof (DataRecord.DataRecordHeader) + sizeof (DataRecord.VariableRecord.ProcessorCoreFrequency)
100 // Record Type 3
102 AString = GetSmbiosString (SmbiosTable, SmbiosTable.Type4->ProcessorVersion);
103 UString = AllocateZeroPool ((AsciiStrLen(AString) + 1) * sizeof(CHAR16));
104 ASSERT (UString != NULL);
105 AsciiStrToUnicodeStr (AString, UString);
107 Status = HiiLibNewString (gStringHandle, &Token, UString);
109 if (EFI_ERROR (Status)) {
110 gBS->FreePool (UString);
111 return ;
113 gBS->FreePool (UString);
115 DataRecord.DataRecordHeader.RecordType = ProcessorVersionRecordType;
116 DataRecord.VariableRecord.ProcessorVersion = Token;
118 Status = gDataHub->LogData (
119 gDataHub,
120 &gEfiProcessorSubClassGuid,
121 &gEfiMiscProducerGuid,
122 EFI_DATA_RECORD_CLASS_DATA,
123 &DataRecord,
124 sizeof (DataRecord.DataRecordHeader) + sizeof (DataRecord.VariableRecord.ProcessorVersion)
127 return ;
130 VOID
131 InstallCacheDataHub (
132 IN VOID *Smbios
135 return ;
138 EFI_SUBCLASS_TYPE1_HEADER mMemorySubclassDriverDataHeader = {
139 EFI_MEMORY_SUBCLASS_VERSION, // Version
140 sizeof (EFI_SUBCLASS_TYPE1_HEADER), // Header Size
141 0, // Instance, Initialize later
142 EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance
143 0 // RecordType, Initialize later
146 VOID
147 InstallMemoryDataHub (
148 IN VOID *Smbios
151 SMBIOS_STRUCTURE_POINTER SmbiosTable;
152 EFI_MEMORY_SUBCLASS_DRIVER_DATA DataRecord;
155 // Generate Memory Array Mapped Address info (TYPE 19)
157 SmbiosTable = GetSmbiosTableFromType ((SMBIOS_TABLE_ENTRY_POINT *)Smbios, 19, 0);
158 if (SmbiosTable.Raw == NULL) {
159 DEBUG ((EFI_D_ERROR, "SmbiosTable: Type 19 (Memory Array Mapped Address Info) not found!\n"));
160 return ;
164 // Record Header
166 CopyMem (&DataRecord, &mMemorySubclassDriverDataHeader, sizeof (DataRecord.Header));
169 // Record Type 4
171 DataRecord.Header.RecordType = EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER;
172 DataRecord.Record.ArrayStartAddress.MemoryArrayStartAddress = LShiftU64(SmbiosTable.Type19->StartingAddress, 10);
173 DataRecord.Record.ArrayStartAddress.MemoryArrayEndAddress = LShiftU64((UINT64) SmbiosTable.Type19->EndingAddress + 1, 10) - 1;
175 DataRecord.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName = gEfiMemoryProducerGuid;
176 DataRecord.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance = 0;
177 DataRecord.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;
178 DataRecord.Record.ArrayStartAddress.MemoryArrayPartitionWidth = (UINT16)(SmbiosTable.Type19->PartitionWidth);
180 gDataHub->LogData (
181 gDataHub,
182 &gEfiMemorySubClassGuid,
183 &gEfiMiscProducerGuid,
184 EFI_DATA_RECORD_CLASS_DATA,
185 &DataRecord,
186 sizeof (DataRecord.Header) + sizeof (DataRecord.Record.ArrayStartAddress)
189 return ;
192 EFI_SUBCLASS_TYPE1_HEADER mMiscSubclassDriverDataHeader = {
193 EFI_MISC_SUBCLASS_VERSION, // Version
194 sizeof (EFI_SUBCLASS_TYPE1_HEADER), // Header Size
195 0, // Instance, Initialize later
196 EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance
197 0 // RecordType, Initialize later
200 VOID
201 InstallMiscDataHub (
202 IN VOID *Smbios
205 EFI_STATUS Status;
206 SMBIOS_STRUCTURE_POINTER SmbiosTable;
207 EFI_MISC_SUBCLASS_DRIVER_DATA DataRecord;
208 CHAR8 *AString;
209 CHAR16 *UString;
210 STRING_REF Token;
213 // BIOS information (TYPE 0)
215 SmbiosTable = GetSmbiosTableFromType ((SMBIOS_TABLE_ENTRY_POINT *)Smbios, 0, 0);
216 if (SmbiosTable.Raw == NULL) {
217 DEBUG ((EFI_D_ERROR, "SmbiosTable: Type 0 (BIOS Information) not found!\n"));
218 return ;
222 // Record Header
224 CopyMem (&DataRecord, &mMiscSubclassDriverDataHeader, sizeof (DataRecord.Header));
227 // Record Type 2
229 AString = GetSmbiosString (SmbiosTable, SmbiosTable.Type0->BiosVersion);
230 UString = AllocateZeroPool ((AsciiStrLen(AString) + 1) * sizeof(CHAR16) + sizeof(FIRMWARE_BIOS_VERSIONE));
231 ASSERT (UString != NULL);
232 CopyMem (UString, FIRMWARE_BIOS_VERSIONE, sizeof(FIRMWARE_BIOS_VERSIONE));
233 AsciiStrToUnicodeStr (AString, UString + sizeof(FIRMWARE_BIOS_VERSIONE) / sizeof(CHAR16) - 1);
235 Status = HiiLibNewString (gStringHandle, &Token, UString);
237 if (EFI_ERROR (Status)) {
238 gBS->FreePool (UString);
239 return ;
241 gBS->FreePool (UString);
243 DataRecord.Header.RecordType = EFI_MISC_BIOS_VENDOR_RECORD_NUMBER;
244 DataRecord.Record.MiscBiosVendor.BiosVendor = 0;
245 DataRecord.Record.MiscBiosVendor.BiosVersion = Token;
246 DataRecord.Record.MiscBiosVendor.BiosReleaseDate = 0;
247 DataRecord.Record.MiscBiosVendor.BiosStartingAddress = 0;
248 DataRecord.Record.MiscBiosVendor.BiosPhysicalDeviceSize.Value = 0;
249 DataRecord.Record.MiscBiosVendor.BiosPhysicalDeviceSize.Exponent = 0;
250 // DataRecord.Record.MiscBiosVendor.BiosCharacteristics1 = {0};
251 // DataRecord.Record.MiscBiosVendor.BiosCharacteristics2 = {0};
252 DataRecord.Record.MiscBiosVendor.BiosMajorRelease = 0;
253 DataRecord.Record.MiscBiosVendor.BiosMinorRelease = 0;
254 DataRecord.Record.MiscBiosVendor.BiosEmbeddedFirmwareMajorRelease = 0;
255 DataRecord.Record.MiscBiosVendor.BiosEmbeddedFirmwareMinorRelease = 0;
257 Status = gDataHub->LogData (
258 gDataHub,
259 &gEfiMiscSubClassGuid,
260 &gEfiMiscProducerGuid,
261 EFI_DATA_RECORD_CLASS_DATA,
262 &DataRecord,
263 sizeof (DataRecord.Header) + sizeof (DataRecord.Record.MiscBiosVendor)
267 // System information (TYPE 1)
269 SmbiosTable = GetSmbiosTableFromType ((SMBIOS_TABLE_ENTRY_POINT *)Smbios, 1, 0);
270 if (SmbiosTable.Raw == NULL) {
271 DEBUG ((EFI_D_ERROR, "SmbiosTable: Type 1 (System Information) not found!\n"));
272 return ;
276 // Record Type 3
278 AString = GetSmbiosString (SmbiosTable, SmbiosTable.Type1->ProductName);
279 UString = AllocateZeroPool ((AsciiStrLen(AString) + 1) * sizeof(CHAR16) + sizeof(FIRMWARE_PRODUCT_NAME));
280 ASSERT (UString != NULL);
281 CopyMem (UString, FIRMWARE_PRODUCT_NAME, sizeof(FIRMWARE_PRODUCT_NAME));
282 AsciiStrToUnicodeStr (AString, UString + sizeof(FIRMWARE_PRODUCT_NAME) / sizeof(CHAR16) - 1);
284 Status = HiiLibNewString (gStringHandle, &Token, UString);
286 if (EFI_ERROR (Status)) {
287 gBS->FreePool (UString);
288 return ;
290 gBS->FreePool (UString);
292 DataRecord.Header.RecordType = EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER;
293 DataRecord.Record.MiscSystemManufacturer.SystemManufacturer = 0;
294 DataRecord.Record.MiscSystemManufacturer.SystemProductName = Token;
295 DataRecord.Record.MiscSystemManufacturer.SystemVersion = 0;
296 DataRecord.Record.MiscSystemManufacturer.SystemSerialNumber = 0;
297 // DataRecord.Record.MiscSystemManufacturer.SystemUuid = {0};
298 DataRecord.Record.MiscSystemManufacturer.SystemWakeupType = EfiSystemWakeupTypeReserved;
299 DataRecord.Record.MiscSystemManufacturer.SystemSKUNumber = 0;
300 DataRecord.Record.MiscSystemManufacturer.SystemFamily = 0;
302 Status = gDataHub->LogData (
303 gDataHub,
304 &gEfiMiscSubClassGuid,
305 &gEfiMiscProducerGuid,
306 EFI_DATA_RECORD_CLASS_DATA,
307 &DataRecord,
308 sizeof (DataRecord.Header) + sizeof (DataRecord.Record.MiscSystemManufacturer)
311 return ;
314 EFI_STATUS
315 EFIAPI
316 DataHubGenEntrypoint (
317 IN EFI_HANDLE ImageHandle,
318 IN EFI_SYSTEM_TABLE *SystemTable
321 EFI_STATUS Status;
322 VOID *Smbios;
324 Smbios = GetSmbiosTablesFromHob ();
325 if (Smbios == NULL) {
326 return EFI_NOT_FOUND;
329 Status = gBS->LocateProtocol (
330 &gEfiDataHubProtocolGuid,
331 NULL,
332 (VOID**)&gDataHub
334 if (EFI_ERROR (Status)) {
335 return Status;
338 Status = gBS->LocateProtocol (
339 &gEfiHiiDatabaseProtocolGuid,
340 NULL,
341 (VOID**)&gHiiDatabase
344 if (EFI_ERROR (Status)) {
345 return Status;
348 HiiLibAddPackages (1, &gEfiMiscProducerGuid, NULL, &gStringHandle, DataHubGenDxeStrings);
350 InstallProcessorDataHub (Smbios);
351 InstallCacheDataHub (Smbios);
352 InstallMemoryDataHub (Smbios);
353 InstallMiscDataHub (Smbios);
355 return EFI_SUCCESS;
359 // Internal function
362 UINTN
363 SmbiosTableLength (
364 IN SMBIOS_STRUCTURE_POINTER SmbiosTable
367 CHAR8 *AChar;
368 UINTN Length;
370 AChar = (CHAR8 *)(SmbiosTable.Raw + SmbiosTable.Hdr->Length);
371 while ((*AChar != 0) || (*(AChar + 1) != 0)) {
372 AChar ++;
374 Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);
376 return Length;
379 SMBIOS_STRUCTURE_POINTER
380 GetSmbiosTableFromType (
381 IN SMBIOS_TABLE_ENTRY_POINT *Smbios,
382 IN UINT8 Type,
383 IN UINTN Index
386 SMBIOS_STRUCTURE_POINTER SmbiosTable;
387 UINTN SmbiosTypeIndex;
389 SmbiosTypeIndex = 0;
390 SmbiosTable.Raw = (UINT8 *)(UINTN)Smbios->TableAddress;
391 if (SmbiosTable.Raw == NULL) {
392 return SmbiosTable;
394 while ((SmbiosTypeIndex != Index) || (SmbiosTable.Hdr->Type != Type)) {
395 if (SmbiosTable.Hdr->Type == 127) {
396 SmbiosTable.Raw = NULL;
397 return SmbiosTable;
399 if (SmbiosTable.Hdr->Type == Type) {
400 SmbiosTypeIndex ++;
402 SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));
405 return SmbiosTable;
408 CHAR8 *
409 GetSmbiosString (
410 IN SMBIOS_STRUCTURE_POINTER SmbiosTable,
411 IN SMBIOS_TABLE_STRING String
414 CHAR8 *AString;
415 UINT8 Index;
417 Index = 1;
418 AString = (CHAR8 *)(SmbiosTable.Raw + SmbiosTable.Hdr->Length);
419 while (Index != String) {
420 while (*AString != 0) {
421 AString ++;
423 AString ++;
424 if (*AString == 0) {
425 return AString;
427 Index ++;
430 return AString;