]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformSetupDxe/SetupInfoRecords.c
Vlv2DeviceRefCodePkg&Vlv2TbltDevicePkg:Convert Mix to DOS.
[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 UINT32 SrcDataSize;
524 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
525 CHAR16 *NewString;
526 CHAR16 *NewString2;
527 CHAR16 *NewStringToken;
528 STRING_REF TokenToUpdate;
529 EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;
530 UINTN Index;
531 UINT16 EeState;
532 UINTN DataOutput;
533
534 EFI_PROCESSOR_MICROCODE_REVISION_DATA *CpuUcodeRevisionData;
535 EFI_MEMORY_ARRAY_START_ADDRESS *MemoryArray;
536 EFI_MEMORY_ARRAY_LINK *MemoryArrayLink;
537 UINT64 MonotonicCount;
538
539 CHAR16 Version[100]; //Assuming that strings are < 100 UCHAR
540 CHAR16 ReleaseDate[100]; //Assuming that strings are < 100 UCHAR
541 CHAR16 ReleaseTime[100]; //Assuming that strings are < 100 UCHAR
542
543 NewString = AllocateZeroPool (0x100);
544 NewString2 = AllocateZeroPool (0x100);
545 SetMem(Version, sizeof(Version), 0);
546 SetMem(ReleaseDate, sizeof(ReleaseDate), 0);
547 SetMem(ReleaseTime, sizeof(ReleaseTime), 0);
548
549 //
550 // Initialize EE state for not to show EE related setup options
551 //
552 EeState = 0;
553
554 //
555 // Get the Data Hub Protocol. Assume only one instance
556 //
557 Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (void **)&DataHub);
558 ASSERT_EFI_ERROR(Status);
559
560 //
561 // Get all available data records from data hub
562 //
563 MonotonicCount = 0;
564 Record = NULL;
565
566 do {
567 Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);
568 if (!EFI_ERROR(Status)) {
569 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
570 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
571 SrcData = (UINT8 *)(DataHeader + 1);
572 SrcDataSize = Record->RecordSize - Record->HeaderSize - sizeof (EFI_SUBCLASS_TYPE1_HEADER);
573
574 //
575 // Processor
576 //
577 if (CompareGuid(&Record->DataRecordGuid, &gEfiProcessorSubClassGuid)) {
578 CopyMem (&mProcessorProducerGuid, &Record->ProducerName, sizeof(EFI_GUID));
579 switch (DataHeader->RecordType) {
580 case ProcessorCoreFrequencyRecordType:
581 CopyMem(&mProcessorFrequency, SrcData, sizeof(EFI_EXP_BASE10_DATA));
582 Index = EfiValueToString (
583 NewString,
584 ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)/1000000000,
585 PREFIX_ZERO,
586 0
587 );
588 StrCat (NewString, L".");
589 EfiValueToString (
590 NewString + Index + 1,
591 ((ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)%1000000000)/10000000),
592 PREFIX_ZERO,
593 0
594 );
595 StrCat (NewString, L" GHz");
596 TokenToUpdate = (STRING_REF)STR_PROCESSOR_SPEED_VALUE;
597 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
598 break;
599
600 case ProcessorVersionRecordType:
601 ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *)SrcData;
602 NewStringToken = HiiGetPackageString(&mProcessorProducerGuid, *ProcessorVersion, NULL);
603 TokenToUpdate = (STRING_REF)STR_PROCESSOR_VERSION_VALUE;
604 HiiSetString(mHiiHandle, TokenToUpdate, NewStringToken, NULL);
605 break;
606 case CpuUcodeRevisionDataRecordType:
607 CpuUcodeRevisionData = (EFI_PROCESSOR_MICROCODE_REVISION_DATA *) SrcData;
608 if (CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber != 0) {
609 EfiValueToHexStr (
610 NewString,
611 CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber,
612 PREFIX_ZERO,
613 8
614 );
615 TokenToUpdate = (STRING_REF)STR_PROCESSOR_MICROCODE_VALUE;
616 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
617 }
618 break;
619 default:
620 break;
621 }
622
623 //
624 // Cache
625 //
626 } else if (CompareGuid(&Record->DataRecordGuid, &gEfiCacheSubClassGuid) &&
627 (DataHeader->RecordType == CacheSizeRecordType)) {
628 if (DataHeader->SubInstance == EFI_CACHE_L1) {
629 EFI_CACHE_TYPE_DATA CacheType;
630 if (EFI_SUCCESS == GetCacheType(DataHeader->Instance, DataHeader->SubInstance,&CacheType)){
631 if (CacheType == EfiCacheTypeData) {
632 TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_DATA_CACHE_VALUE;
633 } else if (CacheType == EfiCacheTypeInstruction) {
634 TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_INSTR_CACHE_VALUE;
635 } else {
636 continue;
637 }
638 } else {
639 continue;
640 }
641 }
642 else if (DataHeader->SubInstance == EFI_CACHE_L2) {
643 TokenToUpdate = (STRING_REF)STR_PROCESSOR_L2_CACHE_VALUE;
644 } else {
645 continue;
646 }
647 if (ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData)) {
648 DataOutput = ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData) >> 10;
649 EfiValueToString (NewString, DataOutput, PREFIX_ZERO, 0);
650
651 StrCat (NewString, L" KB");
652 if (DataHeader->SubInstance == EFI_CACHE_L3) {
653 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
654 } else if(DataHeader->SubInstance == EFI_CACHE_L2 && mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage > 1){
655 //
656 // Show XxL2 string
657 //
658 EfiValueToString (
659 NewString2,
660 mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage,
661 PREFIX_ZERO,
662 0
663 );
664 StrCat(NewString2, L"x ");
665 StrCat(NewString2, NewString);
666 HiiSetString(mHiiHandle, TokenToUpdate, NewString2, NULL);
667 } else {
668 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
669 }
670 }
671
672 //
673 // Memory
674 //
675 } else if (CompareGuid(&Record->DataRecordGuid, &gEfiMemorySubClassGuid)) {
676 switch (DataHeader->RecordType) {
677 case EFI_MEMORY_ARRAY_LINK_RECORD_NUMBER:
678 MemoryArrayLink = (EFI_MEMORY_ARRAY_LINK *)SrcData;
679
680 if (MemoryArrayLink->MemorySpeed > 0) {
681 //
682 // Save the lowest speed memory module
683 //
684 if (MemoryArrayLink->MemorySpeed < mMemorySpeed) {
685 mMemorySpeed = MemoryArrayLink->MemorySpeed;
686 }
687 switch (DataHeader->SubInstance) {
688 case 1:
689 mMemorySpeedChannelASlot0 = MemoryArrayLink->MemorySpeed;
690 mMemorySizeChannelASlot0 = MemoryArrayLink->MemoryDeviceSize;
691 break;
692 case 2:
693 mMemorySpeedChannelASlot1 = MemoryArrayLink->MemorySpeed;
694 mMemorySizeChannelASlot1 = MemoryArrayLink->MemoryDeviceSize;
695 break;
696 case 3:
697 mMemorySpeedChannelBSlot0 = MemoryArrayLink->MemorySpeed;
698 mMemorySizeChannelBSlot0 = MemoryArrayLink->MemoryDeviceSize;
699 break;
700 case 4:
701 mMemorySpeedChannelBSlot1 = MemoryArrayLink->MemorySpeed;
702 mMemorySizeChannelBSlot1 = MemoryArrayLink->MemoryDeviceSize;
703 break;
704 case 5:
705 mMemorySpeedChannelCSlot0 = MemoryArrayLink->MemorySpeed;
706 mMemorySizeChannelCSlot0 = MemoryArrayLink->MemoryDeviceSize;
707 break;
708 case 6:
709 mMemorySpeedChannelCSlot1 = MemoryArrayLink->MemorySpeed;
710 mMemorySizeChannelCSlot1 = MemoryArrayLink->MemoryDeviceSize;
711 break;
712 default:
713 break;
714 }
715 }
716 break;
717
718 case EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER:
719 MemoryArray = (EFI_MEMORY_ARRAY_START_ADDRESS *)SrcData;
720 if (MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress) {
721 DataOutput = (UINTN)RShiftU64((MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress + 1), 20);
722 EfiValueToString (NewString, DataOutput / 1024, PREFIX_ZERO, 0);
723 if(DataOutput % 1024) {
724 StrCat (NewString, L".");
725 DataOutput = ((DataOutput % 1024) * 1000) / 1024;
726 while(!(DataOutput % 10))
727 DataOutput = DataOutput / 10;
728 EfiValueToString (NewString2, DataOutput, PREFIX_ZERO, 0);
729 StrCat (NewString, NewString2);
730 }
731 StrCat (NewString, L" GB");
732 TokenToUpdate = (STRING_REF)STR_TOTAL_MEMORY_SIZE_VALUE;
733 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
734 }
735 break;
736
737 default:
738 break;
739 }
740 }
741 }
742 }
743 } while (!EFI_ERROR(Status) && (MonotonicCount != 0));
744
745 Status = GetBiosVersionDateTime (
746 Version,
747 ReleaseDate,
748 ReleaseTime
749 );
750
751 DEBUG ((EFI_D_ERROR, "GetBiosVersionDateTime :%s %s %s \n", Version, ReleaseDate, ReleaseTime));
752 if (!EFI_ERROR (Status)) {
753 UINTN Length = 0;
754 CHAR16 *BuildDateTime;
755
756 Length = StrLen(ReleaseDate) + StrLen(ReleaseTime);
757
758 BuildDateTime = AllocateZeroPool ((Length+2) * sizeof(CHAR16));
759 StrCpy (BuildDateTime, ReleaseDate);
760 StrCat (BuildDateTime, L" ");
761 StrCat (BuildDateTime, ReleaseTime);
762
763 TokenToUpdate = (STRING_REF)STR_BIOS_VERSION_VALUE;
764 DEBUG ((EFI_D_ERROR, "update STR_BIOS_VERSION_VALUE\n"));
765 HiiSetString(mHiiHandle, TokenToUpdate, Version, NULL);
766
767 TokenToUpdate = (STRING_REF)STR_BIOS_BUILD_TIME_VALUE;
768 DEBUG ((EFI_D_ERROR, "update STR_BIOS_BUILD_TIME_VALUE\n"));
769 HiiSetString(mHiiHandle, TokenToUpdate, BuildDateTime, NULL);
770 }
771
772 //
773 // Calculate and update memory speed display in Main Page
774 //
775 //
776 // Update the overall memory speed
777 //
778 if (mMemorySpeed != 0xffff) {
779 EfiValueToString (NewString, mMemorySpeed, PREFIX_ZERO, 0);
780 StrCat (NewString, L" MHz");
781
782 TokenToUpdate = (STRING_REF)STR_SYSTEM_MEMORY_SPEED_VALUE;
783 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
784 }
785
786 gBS->FreePool(NewString);
787 gBS->FreePool(NewString2);
788
789 return;
790 }
791
792 /**
793
794 Routine Description: update the SETUP info for "Additional Information" which is SMBIOS info.
795
796 @retval EFI_STATUS
797
798 **/
799 EFI_STATUS
800 UpdateAdditionalInformation (
801 )
802 {
803 EFI_STATUS Status;
804 UINT64 MonotonicCount;
805 EFI_DATA_HUB_PROTOCOL *DataHub;
806 EFI_DATA_RECORD_HEADER *Record;
807 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
808 EFI_MISC_SYSTEM_MANUFACTURER *SystemManufacturer;
809 UINTN Size;
810 EFI_SMBIOS_PROTOCOL *Smbios;
811 EFI_SMBIOS_HANDLE SmbiosHandle;
812 EFI_SMBIOS_TABLE_HEADER *SmbiosRecord;
813 SMBIOS_TABLE_TYPE0 *Type0Record;
814 UINT8 StrIndex;
815 CHAR16 *BiosVersion = NULL;
816 CHAR16 *IfwiVersion = NULL;
817 UINT16 SearchIndex;
818 EFI_STRING_ID TokenToUpdate;
819
820 Status = gBS->LocateProtocol (
821 &gEfiDataHubProtocolGuid,
822 NULL,
823 (void **)&DataHub
824 );
825
826 ASSERT_EFI_ERROR(Status);
827
828 Size = 3;
829
830 MonotonicCount = 0;
831 Record = NULL;
832 do {
833 Status = DataHub->GetNextRecord (
834 DataHub,
835 &MonotonicCount,
836 NULL,
837 &Record
838 );
839 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
840 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
841
842 if (CompareGuid(&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
843 (DataHeader->RecordType == EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER)) {
844 //
845 // System Information
846 //
847 SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER *)(DataHeader + 1);
848
849 #if defined( RVP_SUPPORT ) && RVP_SUPPORT
850 //
851 // UUID (System Information)
852 //
853 SMBIOSString = EfiLibAllocateZeroPool (0x100);
854 GuidToString ( &SystemManufacturer->SystemUuid, SMBIOSString, 0x00 );
855
856 TokenToUpdate = (STRING_REF)STR_SYSTEM_UUID_VALUE;
857 HiiSetString(mHiiHandle, TokenToUpdate, SMBIOSString, NULL);
858
859 gBS->FreePool(SMBIOSString);
860 #endif
861 }
862 }
863 } while (!EFI_ERROR(Status) && (MonotonicCount != 0));
864
865 Status = gBS->LocateProtocol (
866 &gEfiSmbiosProtocolGuid,
867 NULL,
868 (VOID **) &Smbios
869 );
870 ASSERT_EFI_ERROR (Status);
871
872 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
873 do {
874 Status = Smbios->GetNext (
875 Smbios,
876 &SmbiosHandle,
877 NULL,
878 &SmbiosRecord,
879 NULL
880 );
881 if (SmbiosRecord->Type == EFI_SMBIOS_TYPE_BIOS_INFORMATION) {
882 Type0Record = (SMBIOS_TABLE_TYPE0 *) SmbiosRecord;
883 StrIndex = Type0Record->BiosVersion;
884 GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type0Record + Type0Record->Hdr.Length), StrIndex, &BiosVersion);
885 TokenToUpdate = STRING_TOKEN (STR_BIOS_VERSION_VALUE);
886 for (SearchIndex = 0x0; SearchIndex < SMBIOS_STRING_MAX_LENGTH; SearchIndex++) {
887 if (BiosVersion[SearchIndex] == 0x0020) {
888 BiosVersion[SearchIndex] = 0x0000;
889 IfwiVersion = (CHAR16 *)(&BiosVersion[SearchIndex+1]);
890 break;
891 } else if (BiosVersion[SearchIndex] == 0x0000) {
892 break;
893 }
894 }
895 HiiSetString (mHiiHandle, TokenToUpdate, BiosVersion, NULL);
896
897 //
898 // Check IfwiVersion, to avoid no IFWI version in SMBIOS Type 0 strucntion
899 //
900 if(IfwiVersion) {
901 TokenToUpdate = STRING_TOKEN (STR_IFWI_VERSION_VALUE);
902 HiiSetString (mHiiHandle, TokenToUpdate, IfwiVersion, NULL);
903 }
904 }
905 } while (!EFI_ERROR(Status));
906
907 UpdateLatestBootTime();
908
909 return EFI_SUCCESS;
910 }
911
912 VOID
913 UpdateCPUInformation ()
914 {
915 CHAR16 Buffer[40];
916 UINT16 FamilyId;
917 UINT8 Model;
918 UINT8 SteppingId;
919 UINT8 ProcessorType;
920 EFI_STATUS Status;
921 EFI_MP_SERVICES_PROTOCOL *MpService;
922 UINTN MaximumNumberOfCPUs;
923 UINTN NumberOfEnabledCPUs;
924 UINT32 Buffer32 = 0xFFFFFFFF; // Keep buffer with unknown device
925
926 EfiCpuVersion (&FamilyId, &Model, &SteppingId, &ProcessorType);
927
928 //
929 //we need raw Model data
930 //
931 Model = Model & 0xf;
932
933 //
934 //Family/Model/Step
935 //
936 UnicodeSPrint (Buffer, sizeof (Buffer), L"%d/%d/%d", FamilyId, Model, SteppingId);
937 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_ID_VALUE), Buffer, NULL);
938
939 Status = gBS->LocateProtocol (
940 &gEfiMpServiceProtocolGuid,
941 NULL,
942 (void **)&MpService
943 );
944 if (!EFI_ERROR (Status)) {
945 //
946 // Determine the number of processors
947 //
948 MpService->GetNumberOfProcessors (
949 MpService,
950 &MaximumNumberOfCPUs,
951 &NumberOfEnabledCPUs
952 );
953 UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", MaximumNumberOfCPUs);
954 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_CORE_VALUE), Buffer, NULL);
955 }
956 //
957 // Update Mobile / Desktop / Tablet SKU
958 //
959 Buffer32 =(UINT32) RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
960
961 switch(Buffer32){
962 case 0x0:
963 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - ISG SKU SOC", Buffer32);
964 break;
965 case 0x01:
966 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
967 break;
968 case 0x02:
969 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Desktop SKU SOC", Buffer32);
970 break;
971 case 0x03:
972 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
973 break;
974 default:
975 UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Unknown SKU SOC", Buffer32);
976 break;
977 }
978 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_SKU_VALUE), Buffer, NULL);
979
980 }
981
982
983 EFI_STATUS
984 SearchChildHandle(
985 EFI_HANDLE Father,
986 EFI_HANDLE *Child
987 )
988 {
989 EFI_STATUS Status;
990 UINTN HandleIndex;
991 EFI_GUID **ProtocolGuidArray = NULL;
992 UINTN ArrayCount;
993 UINTN ProtocolIndex;
994 UINTN OpenInfoCount;
995 UINTN OpenInfoIndex;
996 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo = NULL;
997 UINTN mHandleCount;
998 EFI_HANDLE *mHandleBuffer= NULL;
999
1000 //
1001 // Retrieve the list of all handles from the handle database
1002 //
1003 Status = gBS->LocateHandleBuffer (
1004 AllHandles,
1005 NULL,
1006 NULL,
1007 &mHandleCount,
1008 &mHandleBuffer
1009 );
1010
1011 for (HandleIndex = 0; HandleIndex < mHandleCount; HandleIndex++)
1012 {
1013 //
1014 // Retrieve the list of all the protocols on each handle
1015 //
1016 Status = gBS->ProtocolsPerHandle (
1017 mHandleBuffer[HandleIndex],
1018 &ProtocolGuidArray,
1019 &ArrayCount
1020 );
1021 if (!EFI_ERROR (Status))
1022 {
1023 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++)
1024 {
1025 Status = gBS->OpenProtocolInformation (
1026 mHandleBuffer[HandleIndex],
1027 ProtocolGuidArray[ProtocolIndex],
1028 &OpenInfo,
1029 &OpenInfoCount
1030 );
1031 if (!EFI_ERROR (Status))
1032 {
1033 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++)
1034 {
1035 if(OpenInfo[OpenInfoIndex].AgentHandle == Father)
1036 {
1037 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER)
1038 {
1039 *Child = mHandleBuffer[HandleIndex];
1040 Status = EFI_SUCCESS;
1041 goto TryReturn;
1042 }
1043 }
1044 }
1045 Status = EFI_NOT_FOUND;
1046 }
1047 }
1048 if(OpenInfo != NULL)
1049 {
1050 FreePool(OpenInfo);
1051 OpenInfo = NULL;
1052 }
1053 }
1054 FreePool (ProtocolGuidArray);
1055 ProtocolGuidArray = NULL;
1056 }
1057 TryReturn:
1058 if(OpenInfo != NULL)
1059 {
1060 FreePool (OpenInfo);
1061 OpenInfo = NULL;
1062 }
1063 if(ProtocolGuidArray != NULL)
1064 {
1065 FreePool(ProtocolGuidArray);
1066 ProtocolGuidArray = NULL;
1067 }
1068 if(mHandleBuffer != NULL)
1069 {
1070 FreePool (mHandleBuffer);
1071 mHandleBuffer = NULL;
1072 }
1073 return Status;
1074 }
1075
1076 EFI_STATUS
1077 JudgeHandleIsPCIDevice(
1078 EFI_HANDLE Handle,
1079 UINT8 Device,
1080 UINT8 Funs
1081 )
1082 {
1083 EFI_STATUS Status;
1084 EFI_DEVICE_PATH *DPath;
1085 EFI_DEVICE_PATH *DevicePath;
1086
1087 Status = gBS->HandleProtocol (
1088 Handle,
1089 &gEfiDevicePathProtocolGuid,
1090 (VOID **) &DPath
1091 );
1092 if(!EFI_ERROR(Status))
1093 {
1094 DevicePath = DPath;
1095 while(!IsDevicePathEnd(DPath))
1096 {
1097 if((DPath->Type == HARDWARE_DEVICE_PATH) && (DPath->SubType == HW_PCI_DP))
1098 {
1099 PCI_DEVICE_PATH *PCIPath;
1100
1101 PCIPath = (PCI_DEVICE_PATH*) DPath;
1102 DPath = NextDevicePathNode(DPath);
1103 if(IsDevicePathEnd(DPath) && (PCIPath->Device == Device) && (PCIPath->Function == Funs))
1104 {
1105 return EFI_SUCCESS;
1106 }
1107 }
1108 else
1109 {
1110 DPath = NextDevicePathNode(DPath);
1111 }
1112 }
1113 }
1114 return EFI_UNSUPPORTED;
1115 }
1116
1117 EFI_STATUS
1118 GetDriverName(
1119 EFI_HANDLE Handle,
1120 CHAR16 *Name
1121 )
1122 {
1123 EFI_DRIVER_BINDING_PROTOCOL *BindHandle = NULL;
1124 EFI_STATUS Status;
1125 UINT32 Version;
1126 UINT16 *Ptr;
1127 Status = gBS->OpenProtocol(
1128 Handle,
1129 &gEfiDriverBindingProtocolGuid,
1130 (VOID**)&BindHandle,
1131 NULL,
1132 NULL,
1133 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1134 );
1135
1136 if (EFI_ERROR(Status))
1137 {
1138 return EFI_NOT_FOUND;
1139 }
1140
1141 Version = BindHandle->Version;
1142 Ptr = (UINT16*)&Version;
1143 UnicodeSPrint(Name, 40, L"%d.%d.%d", Version >> 24 , (Version >>16)& 0x0f ,*(Ptr));
1144
1145 return EFI_SUCCESS;
1146 }
1147
1148 EFI_STATUS
1149 GetGOPDriverName(
1150 CHAR16 *Name
1151 )
1152 {
1153 UINTN HandleCount;
1154 EFI_HANDLE *Handles= NULL;
1155 UINTN Index;
1156 EFI_STATUS Status;
1157 EFI_HANDLE Child = 0;
1158
1159 Status = gBS->LocateHandleBuffer(
1160 ByProtocol,
1161 &gEfiDriverBindingProtocolGuid,
1162 NULL,
1163 &HandleCount,
1164 &Handles
1165 );
1166 for (Index = 0; Index < HandleCount ; Index++)
1167 {
1168 Status = SearchChildHandle(Handles[Index], &Child);
1169 if(!EFI_ERROR(Status))
1170 {
1171 Status = JudgeHandleIsPCIDevice(
1172 Child,
1173 0x02,
1174 0x00
1175 );
1176 if(!EFI_ERROR(Status))
1177 {
1178 return GetDriverName(Handles[Index], Name);
1179 }
1180 }
1181 }
1182 return EFI_UNSUPPORTED;
1183 }
1184
1185 EFI_STATUS
1186 UpdatePlatformInformation (
1187 )
1188 {
1189 UINT32 MicroCodeVersion;
1190 CHAR16 Buffer[40];
1191 UINT8 IgdVBIOSRevH;
1192 UINT8 IgdVBIOSRevL;
1193 UINT16 EDX;
1194 EFI_IA32_REGISTER_SET RegSet;
1195 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios = NULL;
1196 EFI_STATUS Status;
1197 UINT8 CpuFlavor=0;
1198 EFI_PEI_HOB_POINTERS GuidHob;
1199 EFI_PLATFORM_INFO_HOB *mPlatformInfo=NULL;
1200 UINTN NumHandles;
1201 EFI_HANDLE *HandleBuffer;
1202 UINTN Index;
1203 DXE_PCH_PLATFORM_POLICY_PROTOCOL *PchPlatformPolicy;
1204 UINTN PciD31F0RegBase;
1205 UINT8 count;
1206 UINT8 Data8;
1207 UINT8 PIDData8;
1208
1209 CHAR16 Name[40];
1210 UINT32 MrcVersion;
1211
1212 //
1213 // Get the HOB list. If it is not present, then ASSERT.
1214 //
1215 GuidHob.Raw = GetHobList ();
1216 if (GuidHob.Raw != NULL) {
1217 if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
1218 mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
1219 }
1220 }
1221
1222 //
1223 //VBIOS version
1224 //
1225 Status = gBS->LocateProtocol(
1226 &gEfiLegacyBiosProtocolGuid,
1227 NULL,
1228 (void **)&LegacyBios
1229 );
1230 if (!EFI_ERROR (Status)) {
1231 RegSet.X.AX = 0x5f01;
1232 Status = LegacyBios->Int86 (LegacyBios, 0x10, &RegSet);
1233 ASSERT_EFI_ERROR(Status);
1234
1235 //
1236 // simulate AMI int15 (ax=5f01) handler
1237 // check NbInt15.asm in AMI code for asm edition
1238 //
1239 EDX = (UINT16)((RegSet.E.EBX >> 16) & 0xffff);
1240 IgdVBIOSRevH = (UINT8)(((EDX & 0x0F00) >> 4) | (EDX & 0x000F));
1241 IgdVBIOSRevL = (UINT8)(((RegSet.X.BX & 0x0F00) >> 4) | (RegSet.X.BX & 0x000F));
1242
1243 if (IgdVBIOSRevH==0 && IgdVBIOSRevL==0){
1244 HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), L"N/A", NULL);
1245 } else {
1246 UnicodeSPrint (Buffer, sizeof (Buffer), L"%02X%02X", IgdVBIOSRevH,IgdVBIOSRevL);
1247 HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), Buffer, NULL);
1248 }
1249 }
1250
1251 Status = GetGOPDriverName(Name);
1252
1253 if (!EFI_ERROR(Status))
1254 {
1255 HiiSetString(mHiiHandle, STRING_TOKEN(STR_GOP_VALUE), Name, NULL);
1256 }
1257
1258
1259 //
1260 // CpuFlavor
1261 // ISG-DC Tablet 000
1262 // VLV-QC Tablet 001
1263 // VLV-QC Desktop 010
1264 // VLV-QC Notebook 011
1265 //
1266 CpuFlavor = RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
1267
1268 switch(CpuFlavor){
1269 case 0x0:
1270 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-DC Tablet", CpuFlavor);
1271 break;
1272 case 0x01:
1273 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
1274 break;
1275 case 0x02:
1276 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Desktop", CpuFlavor);
1277 break;
1278 case 0x03:
1279 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
1280 break;
1281 default:
1282 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"Unknown CPU", CpuFlavor);
1283 break;
1284 }
1285 HiiSetString(mHiiHandle,STRING_TOKEN(STR_CPU_FLAVOR_VALUE), Buffer, NULL);
1286
1287 if ( NULL != mPlatformInfo) {
1288 //
1289 //BoardId
1290 //
1291 switch(mPlatformInfo->BoardId){
1292 case 0x2:
1293 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE RVP(%02x)", mPlatformInfo->BoardId);
1294 break;
1295
1296 case 0x4:
1297 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFRD(%02x)", mPlatformInfo->BoardId);
1298 break;
1299
1300 case 0x5:
1301 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY ROCK RVP DDR3L (%02x)", mPlatformInfo->BoardId);
1302 break;
1303
1304 case 0x20:
1305 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAYLEY BAY (%02x)", mPlatformInfo->BoardId);
1306 break;
1307
1308 case 0x30:
1309 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAKER SPORT (%02x)", mPlatformInfo->BoardId);
1310 break;
1311
1312 case 0x0:
1313 UnicodeSPrint (Buffer, sizeof (Buffer), L"ALPINE VALLEY (%x)", mPlatformInfo->BoardId);
1314 break;
1315
1316 case 0x3:
1317 UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFD8 (%x)", mPlatformInfo->BoardId);
1318 break;
1319
1320 default:
1321 UnicodeSPrint (Buffer, sizeof (Buffer), L"Unknown BOARD (%02x)", mPlatformInfo->BoardId);
1322 break;
1323 }
1324 HiiSetString(mHiiHandle,STRING_TOKEN(STR_BOARD_ID_VALUE), Buffer, NULL);
1325
1326
1327 //
1328 // Get Board FAB ID Info from protocol, update into the NVS area.
1329 // bit0~bit3 are for Fab ID, 0x0F means unknow FAB.
1330 //
1331 if(mPlatformInfo->BoardRev == 0x0F) {
1332 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", L"Unknown FAB");
1333 HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
1334 } else {
1335 UnicodeSPrint (Buffer, sizeof (Buffer), L"%2x", mPlatformInfo->BoardRev);
1336 HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
1337 }
1338 }
1339
1340 //
1341 //Update MRC Version
1342 //
1343 MrcVersion = 0x00000000;
1344 MrcVersion &= 0xffff;
1345 Index = EfiValueToString (Buffer, MrcVersion/100, PREFIX_ZERO, 0);
1346 StrCat (Buffer, L".");
1347 EfiValueToString (Buffer + Index + 1, (MrcVersion%100)/10, PREFIX_ZERO, 0);
1348 EfiValueToString (Buffer + Index + 2, (MrcVersion%100)%10, PREFIX_ZERO, 0);
1349 HiiSetString(mHiiHandle,STRING_TOKEN(STR_MRC_VERSION_VALUE), Buffer, NULL);
1350
1351 //
1352 //Update Soc Version
1353 //
1354
1355 //
1356 // Retrieve all instances of PCH Platform Policy protocol
1357 //
1358 Status = gBS->LocateHandleBuffer (
1359 ByProtocol,
1360 &gDxePchPlatformPolicyProtocolGuid,
1361 NULL,
1362 &NumHandles,
1363 &HandleBuffer
1364 );
1365 if (!EFI_ERROR (Status)) {
1366 //
1367 // Find the matching PCH Policy protocol
1368 //
1369 for (Index = 0; Index < NumHandles; Index++) {
1370 Status = gBS->HandleProtocol (
1371 HandleBuffer[Index],
1372 &gDxePchPlatformPolicyProtocolGuid,
1373 (void **)&PchPlatformPolicy
1374 );
1375 if (!EFI_ERROR (Status)) {
1376 PciD31F0RegBase = MmPciAddress (
1377 0,
1378 PchPlatformPolicy->BusNumber,
1379 PCI_DEVICE_NUMBER_PCH_LPC,
1380 PCI_FUNCTION_NUMBER_PCH_LPC,
1381 0
1382 );
1383
1384 Data8 = MmioRead8 (PciD31F0RegBase + R_PCH_LPC_RID_CC);
1385 count = sizeof (SBRevisionTable) / sizeof (SBRevisionTable[0]);
1386 for (Index = 0; Index < count; Index++) {
1387 if(Data8 == SBRevisionTable[Index].RevId) {
1388 UnicodeSPrint (Buffer, sizeof (Buffer), L"%02x %a", Data8, SBRevisionTable[Index].String);
1389 HiiSetString(mHiiHandle,STRING_TOKEN(STR_SOC_VALUE), Buffer, NULL);
1390 break;
1391 }
1392 }
1393 break;
1394 }
1395 }
1396 }
1397
1398 //
1399 // Microcode Revision
1400 //
1401 EfiWriteMsr (EFI_MSR_IA32_BIOS_SIGN_ID, 0);
1402 EfiCpuid (EFI_CPUID_VERSION_INFO, NULL);
1403 MicroCodeVersion = (UINT32) RShiftU64 (EfiReadMsr (EFI_MSR_IA32_BIOS_SIGN_ID), 32);
1404 UnicodeSPrint (Buffer, sizeof (Buffer), L"%x", MicroCodeVersion);
1405 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_MICROCODE_VALUE), Buffer, NULL);
1406
1407 //
1408 // Punit Version
1409 //
1410 Data8 = 0;
1411 UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%x", Data8);
1412 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PUNIT_FW_VALUE), Buffer, NULL);
1413
1414 //
1415 // PMC Version
1416 //
1417 Data8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>16)&0x00FF);
1418 PIDData8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>24)&0x00FF);
1419 UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%X_%X",PIDData8, Data8);
1420 HiiSetString(mHiiHandle,STRING_TOKEN(STR_PMC_FW_VALUE), Buffer, NULL);
1421
1422 return EFI_SUCCESS;
1423 }
1424
1425 /**
1426
1427 Update SATA Drivesize Strings for Setup and Boot order
1428
1429 @param NewString - pointer to string.
1430 @param DeviceSpeed - speed of drive.
1431
1432 **/
1433 VOID
1434 GetDeviceSpeedString (
1435 CHAR16 *NewString,
1436 IN UINTN DeviceSpeed
1437 )
1438 {
1439 if (DeviceSpeed == 0x01) {
1440 StrCat (NewString, L"1.5Gb/s");
1441 } else if (DeviceSpeed == 0x02) {
1442 StrCat (NewString, L"3.0Gb/s");
1443 } else if (DeviceSpeed == 0x03) {
1444 StrCat (NewString, L"6.0Gb/s");
1445 } else if (DeviceSpeed == 0x0) {
1446
1447 }
1448 }
1449
1450 UINT8
1451 GetChipsetSataPortSpeed (
1452 UINTN PortNum
1453 )
1454 {
1455 UINT32 DeviceSpeed;
1456 UINT8 DeviceConfigStatus;
1457 UINT32 IdeAhciBar;
1458 EFI_PHYSICAL_ADDRESS MemBaseAddress = 0;
1459 UINT8 FunNum;
1460 EFI_STATUS Status;
1461 UINT32 DwordReg;
1462
1463
1464 DeviceSpeed = 0x01; // generation 1
1465
1466
1467 //
1468 // Allocate the AHCI BAR
1469 //
1470 FunNum = PCI_FUNCTION_NUMBER_PCH_SATA;
1471 MemBaseAddress = 0x0ffffffff;
1472 Status = gDS->AllocateMemorySpace (
1473 EfiGcdAllocateMaxAddressSearchBottomUp,
1474 EfiGcdMemoryTypeMemoryMappedIo,
1475 N_PCH_SATA_ABAR_ALIGNMENT, // 2^11: 2K Alignment
1476 V_PCH_SATA_ABAR_LENGTH, // 2K Length
1477 &MemBaseAddress,
1478 mImageHandle,
1479 NULL
1480 );
1481 IdeAhciBar = MmioRead32 (
1482 MmPciAddress (
1483 0,
1484 0,
1485 PCI_DEVICE_NUMBER_PCH_SATA,
1486 FunNum,
1487 R_PCH_SATA_ABAR
1488 )
1489 );
1490 IdeAhciBar &= 0xFFFFF800;
1491 DeviceConfigStatus = 0;
1492 if (IdeAhciBar == 0) {
1493 DeviceConfigStatus = 1;
1494 IdeAhciBar = (UINT32)MemBaseAddress;
1495 MmioWrite32 (
1496 MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
1497 IdeAhciBar
1498 );
1499 MmioOr16 (
1500 MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_COMMAND),
1501 B_PCH_SATA_COMMAND_MSE
1502 );
1503 }
1504
1505 if (mSystemConfiguration.SataType == PCH_SATA_MODE_IDE){
1506 //
1507 // Program the "Ports Implemented Register"
1508 //
1509 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));
1510 DwordReg = MmioRead32 (IdeAhciBar + R_PCH_SATA_AHCI_PI);
1511 }
1512
1513 switch (PortNum)
1514 {
1515 case 0:
1516 DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P0SSTS);
1517 break;
1518 case 1:
1519 DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P1SSTS);
1520 break;
1521 }
1522
1523 if (MemBaseAddress) {
1524 gDS->FreeMemorySpace (
1525 MemBaseAddress,
1526 V_PCH_SATA_ABAR_LENGTH
1527 );
1528 }
1529
1530 if (DeviceConfigStatus) {
1531 IdeAhciBar = 0;
1532 MmioWrite32 (
1533 MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
1534 IdeAhciBar
1535 );
1536 }
1537
1538 DeviceSpeed = (UINT8)((DeviceSpeed >> 4) & 0x0F);
1539
1540 return (UINT8)DeviceSpeed;
1541 }
1542
1543 /**
1544
1545 IDE data filter function.
1546
1547 **/
1548 void
1549 IdeDataFilter (void)
1550 {
1551 EFI_STATUS Status;
1552 UINTN HandleCount;
1553 EFI_HANDLE *HandleBuffer;
1554 EFI_DISK_INFO_PROTOCOL *DiskInfo;
1555 EFI_DEVICE_PATH_PROTOCOL *DevicePath, *DevicePathNode;
1556 PCI_DEVICE_PATH *PciDevicePath;
1557 UINTN Index;
1558 UINT8 Index1;
1559 UINT32 BufferSize;
1560 UINT32 DriveSize;
1561 UINT32 IdeChannel;
1562 UINT32 IdeDevice;
1563 EFI_ATA_IDENTIFY_DATA *IdentifyDriveInfo;
1564 CHAR16 *NewString;
1565 CHAR16 SizeString[20];
1566 STRING_REF NameToUpdate;
1567 CHAR8 StringBuffer[0x100];
1568 UINT32 DeviceSpeed;
1569 UINTN PortNumber;
1570
1571 //
1572 // Assume no line strings is longer than 256 bytes.
1573 //
1574 NewString = AllocateZeroPool (0x100);
1575 PciDevicePath = NULL;
1576
1577 //
1578 // Fill IDE Infomation
1579 //
1580 Status = gBS->LocateHandleBuffer (
1581 ByProtocol,
1582 &gEfiDiskInfoProtocolGuid,
1583 NULL,
1584 &HandleCount,
1585 &HandleBuffer
1586 );
1587
1588 if (EFI_ERROR (Status)) {
1589 return;
1590 }
1591
1592 for (Index = 0; Index < HandleCount; Index++) {
1593
1594 Status = gBS->HandleProtocol (
1595 HandleBuffer[Index],
1596 &gEfiDevicePathProtocolGuid,
1597 (VOID*)&DevicePath
1598 );
1599 ASSERT_EFI_ERROR (Status);
1600
1601 DevicePathNode = DevicePath;
1602 while (!IsDevicePathEnd (DevicePathNode) ) {
1603 if ((DevicePathType (DevicePathNode) == HARDWARE_DEVICE_PATH) &&
1604 ( DevicePathSubType (DevicePathNode) == HW_PCI_DP)) {
1605 PciDevicePath = (PCI_DEVICE_PATH *) DevicePathNode;
1606 break;
1607 }
1608 DevicePathNode = NextDevicePathNode (DevicePathNode);
1609 }
1610
1611 if (PciDevicePath == NULL) {
1612 continue;
1613 }
1614
1615 //
1616 // Check for onboard IDE
1617 //
1618 if (PciDevicePath->Device== PCI_DEVICE_NUMBER_PCH_SATA) {
1619 Status = gBS->HandleProtocol (
1620 HandleBuffer[Index],
1621 &gEfiDiskInfoProtocolGuid,
1622 (void **)&DiskInfo
1623 );
1624 ASSERT_EFI_ERROR (Status);
1625
1626 Status = DiskInfo->WhichIde (
1627 DiskInfo,
1628 &IdeChannel,
1629 &IdeDevice
1630 );
1631 ASSERT_EFI_ERROR (Status);
1632
1633 IdentifyDriveInfo = AllocatePool (sizeof(EFI_ATA_IDENTIFY_DATA));
1634
1635 BufferSize = sizeof(EFI_ATA_IDENTIFY_DATA);
1636 Status = DiskInfo->Identify (
1637 DiskInfo,
1638 IdentifyDriveInfo,
1639 &BufferSize
1640 );
1641 ASSERT_EFI_ERROR(Status);
1642
1643 //
1644 // Onboard SATA Devices
1645 //
1646 if (PciDevicePath->Function == PCI_FUNCTION_NUMBER_PCH_SATA) {
1647 if (IdeChannel == 0 && IdeDevice == 0) {
1648 NameToUpdate = (STRING_REF)STR_SATA0_NAME;
1649 } else if (IdeChannel == 1 && IdeDevice == 0) {
1650 NameToUpdate = (STRING_REF)STR_SATA1_NAME;
1651 } else {
1652 continue;
1653 }
1654 } else {
1655 continue;
1656 }
1657
1658 ZeroMem(StringBuffer, sizeof(StringBuffer));
1659 CopyMem(
1660 StringBuffer,
1661 (CHAR8 *)&IdentifyDriveInfo->ModelName,
1662 sizeof(IdentifyDriveInfo->ModelName)
1663 );
1664 SwapEntries(StringBuffer);
1665 AsciiToUnicode(StringBuffer, NewString);
1666
1667 //
1668 // Chap it off after 16 characters
1669 //
1670 NewString[16] = 0;
1671
1672 //
1673 // For HardDisk append the size. Otherwise display atapi
1674 //
1675 if ((IdentifyDriveInfo->config & 0x8000) == 00) {
1676 //
1677 // 48 bit address feature set is supported, get maximum capacity
1678 //
1679 if ((IdentifyDriveInfo->command_set_supported_83 & 0x0400) == 0) {
1680 DriveSize = (((((IdentifyDriveInfo->user_addressable_sectors_hi << 16) +
1681 IdentifyDriveInfo->user_addressable_sectors_lo) / 1000) * 512) / 1000);
1682 } else {
1683 DriveSize = IdentifyDriveInfo->maximum_lba_for_48bit_addressing[0];
1684 for (Index1 = 1; Index1 < 4; Index1++) {
1685 //
1686 // Lower byte goes first: word[100] is the lowest word, word[103] is highest
1687 //
1688 DriveSize |= LShiftU64(IdentifyDriveInfo->maximum_lba_for_48bit_addressing[Index1], 16 * Index1);
1689 }
1690 DriveSize = (UINT32) DivU64x32(MultU64x32(DivU64x32(DriveSize, 1000), 512), 1000);
1691 }
1692
1693 StrCat (NewString, L"(");
1694 EfiValueToString (SizeString, DriveSize/1000, PREFIX_BLANK, 0);
1695 StrCat (NewString, SizeString);
1696 StrCat (NewString, L".");
1697 EfiValueToString (SizeString, (DriveSize%1000)/100, PREFIX_BLANK, 0);
1698 StrCat (NewString, SizeString);
1699 StrCat (NewString, L"GB");
1700 } else {
1701 StrCat (NewString, L"(ATAPI");
1702 }
1703
1704 //
1705 // Update SPEED.
1706 //
1707 PortNumber = (IdeDevice << 1) + IdeChannel;
1708 DeviceSpeed = GetChipsetSataPortSpeed(PortNumber);
1709
1710 if (DeviceSpeed) {
1711 StrCat (NewString, L"-");
1712 GetDeviceSpeedString( NewString, DeviceSpeed);
1713 }
1714
1715 StrCat (NewString, L")");
1716
1717 HiiSetString(mHiiHandle, NameToUpdate, NewString, NULL);
1718
1719 }
1720 }
1721
1722 if (HandleBuffer != NULL) {
1723 gBS->FreePool (HandleBuffer);
1724 }
1725
1726 gBS->FreePool(NewString);
1727
1728 return;
1729 }
1730
1731
1732 VOID
1733 EFIAPI
1734 SetupInfo (void)
1735 {
1736 EFI_STATUS Status;
1737 UINTN VarSize;
1738 EFI_PEI_HOB_POINTERS GuidHob;
1739
1740 if (mSetupInfoDone) {
1741 return;
1742 }
1743
1744 VarSize = sizeof(SYSTEM_CONFIGURATION);
1745 Status = gRT->GetVariable(
1746 NORMAL_SETUP_NAME,
1747 &gEfiNormalSetupGuid,
1748 NULL,
1749 &VarSize,
1750 &mSystemConfiguration
1751 );
1752
1753 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
1754 //The setup variable is corrupted
1755 VarSize = sizeof(SYSTEM_CONFIGURATION);
1756 Status = gRT->GetVariable(
1757 L"SetupRecovery",
1758 &gEfiNormalSetupGuid,
1759 NULL,
1760 &VarSize,
1761 &mSystemConfiguration
1762 );
1763 ASSERT_EFI_ERROR (Status);
1764 }
1765
1766 //
1767 // Update HOB variable for PCI resource information
1768 // Get the HOB list. If it is not present, then ASSERT.
1769 //
1770 GuidHob.Raw = GetHobList ();
1771 if (GuidHob.Raw != NULL) {
1772 if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
1773 mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
1774 }
1775 }
1776
1777
1778 PrepareSetupInformation();
1779 UpdateAdditionalInformation ();
1780 UpdatePlatformInformation();
1781 UpdateCPUInformation();
1782 IdeDataFilter();
1783 mSetupInfoDone = TRUE;
1784
1785 return;
1786 }
1787
1788
1789 #define EFI_SECURE_BOOT_MODE_NAME L"SecureBoot"
1790
1791 VOID
1792 CheckSystemConfigLoad(SYSTEM_CONFIGURATION *SystemConfigPtr)
1793 {
1794 EFI_STATUS Status;
1795 UINT8 SecureBoot;
1796 UINTN DataSize;
1797
1798
1799 DataSize = sizeof(SecureBoot);
1800 Status = gRT->GetVariable (
1801 EFI_SECURE_BOOT_MODE_NAME,
1802 &gEfiGlobalVariableGuid,
1803 NULL,
1804 &DataSize,
1805 &SecureBoot
1806 );
1807
1808 if (EFI_ERROR(Status)) {
1809 SystemConfigPtr->SecureBoot = 0;
1810 } else {
1811 SystemConfigPtr->SecureBoot = SecureBoot;
1812 }
1813 }
1814
1815
1816 //
1817 // "SecureBootEnable" variable for the Secure boot feature enable/disable.
1818 //
1819 #define EFI_SECURE_BOOT_ENABLE_NAME L"SecureBootEnable"
1820 extern EFI_GUID gEfiSecureBootEnableDisableGuid;
1821
1822
1823 VOID
1824 CheckSystemConfigSave(SYSTEM_CONFIGURATION *SystemConfigPtr)
1825 {
1826 EFI_STATUS Status;
1827 UINT8 SecureBootCfg;
1828 BOOLEAN SecureBootNotFound;
1829 UINTN DataSize;
1830
1831
1832 //
1833 // Secure Boot configuration changes
1834 //
1835 DataSize = sizeof(SecureBootCfg);
1836 SecureBootNotFound = FALSE;
1837 Status = gRT->GetVariable (
1838 EFI_SECURE_BOOT_ENABLE_NAME,
1839 &gEfiSecureBootEnableDisableGuid,
1840 NULL,
1841 &DataSize,
1842 &SecureBootCfg
1843 );
1844
1845 if (EFI_ERROR(Status)) {
1846 SecureBootNotFound = TRUE;
1847 }
1848 if (SecureBootNotFound) {
1849 Status = gRT->GetVariable (
1850 EFI_SECURE_BOOT_ENABLE_NAME,
1851 &gEfiSecureBootEnableDisableGuid,
1852 NULL,
1853 &DataSize,
1854 &SecureBootCfg
1855 );
1856 ASSERT_EFI_ERROR(Status);
1857 }
1858 if ((SecureBootCfg) != SystemConfigPtr->SecureBoot) {
1859 SecureBootCfg = !SecureBootCfg;
1860 Status = gRT->SetVariable (
1861 EFI_SECURE_BOOT_ENABLE_NAME,
1862 &gEfiSecureBootEnableDisableGuid,
1863 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
1864 sizeof (UINT8),
1865 &SecureBootCfg
1866 );
1867 }
1868
1869 }
1870
1871 VOID
1872 ConfirmSecureBootTest()
1873 {
1874
1875 }
1876