]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformSetupDxe/SetupInfoRecords.c
c404ada58803af9423a1a41a341c0a0898a45ac0
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformSetupDxe / SetupInfoRecords.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7
8
9
10 Module Name:
11
12 SetupInfoRecords.c
13
14 Abstract:
15
16 This is the filter driver to retrieve data hub entries.
17
18 Revision History:
19 --*/
20
21 #include "PlatformSetupDxe.h"
22 #include <Protocol/LegacyBios.h>
23 #include <Protocol/PciRootBridgeIo.h>
24 #include <Protocol/SimpleNetwork.h>
25 #include <Protocol/DevicePath.h>
26 #include <Protocol/DiskInfo.h>
27 #include <Protocol/IdeControllerInit.h>
28 #include <Protocol/MpService.h>
29 #include <Protocol/PchPlatformPolicy.h>
30 #include <Protocol/CpuIo2.h>
31 #include <Protocol/Smbios.h>
32 #include <IndustryStandard/SmBios.h>
33 #include <Library/IoLib.h>
34 #include <Library/I2CLib.h>
35 #include <Guid/GlobalVariable.h>
36
37 #include "Valleyview.h"
38 #include "VlvAccess.h"
39 #include "PchAccess.h"
40 #include "SetupMode.h"
41 #include "PchCommonDefinitions.h"
42 #include <PlatformBaseAddresses.h>
43
44
45 typedef struct {
46 UINT8 ID;
47 CHAR8 String[16];
48 } VLV_REV;
49
50 typedef struct {
51 UINT8 RevId;
52 CHAR8 String[16];
53 } SB_REV;
54
55 //
56 // Silicon Steppings
57 //
58 SB_REV SBRevisionTable[] = {
59 {V_PCH_LPC_RID_0, "(A0 Stepping)"},
60 {V_PCH_LPC_RID_1, "(A0 Stepping)"},
61 {V_PCH_LPC_RID_2, "(A1 Stepping)"},
62 {V_PCH_LPC_RID_3, "(A1 Stepping)"},
63 {V_PCH_LPC_RID_4, "(B0 Stepping)"},
64 {V_PCH_LPC_RID_5, "(B0 Stepping)"},
65 {V_PCH_LPC_RID_6, "(B1 Stepping)"},
66 {V_PCH_LPC_RID_7, "(B1 Stepping)"},
67 {V_PCH_LPC_RID_8, "(B2 Stepping)"},
68 {V_PCH_LPC_RID_9, "(B2 Stepping)"},
69 {V_PCH_LPC_RID_A, "(B3 Stepping)"},
70 {V_PCH_LPC_RID_B, "(B3 Stepping)"},
71 {V_PCH_LPC_RID_C, "(C0 Stepping)"},
72 {V_PCH_LPC_RID_D, "(C0 Stepping)"}
73 };
74
75 #define LEFT_JUSTIFY 0x01
76 #define PREFIX_SIGN 0x02
77 #define PREFIX_BLANK 0x04
78 #define COMMA_TYPE 0x08
79 #define LONG_TYPE 0x10
80 #define PREFIX_ZERO 0x20
81
82 #define ICH_REG_REV 0x08
83 #define MSR_IA32_PLATFORM_ID 0x17
84
85
86 BOOLEAN mSetupInfoDone = FALSE;
87 UINT8 mUseProductKey = 0;
88 EFI_EXP_BASE10_DATA mProcessorFrequency;
89 EFI_EXP_BASE10_DATA mProcessorFsbFrequency;
90
91 EFI_GUID mProcessorProducerGuid;
92 EFI_HII_HANDLE mHiiHandle;
93 EFI_PLATFORM_CPU_INFO mPlatformCpuInfo;
94 SYSTEM_CONFIGURATION mSystemConfiguration;
95 EFI_PLATFORM_INFO_HOB *mPlatformInfo;
96
97
98 #define memset SetMem
99
100 UINT16 mMemorySpeed = 0xffff;
101 EFI_PHYSICAL_ADDRESS mMemorySizeChannelASlot0 = 0;
102 UINT16 mMemorySpeedChannelASlot0 = 0xffff;
103 EFI_PHYSICAL_ADDRESS mMemorySizeChannelASlot1 = 0;
104 UINT16 mMemorySpeedChannelASlot1 = 0xffff;
105 EFI_PHYSICAL_ADDRESS mMemorySizeChannelBSlot0 = 0;
106 UINT16 mMemorySpeedChannelBSlot0 = 0xffff;
107 EFI_PHYSICAL_ADDRESS mMemorySizeChannelBSlot1 = 0;
108 UINT16 mMemorySpeedChannelBSlot1 = 0xffff;
109 EFI_PHYSICAL_ADDRESS mMemorySizeChannelCSlot0 = 0;
110 UINT16 mMemorySpeedChannelCSlot0 = 0xffff;
111 EFI_PHYSICAL_ADDRESS mMemorySizeChannelCSlot1 = 0;
112 UINT16 mMemorySpeedChannelCSlot1 = 0xffff;
113 UINTN mMemoryMode = 0xff;
114
115 #define CHARACTER_NUMBER_FOR_VALUE 30
116 typedef struct {
117 EFI_STRING_TOKEN MemoryDeviceLocator;
118 EFI_STRING_TOKEN MemoryBankLocator;
119 EFI_STRING_TOKEN MemoryManufacturer;
120 EFI_STRING_TOKEN MemorySerialNumber;
121 EFI_STRING_TOKEN MemoryAssetTag;
122 EFI_STRING_TOKEN MemoryPartNumber;
123 EFI_INTER_LINK_DATA MemoryArrayLink;
124 EFI_INTER_LINK_DATA MemorySubArrayLink;
125 UINT16 MemoryTotalWidth;
126 UINT16 MemoryDataWidth;
127 UINT64 MemoryDeviceSize;
128 EFI_MEMORY_FORM_FACTOR MemoryFormFactor;
129 UINT8 MemoryDeviceSet;
130 EFI_MEMORY_ARRAY_TYPE MemoryType;
131 EFI_MEMORY_TYPE_DETAIL MemoryTypeDetail;
132 UINT16 MemorySpeed;
133 EFI_MEMORY_STATE MemoryState;
134 } EFI_MEMORY_ARRAY_LINK;
135
136
137 typedef struct {
138 EFI_PHYSICAL_ADDRESS MemoryArrayStartAddress;
139 EFI_PHYSICAL_ADDRESS MemoryArrayEndAddress;
140 EFI_INTER_LINK_DATA PhysicalMemoryArrayLink;
141 UINT16 MemoryArrayPartitionWidth;
142 } EFI_MEMORY_ARRAY_START_ADDRESS;
143
144
145 typedef enum {
146 PCH_SATA_MODE_IDE = 0,
147 PCH_SATA_MODE_AHCI,
148 PCH_SATA_MODE_RAID,
149 PCH_SATA_MODE_MAX
150 } PCH_SATA_MODE;
151
152 /**
153 Acquire the string associated with the Index from smbios structure and return it.
154 The caller is responsible for free the string buffer.
155
156 @param OptionalStrStart The start position to search the string
157 @param Index The index of the string to extract
158 @param String The string that is extracted
159
160 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
161
162 **/
163 EFI_STATUS
164 GetOptionalStringByIndex (
165 IN CHAR8 *OptionalStrStart,
166 IN UINT8 Index,
167 OUT CHAR16 **String
168 )
169 {
170 UINTN StrSize;
171
172 if (Index == 0) {
173 *String = AllocateZeroPool (sizeof (CHAR16));
174 return EFI_SUCCESS;
175 }
176
177 StrSize = 0;
178 do {
179 Index--;
180 OptionalStrStart += StrSize;
181 StrSize = AsciiStrSize (OptionalStrStart);
182 } while (OptionalStrStart[StrSize] != 0 && Index != 0);
183
184 if ((Index != 0) || (StrSize == 1)) {
185 //
186 // Meet the end of strings set but Index is non-zero, or
187 // Find an empty string
188 //
189 return EFI_NOT_FOUND;
190 } else {
191 *String = AllocatePool (StrSize * sizeof (CHAR16));
192 AsciiStrToUnicodeStr (OptionalStrStart, *String);
193 }
194
195 return EFI_SUCCESS;
196 }
197
198 /**
199 VSPrint worker function that prints a Value as a decimal number in Buffer
200
201 @param Buffer Location to place ascii decimal number string of Value.
202 @param Value Decimal value to convert to a string in Buffer.
203 @param Flags Flags to use in printing decimal string, see file header for details.
204 @param Width Width of hex value.
205
206 Number of characters printed.
207
208 **/
209 UINTN
210 EfiValueToString (
211 IN OUT CHAR16 *Buffer,
212 IN INT64 Value,
213 IN UINTN Flags,
214 IN UINTN Width
215 )
216 {
217 CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
218 CHAR16 *TempStr;
219 CHAR16 *BufferPtr;
220 UINTN Count;
221 UINTN ValueCharNum;
222 UINTN Remainder;
223 CHAR16 Prefix;
224 UINTN Index;
225 BOOLEAN ValueIsNegative;
226 UINT64 TempValue;
227
228 TempStr = TempBuffer;
229 BufferPtr = Buffer;
230 Count = 0;
231 ValueCharNum = 0;
232 ValueIsNegative = FALSE;
233
234 if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
235 Width = CHARACTER_NUMBER_FOR_VALUE - 1;
236 }
237
238 if (Value < 0) {
239 Value = -Value;
240 ValueIsNegative = TRUE;
241 }
242
243 do {
244 TempValue = Value;
245 Value = (INT64)DivU64x32 ((UINT64)Value, 10);
246 Remainder = (UINTN)((UINT64)TempValue - 10 * Value);
247 *(TempStr++) = (CHAR16)(Remainder + '0');
248 ValueCharNum++;
249 Count++;
250 if ((Flags & COMMA_TYPE) == COMMA_TYPE) {
251 if (ValueCharNum % 3 == 0 && Value != 0) {
252 *(TempStr++) = ',';
253 Count++;
254 }
255 }
256 } while (Value != 0);
257
258 if (ValueIsNegative) {
259 *(TempStr++) = '-';
260 Count++;
261 }
262
263 if ((Flags & PREFIX_ZERO) && !ValueIsNegative) {
264 Prefix = '0';
265 } else {
266 Prefix = ' ';
267 }
268
269 Index = Count;
270 if (!(Flags & LEFT_JUSTIFY)) {
271 for (; Index < Width; Index++) {
272 *(TempStr++) = Prefix;
273 }
274 }
275
276 //
277 // Reverse temp string into Buffer.
278 //
279 if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
280 TempStr = TempBuffer + Width;
281 }
282 Index = 0;
283 while (TempStr != TempBuffer) {
284 *(BufferPtr++) = *(--TempStr);
285 Index++;
286 }
287
288 *BufferPtr = 0;
289 return Index;
290 }
291
292 static CHAR16 mHexStr[] = { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
293 L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F' };
294
295 /**
296 VSPrint worker function that prints a Value as a hex number in Buffer
297
298 @param Buffer Location to place ascii hex string of Value.
299 @param Value Hex value to convert to a string in Buffer.
300 @param Flags Flags to use in printing Hex string, see file header for details.
301 @param Width Width of hex value.
302
303 @retval Number of characters printed.
304
305 **/
306 UINTN
307 EfiValueToHexStr (
308 IN OUT CHAR16 *Buffer,
309 IN UINT64 Value,
310 IN UINTN Flags,
311 IN UINTN Width
312 )
313 {
314 CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
315 CHAR16 *TempStr;
316 CHAR16 Prefix;
317 CHAR16 *BufferPtr;
318 UINTN Count;
319 UINTN Index;
320
321 TempStr = TempBuffer;
322 BufferPtr = Buffer;
323
324 //
325 // Count starts at one since we will null terminate. Each iteration of the
326 // loop picks off one nibble. Oh yea TempStr ends up backwards
327 //
328 Count = 0;
329
330 if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
331 Width = CHARACTER_NUMBER_FOR_VALUE - 1;
332 }
333
334 do {
335 Index = ((UINTN)Value & 0xf);
336 *(TempStr++) = mHexStr[Index];
337 Value = RShiftU64 (Value, 4);
338 Count++;
339 } while (Value != 0);
340
341 if (Flags & PREFIX_ZERO) {
342 Prefix = '0';
343 } else {
344 Prefix = ' ';
345 }
346
347 Index = Count;
348 if (!(Flags & LEFT_JUSTIFY)) {
349 for (; Index < Width; Index++) {
350 *(TempStr++) = Prefix;
351 }
352 }
353
354 //
355 // Reverse temp string into Buffer.
356 //
357 if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
358 TempStr = TempBuffer + Width;
359 }
360 Index = 0;
361 while (TempStr != TempBuffer) {
362 *(BufferPtr++) = *(--TempStr);
363 Index++;
364 }
365
366 *BufferPtr = 0;
367 return Index;
368 }
369
370 /*++
371 Converts MAC address to Unicode string.
372 The value is 64-bit and the resulting string will be 12
373 digit hex number in pairs of digits separated by dashes.
374
375 @param String string that will contain the value
376 @param MacAddr add argument and description to function comment
377 @param AddrSize add argument and description to function comment
378
379 **/
380 CHAR16 *
381 StrMacToString (
382 OUT CHAR16 *String,
383 IN EFI_MAC_ADDRESS *MacAddr,
384 IN UINT32 AddrSize
385 )
386 {
387 UINT32 i;
388
389 for (i = 0; i < AddrSize; i++) {
390
391 EfiValueToHexStr (
392 &String[2 * i],
393 MacAddr->Addr[i] & 0xFF,
394 PREFIX_ZERO,
395 2
396 );
397 }
398
399 //
400 // Terminate the string.
401 //
402 String[2 * AddrSize] = L'\0';
403
404 return String;
405 }
406
407 VOID UpdateLatestBootTime() {
408 UINTN VarSize;
409 EFI_STATUS Status;
410 UINT64 TimeValue;
411 CHAR16 Buffer[40];
412 if (mSystemConfiguration.LogBootTime != 1) {
413 return;
414 }
415 VarSize = sizeof(TimeValue);
416 Status = gRT->GetVariable(
417 BOOT_TIME_NAME,
418 &gEfiNormalSetupGuid,
419 NULL,
420 &VarSize,
421 &TimeValue
422 );
423 if (EFI_ERROR(Status)) {
424 return;
425 }
426 UnicodeSPrint (Buffer, sizeof (Buffer), L"%d ms", (UINT32)TimeValue);
427 HiiSetString(mHiiHandle,STRING_TOKEN(STR_LOG_BOOT_TIME_VALUE), Buffer, NULL);
428 }
429
430 /**
431 Get Cache Type for the specified Cache. This function is invoked when there is data records
432 available in the Data Hub.
433
434 Get Cache Type function arguments:
435
436 @param Instance The instance number of the subclass with the same ProducerName..
437 @param SubInstance The instance number of the RecordType for the same Instance.
438 @param CacheType Cache type, see definition of EFI_CACHE_TYPE_DATA.
439
440 @retval EFI_STATUS
441
442 **/
443 EFI_STATUS
444 GetCacheType(
445 IN UINT16 Instance,
446 IN UINT16 SubInstance,
447 IN EFI_CACHE_TYPE_DATA* CacheType)
448 {
449 EFI_STATUS Status;
450 EFI_DATA_HUB_PROTOCOL *DataHub;
451 EFI_DATA_RECORD_HEADER *Record;
452 UINT64 MonotonicCount;
453 EFI_CACHE_VARIABLE_RECORD* CacheVariableRecord;
454 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
455
456 Status = gBS->LocateProtocol (
457 &gEfiDataHubProtocolGuid,
458 NULL,
459 (void **)&DataHub
460 );
461 ASSERT_EFI_ERROR(Status);
462
463 //
464 // Get all available data records from data hub
465 //
466 MonotonicCount = 0;
467 Record = NULL;
468
469 do {
470 Status = DataHub->GetNextRecord (
471 DataHub,
472 &MonotonicCount,
473 NULL,
474 &Record
475 );
476 if (!EFI_ERROR(Status)) {
477 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
478 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
479
480 if(CompareGuid(&Record->DataRecordGuid, &gEfiCacheSubClassGuid) &&
481 (DataHeader->RecordType == CacheTypeRecordType) &&
482 (DataHeader->Instance == Instance) &&
483 (DataHeader->SubInstance == SubInstance)) {
484 CacheVariableRecord = (EFI_CACHE_VARIABLE_RECORD *)(DataHeader + 1);
485 if(CacheType){
486 *CacheType = CacheVariableRecord->CacheType;
487 return EFI_SUCCESS;
488 }
489 }
490 }
491 }
492 } while(!EFI_ERROR(Status) && (MonotonicCount != 0));
493
494 return EFI_NOT_FOUND;
495 }
496
497 /**
498 Setup data filter function. This function is invoked when there is data records
499 available in the Data Hub.
500
501
502 Standard event notification function arguments:
503 @param Event The event that is signaled.
504 @param Context Not used here.
505
506 @retval EFI_STATUS
507
508 **/
509 VOID
510 PrepareSetupInformation (
511 )
512 {
513
514 EFI_STATUS Status;
515 EFI_DATA_HUB_PROTOCOL *DataHub;
516 EFI_DATA_RECORD_HEADER *Record;
517 UINT8 *SrcData;
518 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
519 CHAR16 *NewString;
520 CHAR16 *NewString2;
521 CHAR16 *NewStringToken;
522 STRING_REF TokenToUpdate;
523 EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;
524 UINTN Index;
525 UINTN DataOutput;
526
527 EFI_PROCESSOR_MICROCODE_REVISION_DATA *CpuUcodeRevisionData;
528 EFI_MEMORY_ARRAY_START_ADDRESS *MemoryArray;
529 EFI_MEMORY_ARRAY_LINK *MemoryArrayLink;
530 UINT64 MonotonicCount;
531
532 CHAR16 Version[100]; //Assuming that strings are < 100 UCHAR
533 CHAR16 ReleaseDate[100]; //Assuming that strings are < 100 UCHAR
534 CHAR16 ReleaseTime[100]; //Assuming that strings are < 100 UCHAR
535
536 NewString = AllocateZeroPool (0x100);
537 NewString2 = AllocateZeroPool (0x100);
538 SetMem(Version, sizeof(Version), 0);
539 SetMem(ReleaseDate, sizeof(ReleaseDate), 0);
540 SetMem(ReleaseTime, sizeof(ReleaseTime), 0);
541
542 //
543 // Get the Data Hub Protocol. Assume only one instance
544 //
545 Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (void **)&DataHub);
546 ASSERT_EFI_ERROR(Status);
547
548 //
549 // Get all available data records from data hub
550 //
551 MonotonicCount = 0;
552 Record = NULL;
553
554 do {
555 Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);
556 if (!EFI_ERROR(Status)) {
557 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
558 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
559 SrcData = (UINT8 *)(DataHeader + 1);
560
561 //
562 // Processor
563 //
564 if (CompareGuid(&Record->DataRecordGuid, &gEfiProcessorSubClassGuid)) {
565 CopyMem (&mProcessorProducerGuid, &Record->ProducerName, sizeof(EFI_GUID));
566 switch (DataHeader->RecordType) {
567 case ProcessorCoreFrequencyRecordType:
568 CopyMem(&mProcessorFrequency, SrcData, sizeof(EFI_EXP_BASE10_DATA));
569 Index = EfiValueToString (
570 NewString,
571 ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)/1000000000,
572 PREFIX_ZERO,
573 0
574 );
575 StrCat (NewString, L".");
576 EfiValueToString (
577 NewString + Index + 1,
578 ((ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)%1000000000)/10000000),
579 PREFIX_ZERO,
580 0
581 );
582 StrCat (NewString, L" GHz");
583 TokenToUpdate = (STRING_REF)STR_PROCESSOR_SPEED_VALUE;
584 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
585 break;
586
587 case ProcessorVersionRecordType:
588 ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *)SrcData;
589 NewStringToken = HiiGetPackageString(&mProcessorProducerGuid, *ProcessorVersion, NULL);
590 TokenToUpdate = (STRING_REF)STR_PROCESSOR_VERSION_VALUE;
591 HiiSetString(mHiiHandle, TokenToUpdate, NewStringToken, NULL);
592 break;
593 case CpuUcodeRevisionDataRecordType:
594 CpuUcodeRevisionData = (EFI_PROCESSOR_MICROCODE_REVISION_DATA *) SrcData;
595 if (CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber != 0) {
596 EfiValueToHexStr (
597 NewString,
598 CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber,
599 PREFIX_ZERO,
600 8
601 );
602 TokenToUpdate = (STRING_REF)STR_PROCESSOR_MICROCODE_VALUE;
603 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
604 }
605 break;
606 default:
607 break;
608 }
609
610 //
611 // Cache
612 //
613 } else if (CompareGuid(&Record->DataRecordGuid, &gEfiCacheSubClassGuid) &&
614 (DataHeader->RecordType == CacheSizeRecordType)) {
615 if (DataHeader->SubInstance == EFI_CACHE_L1) {
616 EFI_CACHE_TYPE_DATA CacheType;
617 if (EFI_SUCCESS == GetCacheType(DataHeader->Instance, DataHeader->SubInstance,&CacheType)){
618 if (CacheType == EfiCacheTypeData) {
619 TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_DATA_CACHE_VALUE;
620 } else if (CacheType == EfiCacheTypeInstruction) {
621 TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_INSTR_CACHE_VALUE;
622 } else {
623 continue;
624 }
625 } else {
626 continue;
627 }
628 }
629 else if (DataHeader->SubInstance == EFI_CACHE_L2) {
630 TokenToUpdate = (STRING_REF)STR_PROCESSOR_L2_CACHE_VALUE;
631 } else {
632 continue;
633 }
634 if (ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData)) {
635 DataOutput = ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData) >> 10;
636 EfiValueToString (NewString, DataOutput, PREFIX_ZERO, 0);
637
638 StrCat (NewString, L" KB");
639 if (DataHeader->SubInstance == EFI_CACHE_L3) {
640 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
641 } else if(DataHeader->SubInstance == EFI_CACHE_L2 && mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage > 1){
642 //
643 // Show XxL2 string
644 //
645 EfiValueToString (
646 NewString2,
647 mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage,
648 PREFIX_ZERO,
649 0
650 );
651 StrCat(NewString2, L"x ");
652 StrCat(NewString2, NewString);
653 HiiSetString(mHiiHandle, TokenToUpdate, NewString2, NULL);
654 } else {
655 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
656 }
657 }
658
659 //
660 // Memory
661 //
662 } else if (CompareGuid(&Record->DataRecordGuid, &gEfiMemorySubClassGuid)) {
663 switch (DataHeader->RecordType) {
664 case EFI_MEMORY_ARRAY_LINK_RECORD_NUMBER:
665 MemoryArrayLink = (EFI_MEMORY_ARRAY_LINK *)SrcData;
666
667 if (MemoryArrayLink->MemorySpeed > 0) {
668 //
669 // Save the lowest speed memory module
670 //
671 if (MemoryArrayLink->MemorySpeed < mMemorySpeed) {
672 mMemorySpeed = MemoryArrayLink->MemorySpeed;
673 }
674 switch (DataHeader->SubInstance) {
675 case 1:
676 mMemorySpeedChannelASlot0 = MemoryArrayLink->MemorySpeed;
677 mMemorySizeChannelASlot0 = MemoryArrayLink->MemoryDeviceSize;
678 break;
679 case 2:
680 mMemorySpeedChannelASlot1 = MemoryArrayLink->MemorySpeed;
681 mMemorySizeChannelASlot1 = MemoryArrayLink->MemoryDeviceSize;
682 break;
683 case 3:
684 mMemorySpeedChannelBSlot0 = MemoryArrayLink->MemorySpeed;
685 mMemorySizeChannelBSlot0 = MemoryArrayLink->MemoryDeviceSize;
686 break;
687 case 4:
688 mMemorySpeedChannelBSlot1 = MemoryArrayLink->MemorySpeed;
689 mMemorySizeChannelBSlot1 = MemoryArrayLink->MemoryDeviceSize;
690 break;
691 case 5:
692 mMemorySpeedChannelCSlot0 = MemoryArrayLink->MemorySpeed;
693 mMemorySizeChannelCSlot0 = MemoryArrayLink->MemoryDeviceSize;
694 break;
695 case 6:
696 mMemorySpeedChannelCSlot1 = MemoryArrayLink->MemorySpeed;
697 mMemorySizeChannelCSlot1 = MemoryArrayLink->MemoryDeviceSize;
698 break;
699 default:
700 break;
701 }
702 }
703 break;
704
705 case EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER:
706 MemoryArray = (EFI_MEMORY_ARRAY_START_ADDRESS *)SrcData;
707 if (MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress) {
708 DataOutput = (UINTN)RShiftU64((MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress + 1), 20);
709 EfiValueToString (NewString, DataOutput / 1024, PREFIX_ZERO, 0);
710 if(DataOutput % 1024) {
711 StrCat (NewString, L".");
712 DataOutput = ((DataOutput % 1024) * 1000) / 1024;
713 while(!(DataOutput % 10))
714 DataOutput = DataOutput / 10;
715 EfiValueToString (NewString2, DataOutput, PREFIX_ZERO, 0);
716 StrCat (NewString, NewString2);
717 }
718 StrCat (NewString, L" GB");
719 TokenToUpdate = (STRING_REF)STR_TOTAL_MEMORY_SIZE_VALUE;
720 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
721 }
722 break;
723
724 default:
725 break;
726 }
727 }
728 }
729 }
730 } while (!EFI_ERROR(Status) && (MonotonicCount != 0));
731
732 Status = GetBiosVersionDateTime (
733 Version,
734 ReleaseDate,
735 ReleaseTime
736 );
737
738 DEBUG ((EFI_D_ERROR, "GetBiosVersionDateTime :%s %s %s \n", Version, ReleaseDate, ReleaseTime));
739 if (!EFI_ERROR (Status)) {
740 UINTN Length = 0;
741 CHAR16 *BuildDateTime;
742
743 Length = StrLen(ReleaseDate) + StrLen(ReleaseTime);
744
745 BuildDateTime = AllocateZeroPool ((Length+2) * sizeof(CHAR16));
746 StrCpy (BuildDateTime, ReleaseDate);
747 StrCat (BuildDateTime, L" ");
748 StrCat (BuildDateTime, ReleaseTime);
749
750 TokenToUpdate = (STRING_REF)STR_BIOS_VERSION_VALUE;
751 DEBUG ((EFI_D_ERROR, "update STR_BIOS_VERSION_VALUE\n"));
752 HiiSetString(mHiiHandle, TokenToUpdate, Version, NULL);
753
754 TokenToUpdate = (STRING_REF)STR_BIOS_BUILD_TIME_VALUE;
755 DEBUG ((EFI_D_ERROR, "update STR_BIOS_BUILD_TIME_VALUE\n"));
756 HiiSetString(mHiiHandle, TokenToUpdate, BuildDateTime, NULL);
757 }
758
759 //
760 // Calculate and update memory speed display in Main Page
761 //
762 //
763 // Update the overall memory speed
764 //
765 if (mMemorySpeed != 0xffff) {
766 EfiValueToString (NewString, mMemorySpeed, PREFIX_ZERO, 0);
767 StrCat (NewString, L" MHz");
768
769 TokenToUpdate = (STRING_REF)STR_SYSTEM_MEMORY_SPEED_VALUE;
770 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
771 }
772
773 gBS->FreePool(NewString);
774 gBS->FreePool(NewString2);
775
776 return;
777 }
778
779 /**
780
781 Routine Description: update the SETUP info for "Additional Information" which is SMBIOS info.
782
783 @retval EFI_STATUS
784
785 **/
786 EFI_STATUS
787 UpdateAdditionalInformation (
788 )
789 {
790 EFI_STATUS Status;
791 UINT64 MonotonicCount;
792 EFI_DATA_HUB_PROTOCOL *DataHub;
793 EFI_DATA_RECORD_HEADER *Record;
794 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
795 EFI_SMBIOS_PROTOCOL *Smbios;
796 EFI_SMBIOS_HANDLE SmbiosHandle;
797 EFI_SMBIOS_TABLE_HEADER *SmbiosRecord;
798 SMBIOS_TABLE_TYPE0 *Type0Record;
799 UINT8 StrIndex;
800 CHAR16 *BiosVersion = NULL;
801 CHAR16 *IfwiVersion = NULL;
802 UINT16 SearchIndex;
803 EFI_STRING_ID TokenToUpdate;
804 #if defined( RVP_SUPPORT ) && RVP_SUPPORT
805 EFI_MISC_SYSTEM_MANUFACTURER *SystemManufacturer;
806 #endif
807
808 Status = gBS->LocateProtocol (
809 &gEfiDataHubProtocolGuid,
810 NULL,
811 (void **)&DataHub
812 );
813
814 ASSERT_EFI_ERROR(Status);
815
816 MonotonicCount = 0;
817 Record = NULL;
818 do {
819 Status = DataHub->GetNextRecord (
820 DataHub,
821 &MonotonicCount,
822 NULL,
823 &Record
824 );
825 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
826 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
827
828 if (CompareGuid(&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
829 (DataHeader->RecordType == EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER)) {
830 #if defined( RVP_SUPPORT ) && RVP_SUPPORT
831 //
832 // System Information
833 //
834 SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER *)(DataHeader + 1);
835
836 //
837 // UUID (System Information)
838 //
839 SMBIOSString = EfiLibAllocateZeroPool (0x100);
840 GuidToString ( &SystemManufacturer->SystemUuid, SMBIOSString, 0x00 );
841
842 TokenToUpdate = (STRING_REF)STR_SYSTEM_UUID_VALUE;
843 HiiSetString(mHiiHandle, TokenToUpdate, SMBIOSString, NULL);
844
845 gBS->FreePool(SMBIOSString);
846 #endif
847 }
848 }
849 } while (!EFI_ERROR(Status) && (MonotonicCount != 0));
850
851 Status = gBS->LocateProtocol (
852 &gEfiSmbiosProtocolGuid,
853 NULL,
854 (VOID **) &Smbios
855 );
856 ASSERT_EFI_ERROR (Status);
857
858 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
859 do {
860 Status = Smbios->GetNext (
861 Smbios,
862 &SmbiosHandle,
863 NULL,
864 &SmbiosRecord,
865 NULL
866 );
867 if (SmbiosRecord->Type == EFI_SMBIOS_TYPE_BIOS_INFORMATION) {
868 Type0Record = (SMBIOS_TABLE_TYPE0 *) SmbiosRecord;
869 StrIndex = Type0Record->BiosVersion;
870 GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type0Record + Type0Record->Hdr.Length), StrIndex, &BiosVersion);
871 TokenToUpdate = STRING_TOKEN (STR_BIOS_VERSION_VALUE);
872 for (SearchIndex = 0x0; SearchIndex < SMBIOS_STRING_MAX_LENGTH; SearchIndex++) {
873 if (BiosVersion[SearchIndex] == 0x0020) {
874 BiosVersion[SearchIndex] = 0x0000;
875 IfwiVersion = (CHAR16 *)(&BiosVersion[SearchIndex+1]);
876 break;
877 } else if (BiosVersion[SearchIndex] == 0x0000) {
878 break;
879 }
880 }
881 HiiSetString (mHiiHandle, TokenToUpdate, BiosVersion, NULL);
882
883 //
884 // Check IfwiVersion, to avoid no IFWI version in SMBIOS Type 0 strucntion
885 //
886 if(IfwiVersion) {
887 TokenToUpdate = STRING_TOKEN (STR_IFWI_VERSION_VALUE);
888 HiiSetString (mHiiHandle, TokenToUpdate, IfwiVersion, NULL);
889 }
890 }
891 } while (!EFI_ERROR(Status));
892
893 UpdateLatestBootTime();
894
895 return EFI_SUCCESS;
896 }
897
898 VOID
899 UpdateCPUInformation ()
900 {
901 CHAR16 Buffer[40];
902 UINT16 FamilyId;
903 UINT8 Model;
904 UINT8 SteppingId;
905 UINT8 ProcessorType;
906 EFI_STATUS Status;
907 EFI_MP_SERVICES_PROTOCOL *MpService;
908 UINTN MaximumNumberOfCPUs;
909 UINTN NumberOfEnabledCPUs;
910 UINT32 Buffer32 = 0xFFFFFFFF; // Keep buffer with unknown device
911
912 EfiCpuVersion (&FamilyId, &Model, &SteppingId, &ProcessorType);
913
914 //
915 //we need raw Model data
916 //
917 Model = Model & 0xf;
918
919 //
920 //Family/Model/Step
921 //
922 UnicodeSPrint (Buffer, sizeof (Buffer), L"%d/%d/%d", FamilyId, Model, SteppingId);
923 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_ID_VALUE), Buffer, NULL);
924
925 Status = gBS->LocateProtocol (
926 &gEfiMpServiceProtocolGuid,
927 NULL,
928 (void **)&MpService
929 );
930 if (!EFI_ERROR (Status)) {
931 //
932 // Determine the number of processors
933 //
934 MpService->GetNumberOfProcessors (
935 MpService,
936 &MaximumNumberOfCPUs,
937 &NumberOfEnabledCPUs
938 );
939 UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", MaximumNumberOfCPUs);
940 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_CORE_VALUE), Buffer, NULL);
941 }
942 //
943 // Update Mobile / Desktop / Tablet SKU
944 //
945 Buffer32 =(UINT32) RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
946
947 switch(Buffer32){
948 case 0x0:
949 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - ISG SKU SOC", Buffer32);
950 break;
951 case 0x01:
952 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
953 break;
954 case 0x02:
955 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Desktop SKU SOC", Buffer32);
956 break;
957 case 0x03:
958 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
959 break;
960 default:
961 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Unknown SKU SOC", Buffer32);
962 break;
963 }
964 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_SKU_VALUE), Buffer, NULL);
965
966 }
967
968
969 EFI_STATUS
970 SearchChildHandle(
971 EFI_HANDLE Father,
972 EFI_HANDLE *Child
973 )
974 {
975 EFI_STATUS Status;
976 UINTN HandleIndex;
977 EFI_GUID **ProtocolGuidArray = NULL;
978 UINTN ArrayCount;
979 UINTN ProtocolIndex;
980 UINTN OpenInfoCount;
981 UINTN OpenInfoIndex;
982 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo = NULL;
983 UINTN mHandleCount;
984 EFI_HANDLE *mHandleBuffer= NULL;
985
986 //
987 // Retrieve the list of all handles from the handle database
988 //
989 Status = gBS->LocateHandleBuffer (
990 AllHandles,
991 NULL,
992 NULL,
993 &mHandleCount,
994 &mHandleBuffer
995 );
996
997 for (HandleIndex = 0; HandleIndex < mHandleCount; HandleIndex++)
998 {
999 //
1000 // Retrieve the list of all the protocols on each handle
1001 //
1002 Status = gBS->ProtocolsPerHandle (
1003 mHandleBuffer[HandleIndex],
1004 &ProtocolGuidArray,
1005 &ArrayCount
1006 );
1007 if (!EFI_ERROR (Status))
1008 {
1009 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++)
1010 {
1011 Status = gBS->OpenProtocolInformation (
1012 mHandleBuffer[HandleIndex],
1013 ProtocolGuidArray[ProtocolIndex],
1014 &OpenInfo,
1015 &OpenInfoCount
1016 );
1017 if (!EFI_ERROR (Status))
1018 {
1019 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++)
1020 {
1021 if(OpenInfo[OpenInfoIndex].AgentHandle == Father)
1022 {
1023 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER)
1024 {
1025 *Child = mHandleBuffer[HandleIndex];
1026 Status = EFI_SUCCESS;
1027 goto TryReturn;
1028 }
1029 }
1030 }
1031 Status = EFI_NOT_FOUND;
1032 }
1033 }
1034 if(OpenInfo != NULL)
1035 {
1036 FreePool(OpenInfo);
1037 OpenInfo = NULL;
1038 }
1039 }
1040 FreePool (ProtocolGuidArray);
1041 ProtocolGuidArray = NULL;
1042 }
1043 TryReturn:
1044 if(OpenInfo != NULL)
1045 {
1046 FreePool (OpenInfo);
1047 OpenInfo = NULL;
1048 }
1049 if(ProtocolGuidArray != NULL)
1050 {
1051 FreePool(ProtocolGuidArray);
1052 ProtocolGuidArray = NULL;
1053 }
1054 if(mHandleBuffer != NULL)
1055 {
1056 FreePool (mHandleBuffer);
1057 mHandleBuffer = NULL;
1058 }
1059 return Status;
1060 }
1061
1062 EFI_STATUS
1063 JudgeHandleIsPCIDevice(
1064 EFI_HANDLE Handle,
1065 UINT8 Device,
1066 UINT8 Funs
1067 )
1068 {
1069 EFI_STATUS Status;
1070 EFI_DEVICE_PATH *DPath;
1071
1072 Status = gBS->HandleProtocol (
1073 Handle,
1074 &gEfiDevicePathProtocolGuid,
1075 (VOID **) &DPath
1076 );
1077 if(!EFI_ERROR(Status))
1078 {
1079 while(!IsDevicePathEnd(DPath))
1080 {
1081 if((DPath->Type == HARDWARE_DEVICE_PATH) && (DPath->SubType == HW_PCI_DP))
1082 {
1083 PCI_DEVICE_PATH *PCIPath;
1084
1085 PCIPath = (PCI_DEVICE_PATH*) DPath;
1086 DPath = NextDevicePathNode(DPath);
1087 if(IsDevicePathEnd(DPath) && (PCIPath->Device == Device) && (PCIPath->Function == Funs))
1088 {
1089 return EFI_SUCCESS;
1090 }
1091 }
1092 else
1093 {
1094 DPath = NextDevicePathNode(DPath);
1095 }
1096 }
1097 }
1098 return EFI_UNSUPPORTED;
1099 }
1100
1101 EFI_STATUS
1102 GetDriverName(
1103 EFI_HANDLE Handle,
1104 CHAR16 *Name
1105 )
1106 {
1107 EFI_DRIVER_BINDING_PROTOCOL *BindHandle = NULL;
1108 EFI_STATUS Status;
1109 UINT32 Version;
1110 UINT16 *Ptr;
1111 Status = gBS->OpenProtocol(
1112 Handle,
1113 &gEfiDriverBindingProtocolGuid,
1114 (VOID**)&BindHandle,
1115 NULL,
1116 NULL,
1117 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1118 );
1119
1120 if (EFI_ERROR(Status))
1121 {
1122 return EFI_NOT_FOUND;
1123 }
1124
1125 Version = BindHandle->Version;
1126 Ptr = (UINT16*)&Version;
1127 UnicodeSPrint(Name, 40, L"%d.%d.%d", Version >> 24 , (Version >>16)& 0x0f ,*(Ptr));
1128
1129 return EFI_SUCCESS;
1130 }
1131
1132 EFI_STATUS
1133 GetGOPDriverName(
1134 CHAR16 *Name
1135 )
1136 {
1137 UINTN HandleCount;
1138 EFI_HANDLE *Handles= NULL;
1139 UINTN Index;
1140 EFI_STATUS Status;
1141 EFI_HANDLE Child = 0;
1142
1143 Status = gBS->LocateHandleBuffer(
1144 ByProtocol,
1145 &gEfiDriverBindingProtocolGuid,
1146 NULL,
1147 &HandleCount,
1148 &Handles
1149 );
1150 for (Index = 0; Index < HandleCount ; Index++)
1151 {
1152 Status = SearchChildHandle(Handles[Index], &Child);
1153 if(!EFI_ERROR(Status))
1154 {
1155 Status = JudgeHandleIsPCIDevice(
1156 Child,
1157 0x02,
1158 0x00
1159 );
1160 if(!EFI_ERROR(Status))
1161 {
1162 return GetDriverName(Handles[Index], Name);
1163 }
1164 }
1165 }
1166 return EFI_UNSUPPORTED;
1167 }
1168
1169 EFI_STATUS
1170 UpdatePlatformInformation (
1171 )
1172 {
1173 UINT32 MicroCodeVersion;
1174 CHAR16 Buffer[40];
1175 UINT8 IgdVBIOSRevH;
1176 UINT8 IgdVBIOSRevL;
1177 UINT16 EDX;
1178 EFI_IA32_REGISTER_SET RegSet;
1179 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios = NULL;
1180 EFI_STATUS Status;
1181 UINT8 CpuFlavor=0;
1182 EFI_PEI_HOB_POINTERS GuidHob;
1183 UINTN NumHandles;
1184 EFI_HANDLE *HandleBuffer;
1185 UINTN Index;
1186 DXE_PCH_PLATFORM_POLICY_PROTOCOL *PchPlatformPolicy;
1187 UINTN PciD31F0RegBase;
1188 UINT8 count;
1189 UINT8 Data8;
1190 UINT8 PIDData8;
1191
1192 CHAR16 Name[40];
1193 UINT32 MrcVersion;
1194
1195 //
1196 // Get the HOB list. If it is not present, then ASSERT.
1197 //
1198 GuidHob.Raw = GetHobList ();
1199 if (GuidHob.Raw != NULL) {
1200 if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
1201 mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
1202 }
1203 }
1204
1205 //
1206 //VBIOS version
1207 //
1208 Status = gBS->LocateProtocol(
1209 &gEfiLegacyBiosProtocolGuid,
1210 NULL,
1211 (void **)&LegacyBios
1212 );
1213 if (!EFI_ERROR (Status)) {
1214 RegSet.X.AX = 0x5f01;
1215 Status = LegacyBios->Int86 (LegacyBios, 0x10, &RegSet);
1216 ASSERT_EFI_ERROR(Status);
1217
1218 //
1219 // simulate AMI int15 (ax=5f01) handler
1220 // check NbInt15.asm in AMI code for asm edition
1221 //
1222 EDX = (UINT16)((RegSet.E.EBX >> 16) & 0xffff);
1223 IgdVBIOSRevH = (UINT8)(((EDX & 0x0F00) >> 4) | (EDX & 0x000F));
1224 IgdVBIOSRevL = (UINT8)(((RegSet.X.BX & 0x0F00) >> 4) | (RegSet.X.BX & 0x000F));
1225
1226 if (IgdVBIOSRevH==0 && IgdVBIOSRevL==0){
1227 HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), L"N/A", NULL);
1228 } else {
1229 UnicodeSPrint (Buffer, sizeof (Buffer), L"%02X%02X", IgdVBIOSRevH,IgdVBIOSRevL);
1230 HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), Buffer, NULL);
1231 }
1232 }
1233
1234 Status = GetGOPDriverName(Name);
1235
1236 if (!EFI_ERROR(Status))
1237 {
1238 HiiSetString(mHiiHandle, STRING_TOKEN(STR_GOP_VALUE), Name, NULL);
1239 }
1240
1241
1242 //
1243 // CpuFlavor
1244 // ISG-DC Tablet 000
1245 // VLV-QC Tablet 001
1246 // VLV-QC Desktop 010
1247 // VLV-QC Notebook 011
1248 //
1249 CpuFlavor = RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
1250
1251 switch(CpuFlavor){
1252 case 0x0:
1253 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-DC Tablet", CpuFlavor);
1254 break;
1255 case 0x01:
1256 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
1257 break;
1258 case 0x02:
1259 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Desktop", CpuFlavor);
1260 break;
1261 case 0x03:
1262 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
1263 break;
1264 default:
1265 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"Unknown CPU", CpuFlavor);
1266 break;
1267 }
1268 HiiSetString(mHiiHandle,STRING_TOKEN(STR_CPU_FLAVOR_VALUE), Buffer, NULL);
1269
1270 if ( NULL != mPlatformInfo) {
1271 //
1272 //BoardId
1273 //
1274 switch(mPlatformInfo->BoardId){
1275 case 0x2:
1276 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE RVP(%02x)", mPlatformInfo->BoardId);
1277 break;
1278
1279 case 0x4:
1280 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFRD(%02x)", mPlatformInfo->BoardId);
1281 break;
1282
1283 case 0x5:
1284 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY ROCK RVP DDR3L (%02x)", mPlatformInfo->BoardId);
1285 break;
1286
1287 case 0x20:
1288 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAYLEY BAY (%02x)", mPlatformInfo->BoardId);
1289 break;
1290
1291 case 0x30:
1292 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAKER SPORT (%02x)", mPlatformInfo->BoardId);
1293 break;
1294
1295 case 0x0:
1296 UnicodeSPrint (Buffer, sizeof (Buffer), L"ALPINE VALLEY (%x)", mPlatformInfo->BoardId);
1297 break;
1298
1299 case 0x3:
1300 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFD8 (%x)", mPlatformInfo->BoardId);
1301 break;
1302
1303 default:
1304 UnicodeSPrint (Buffer, sizeof (Buffer), L"Unknown BOARD (%02x)", mPlatformInfo->BoardId);
1305 break;
1306 }
1307 HiiSetString(mHiiHandle,STRING_TOKEN(STR_BOARD_ID_VALUE), Buffer, NULL);
1308
1309
1310 //
1311 // Get Board FAB ID Info from protocol, update into the NVS area.
1312 // bit0~bit3 are for Fab ID, 0x0F means unknow FAB.
1313 //
1314 if(mPlatformInfo->BoardRev == 0x0F) {
1315 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", L"Unknown FAB");
1316 HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
1317 } else {
1318 UnicodeSPrint (Buffer, sizeof (Buffer), L"%2x", mPlatformInfo->BoardRev);
1319 HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
1320 }
1321 }
1322
1323 //
1324 //Update MRC Version
1325 //
1326 MrcVersion = 0x00000000;
1327 MrcVersion &= 0xffff;
1328 Index = EfiValueToString (Buffer, MrcVersion/100, PREFIX_ZERO, 0);
1329 StrCat (Buffer, L".");
1330 EfiValueToString (Buffer + Index + 1, (MrcVersion%100)/10, PREFIX_ZERO, 0);
1331 EfiValueToString (Buffer + Index + 2, (MrcVersion%100)%10, PREFIX_ZERO, 0);
1332 HiiSetString(mHiiHandle,STRING_TOKEN(STR_MRC_VERSION_VALUE), Buffer, NULL);
1333
1334 //
1335 //Update Soc Version
1336 //
1337
1338 //
1339 // Retrieve all instances of PCH Platform Policy protocol
1340 //
1341 Status = gBS->LocateHandleBuffer (
1342 ByProtocol,
1343 &gDxePchPlatformPolicyProtocolGuid,
1344 NULL,
1345 &NumHandles,
1346 &HandleBuffer
1347 );
1348 if (!EFI_ERROR (Status)) {
1349 //
1350 // Find the matching PCH Policy protocol
1351 //
1352 for (Index = 0; Index < NumHandles; Index++) {
1353 Status = gBS->HandleProtocol (
1354 HandleBuffer[Index],
1355 &gDxePchPlatformPolicyProtocolGuid,
1356 (void **)&PchPlatformPolicy
1357 );
1358 if (!EFI_ERROR (Status)) {
1359 PciD31F0RegBase = MmPciAddress (
1360 0,
1361 PchPlatformPolicy->BusNumber,
1362 PCI_DEVICE_NUMBER_PCH_LPC,
1363 PCI_FUNCTION_NUMBER_PCH_LPC,
1364 0
1365 );
1366
1367 Data8 = MmioRead8 (PciD31F0RegBase + R_PCH_LPC_RID_CC);
1368 count = ARRAY_SIZE (SBRevisionTable);
1369 for (Index = 0; Index < count; Index++) {
1370 if(Data8 == SBRevisionTable[Index].RevId) {
1371 UnicodeSPrint (Buffer, sizeof (Buffer), L"%02x %a", Data8, SBRevisionTable[Index].String);
1372 HiiSetString(mHiiHandle,STRING_TOKEN(STR_SOC_VALUE), Buffer, NULL);
1373 break;
1374 }
1375 }
1376 break;
1377 }
1378 }
1379 }
1380
1381 //
1382 // Microcode Revision
1383 //
1384 EfiWriteMsr (EFI_MSR_IA32_BIOS_SIGN_ID, 0);
1385 EfiCpuid (EFI_CPUID_VERSION_INFO, NULL);
1386 MicroCodeVersion = (UINT32) RShiftU64 (EfiReadMsr (EFI_MSR_IA32_BIOS_SIGN_ID), 32);
1387 UnicodeSPrint (Buffer, sizeof (Buffer), L"%x", MicroCodeVersion);
1388 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_MICROCODE_VALUE), Buffer, NULL);
1389
1390 //
1391 // Punit Version
1392 //
1393 Data8 = 0;
1394 UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%x", Data8);
1395 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PUNIT_FW_VALUE), Buffer, NULL);
1396
1397 //
1398 // PMC Version
1399 //
1400 Data8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>16)&0x00FF);
1401 PIDData8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>24)&0x00FF);
1402 UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%X_%X",PIDData8, Data8);
1403 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PMC_FW_VALUE), Buffer, NULL);
1404
1405 return EFI_SUCCESS;
1406 }
1407
1408 /**
1409
1410 Update SATA Drivesize Strings for Setup and Boot order
1411
1412 @param NewString - pointer to string.
1413 @param DeviceSpeed - speed of drive.
1414
1415 **/
1416 VOID
1417 GetDeviceSpeedString (
1418 CHAR16 *NewString,
1419 IN UINTN DeviceSpeed
1420 )
1421 {
1422 if (DeviceSpeed == 0x01) {
1423 StrCat (NewString, L"1.5Gb/s");
1424 } else if (DeviceSpeed == 0x02) {
1425 StrCat (NewString, L"3.0Gb/s");
1426 } else if (DeviceSpeed == 0x03) {
1427 StrCat (NewString, L"6.0Gb/s");
1428 } else if (DeviceSpeed == 0x0) {
1429
1430 }
1431 }
1432
1433 UINT8
1434 GetChipsetSataPortSpeed (
1435 UINTN PortNum
1436 )
1437 {
1438 UINT32 DeviceSpeed;
1439 UINT8 DeviceConfigStatus;
1440 UINT32 IdeAhciBar;
1441 EFI_PHYSICAL_ADDRESS MemBaseAddress = 0;
1442 UINT8 FunNum;
1443
1444 DeviceSpeed = 0x01; // generation 1
1445
1446
1447 //
1448 // Allocate the AHCI BAR
1449 //
1450 FunNum = PCI_FUNCTION_NUMBER_PCH_SATA;
1451 MemBaseAddress = 0x0ffffffff;
1452 gDS->AllocateMemorySpace (
1453 EfiGcdAllocateMaxAddressSearchBottomUp,
1454 EfiGcdMemoryTypeMemoryMappedIo,
1455 N_PCH_SATA_ABAR_ALIGNMENT, // 2^11: 2K Alignment
1456 V_PCH_SATA_ABAR_LENGTH, // 2K Length
1457 &MemBaseAddress,
1458 mImageHandle,
1459 NULL
1460 );
1461 IdeAhciBar = MmioRead32 (
1462 MmPciAddress (
1463 0,
1464 0,
1465 PCI_DEVICE_NUMBER_PCH_SATA,
1466 FunNum,
1467 R_PCH_SATA_ABAR
1468 )
1469 );
1470 IdeAhciBar &= 0xFFFFF800;
1471 DeviceConfigStatus = 0;
1472 if (IdeAhciBar == 0) {
1473 DeviceConfigStatus = 1;
1474 IdeAhciBar = (UINT32)MemBaseAddress;
1475 MmioWrite32 (
1476 MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
1477 IdeAhciBar
1478 );
1479 MmioOr16 (
1480 MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_COMMAND),
1481 B_PCH_SATA_COMMAND_MSE
1482 );
1483 }
1484
1485 if (mSystemConfiguration.SataType == PCH_SATA_MODE_IDE){
1486 //
1487 // Program the "Ports Implemented Register"
1488 //
1489 MmioAndThenOr32 (IdeAhciBar + R_PCH_SATA_AHCI_PI, (UINT32)~(B_PCH_SATA_PORT0_IMPLEMENTED + B_PCH_SATA_PORT1_IMPLEMENTED), (UINT32)(B_PCH_SATA_PORT0_IMPLEMENTED + B_PCH_SATA_PORT1_IMPLEMENTED));
1490 }
1491
1492 switch (PortNum)
1493 {
1494 case 0:
1495 DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P0SSTS);
1496 break;
1497 case 1:
1498 DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P1SSTS);
1499 break;
1500 }
1501
1502 if (MemBaseAddress) {
1503 gDS->FreeMemorySpace (
1504 MemBaseAddress,
1505 V_PCH_SATA_ABAR_LENGTH
1506 );
1507 }
1508
1509 if (DeviceConfigStatus) {
1510 IdeAhciBar = 0;
1511 MmioWrite32 (
1512 MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
1513 IdeAhciBar
1514 );
1515 }
1516
1517 DeviceSpeed = (UINT8)((DeviceSpeed >> 4) & 0x0F);
1518
1519 return (UINT8)DeviceSpeed;
1520 }
1521
1522 /**
1523
1524 IDE data filter function.
1525
1526 **/
1527 void
1528 IdeDataFilter (void)
1529 {
1530 EFI_STATUS Status;
1531 UINTN HandleCount;
1532 EFI_HANDLE *HandleBuffer;
1533 EFI_DISK_INFO_PROTOCOL *DiskInfo;
1534 EFI_DEVICE_PATH_PROTOCOL *DevicePath, *DevicePathNode;
1535 PCI_DEVICE_PATH *PciDevicePath;
1536 UINTN Index;
1537 UINT8 Index1;
1538 UINT32 BufferSize;
1539 UINT32 DriveSize;
1540 UINT32 IdeChannel;
1541 UINT32 IdeDevice;
1542 EFI_ATA_IDENTIFY_DATA *IdentifyDriveInfo;
1543 CHAR16 *NewString;
1544 CHAR16 SizeString[20];
1545 STRING_REF NameToUpdate;
1546 CHAR8 StringBuffer[0x100];
1547 UINT32 DeviceSpeed;
1548 UINTN PortNumber;
1549
1550 //
1551 // Assume no line strings is longer than 256 bytes.
1552 //
1553 NewString = AllocateZeroPool (0x100);
1554 PciDevicePath = NULL;
1555
1556 //
1557 // Fill IDE Infomation
1558 //
1559 Status = gBS->LocateHandleBuffer (
1560 ByProtocol,
1561 &gEfiDiskInfoProtocolGuid,
1562 NULL,
1563 &HandleCount,
1564 &HandleBuffer
1565 );
1566
1567 if (EFI_ERROR (Status)) {
1568 return;
1569 }
1570
1571 for (Index = 0; Index < HandleCount; Index++) {
1572
1573 Status = gBS->HandleProtocol (
1574 HandleBuffer[Index],
1575 &gEfiDevicePathProtocolGuid,
1576 (VOID*)&DevicePath
1577 );
1578 ASSERT_EFI_ERROR (Status);
1579
1580 DevicePathNode = DevicePath;
1581 while (!IsDevicePathEnd (DevicePathNode) ) {
1582 if ((DevicePathType (DevicePathNode) == HARDWARE_DEVICE_PATH) &&
1583 ( DevicePathSubType (DevicePathNode) == HW_PCI_DP)) {
1584 PciDevicePath = (PCI_DEVICE_PATH *) DevicePathNode;
1585 break;
1586 }
1587 DevicePathNode = NextDevicePathNode (DevicePathNode);
1588 }
1589
1590 if (PciDevicePath == NULL) {
1591 continue;
1592 }
1593
1594 //
1595 // Check for onboard IDE
1596 //
1597 if (PciDevicePath->Device== PCI_DEVICE_NUMBER_PCH_SATA) {
1598 Status = gBS->HandleProtocol (
1599 HandleBuffer[Index],
1600 &gEfiDiskInfoProtocolGuid,
1601 (void **)&DiskInfo
1602 );
1603 ASSERT_EFI_ERROR (Status);
1604
1605 Status = DiskInfo->WhichIde (
1606 DiskInfo,
1607 &IdeChannel,
1608 &IdeDevice
1609 );
1610 ASSERT_EFI_ERROR (Status);
1611
1612 IdentifyDriveInfo = AllocatePool (sizeof(EFI_ATA_IDENTIFY_DATA));
1613
1614 BufferSize = sizeof(EFI_ATA_IDENTIFY_DATA);
1615 Status = DiskInfo->Identify (
1616 DiskInfo,
1617 IdentifyDriveInfo,
1618 &BufferSize
1619 );
1620 ASSERT_EFI_ERROR(Status);
1621
1622 //
1623 // Onboard SATA Devices
1624 //
1625 if (PciDevicePath->Function == PCI_FUNCTION_NUMBER_PCH_SATA) {
1626 if (IdeChannel == 0 && IdeDevice == 0) {
1627 NameToUpdate = (STRING_REF)STR_SATA0_NAME;
1628 } else if (IdeChannel == 1 && IdeDevice == 0) {
1629 NameToUpdate = (STRING_REF)STR_SATA1_NAME;
1630 } else {
1631 continue;
1632 }
1633 } else {
1634 continue;
1635 }
1636
1637 ZeroMem(StringBuffer, sizeof(StringBuffer));
1638 CopyMem(
1639 StringBuffer,
1640 (CHAR8 *)&IdentifyDriveInfo->ModelName,
1641 sizeof(IdentifyDriveInfo->ModelName)
1642 );
1643 SwapEntries(StringBuffer);
1644 AsciiToUnicode(StringBuffer, NewString);
1645
1646 //
1647 // Chap it off after 16 characters
1648 //
1649 NewString[16] = 0;
1650
1651 //
1652 // For HardDisk append the size. Otherwise display atapi
1653 //
1654 if ((IdentifyDriveInfo->config & 0x8000) == 00) {
1655 //
1656 // 48 bit address feature set is supported, get maximum capacity
1657 //
1658 if ((IdentifyDriveInfo->command_set_supported_83 & 0x0400) == 0) {
1659 DriveSize = (((((IdentifyDriveInfo->user_addressable_sectors_hi << 16) +
1660 IdentifyDriveInfo->user_addressable_sectors_lo) / 1000) * 512) / 1000);
1661 } else {
1662 DriveSize = IdentifyDriveInfo->maximum_lba_for_48bit_addressing[0];
1663 for (Index1 = 1; Index1 < 4; Index1++) {
1664 //
1665 // Lower byte goes first: word[100] is the lowest word, word[103] is highest
1666 //
1667 DriveSize |= LShiftU64(IdentifyDriveInfo->maximum_lba_for_48bit_addressing[Index1], 16 * Index1);
1668 }
1669 DriveSize = (UINT32) DivU64x32(MultU64x32(DivU64x32(DriveSize, 1000), 512), 1000);
1670 }
1671
1672 StrCat (NewString, L"(");
1673 EfiValueToString (SizeString, DriveSize/1000, PREFIX_BLANK, 0);
1674 StrCat (NewString, SizeString);
1675 StrCat (NewString, L".");
1676 EfiValueToString (SizeString, (DriveSize%1000)/100, PREFIX_BLANK, 0);
1677 StrCat (NewString, SizeString);
1678 StrCat (NewString, L"GB");
1679 } else {
1680 StrCat (NewString, L"(ATAPI");
1681 }
1682
1683 //
1684 // Update SPEED.
1685 //
1686 PortNumber = (IdeDevice << 1) + IdeChannel;
1687 DeviceSpeed = GetChipsetSataPortSpeed(PortNumber);
1688
1689 if (DeviceSpeed) {
1690 StrCat (NewString, L"-");
1691 GetDeviceSpeedString( NewString, DeviceSpeed);
1692 }
1693
1694 StrCat (NewString, L")");
1695
1696 HiiSetString(mHiiHandle, NameToUpdate, NewString, NULL);
1697
1698 }
1699 }
1700
1701 if (HandleBuffer != NULL) {
1702 gBS->FreePool (HandleBuffer);
1703 }
1704
1705 gBS->FreePool(NewString);
1706
1707 return;
1708 }
1709
1710
1711 VOID
1712 EFIAPI
1713 SetupInfo (void)
1714 {
1715 EFI_STATUS Status;
1716 UINTN VarSize;
1717 EFI_PEI_HOB_POINTERS GuidHob;
1718
1719 if (mSetupInfoDone) {
1720 return;
1721 }
1722
1723 VarSize = sizeof(SYSTEM_CONFIGURATION);
1724 Status = gRT->GetVariable(
1725 NORMAL_SETUP_NAME,
1726 &gEfiNormalSetupGuid,
1727 NULL,
1728 &VarSize,
1729 &mSystemConfiguration
1730 );
1731
1732 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
1733 //The setup variable is corrupted
1734 VarSize = sizeof(SYSTEM_CONFIGURATION);
1735 Status = gRT->GetVariable(
1736 L"SetupRecovery",
1737 &gEfiNormalSetupGuid,
1738 NULL,
1739 &VarSize,
1740 &mSystemConfiguration
1741 );
1742 ASSERT_EFI_ERROR (Status);
1743 }
1744
1745 //
1746 // Update HOB variable for PCI resource information
1747 // Get the HOB list. If it is not present, then ASSERT.
1748 //
1749 GuidHob.Raw = GetHobList ();
1750 if (GuidHob.Raw != NULL) {
1751 if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
1752 mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
1753 }
1754 }
1755
1756
1757 PrepareSetupInformation();
1758 UpdateAdditionalInformation ();
1759 UpdatePlatformInformation();
1760 UpdateCPUInformation();
1761 IdeDataFilter();
1762 mSetupInfoDone = TRUE;
1763
1764 return;
1765 }
1766
1767
1768 #define EFI_SECURE_BOOT_MODE_NAME L"SecureBoot"
1769
1770 VOID
1771 CheckSystemConfigLoad(SYSTEM_CONFIGURATION *SystemConfigPtr)
1772 {
1773 EFI_STATUS Status;
1774 UINT8 SecureBoot;
1775 UINTN DataSize;
1776
1777
1778 DataSize = sizeof(SecureBoot);
1779 Status = gRT->GetVariable (
1780 EFI_SECURE_BOOT_MODE_NAME,
1781 &gEfiGlobalVariableGuid,
1782 NULL,
1783 &DataSize,
1784 &SecureBoot
1785 );
1786
1787 if (EFI_ERROR(Status)) {
1788 SystemConfigPtr->SecureBoot = 0;
1789 } else {
1790 SystemConfigPtr->SecureBoot = SecureBoot;
1791 }
1792 }
1793
1794
1795 //
1796 // "SecureBootEnable" variable for the Secure boot feature enable/disable.
1797 //
1798 #define EFI_SECURE_BOOT_ENABLE_NAME L"SecureBootEnable"
1799 extern EFI_GUID gEfiSecureBootEnableDisableGuid;
1800
1801
1802 VOID
1803 CheckSystemConfigSave(SYSTEM_CONFIGURATION *SystemConfigPtr)
1804 {
1805 EFI_STATUS Status;
1806 UINT8 SecureBootCfg;
1807 BOOLEAN SecureBootNotFound;
1808 UINTN DataSize;
1809
1810
1811 //
1812 // Secure Boot configuration changes
1813 //
1814 DataSize = sizeof(SecureBootCfg);
1815 SecureBootNotFound = FALSE;
1816 Status = gRT->GetVariable (
1817 EFI_SECURE_BOOT_ENABLE_NAME,
1818 &gEfiSecureBootEnableDisableGuid,
1819 NULL,
1820 &DataSize,
1821 &SecureBootCfg
1822 );
1823
1824 if (EFI_ERROR(Status)) {
1825 SecureBootNotFound = TRUE;
1826 }
1827 if (SecureBootNotFound) {
1828 Status = gRT->GetVariable (
1829 EFI_SECURE_BOOT_ENABLE_NAME,
1830 &gEfiSecureBootEnableDisableGuid,
1831 NULL,
1832 &DataSize,
1833 &SecureBootCfg
1834 );
1835 ASSERT_EFI_ERROR(Status);
1836 }
1837 if ((SecureBootCfg) != SystemConfigPtr->SecureBoot) {
1838 SecureBootCfg = !SecureBootCfg;
1839 Status = gRT->SetVariable (
1840 EFI_SECURE_BOOT_ENABLE_NAME,
1841 &gEfiSecureBootEnableDisableGuid,
1842 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
1843 sizeof (UINT8),
1844 &SecureBootCfg
1845 );
1846 }
1847
1848 }
1849
1850 VOID
1851 ConfirmSecureBootTest()
1852 {
1853
1854 }
1855