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