SetupInfoRecords.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. /** @file
  2. Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. SetupInfoRecords.c
  6. Abstract:
  7. This is the filter driver to retrieve data hub entries.
  8. Revision History:
  9. --*/
  10. #include "PlatformSetupDxe.h"
  11. #include <Protocol/PciRootBridgeIo.h>
  12. #include <Protocol/SimpleNetwork.h>
  13. #include <Protocol/DevicePath.h>
  14. #include <Protocol/DiskInfo.h>
  15. #include <Protocol/IdeControllerInit.h>
  16. #include <Protocol/MpService.h>
  17. #include <Protocol/PchPlatformPolicy.h>
  18. #include <Protocol/Smbios.h>
  19. #include <IndustryStandard/SmBios.h>
  20. #include <Library/IoLib.h>
  21. #include <Guid/GlobalVariable.h>
  22. #include "Valleyview.h"
  23. #include "VlvAccess.h"
  24. #include "PchAccess.h"
  25. #include "SetupMode.h"
  26. #include "PchCommonDefinitions.h"
  27. #include <PlatformBaseAddresses.h>
  28. typedef struct {
  29. UINT8 ID;
  30. CHAR8 String[16];
  31. } VLV_REV;
  32. typedef struct {
  33. UINT8 RevId;
  34. CHAR8 String[16];
  35. } SB_REV;
  36. //
  37. // Silicon Steppings
  38. //
  39. SB_REV SBRevisionTable[] = {
  40. {V_PCH_LPC_RID_0, "(A0 Stepping)"},
  41. {V_PCH_LPC_RID_1, "(A0 Stepping)"},
  42. {V_PCH_LPC_RID_2, "(A1 Stepping)"},
  43. {V_PCH_LPC_RID_3, "(A1 Stepping)"},
  44. {V_PCH_LPC_RID_4, "(B0 Stepping)"},
  45. {V_PCH_LPC_RID_5, "(B0 Stepping)"},
  46. {V_PCH_LPC_RID_6, "(B1 Stepping)"},
  47. {V_PCH_LPC_RID_7, "(B1 Stepping)"},
  48. {V_PCH_LPC_RID_8, "(B2 Stepping)"},
  49. {V_PCH_LPC_RID_9, "(B2 Stepping)"},
  50. {V_PCH_LPC_RID_A, "(B3 Stepping)"},
  51. {V_PCH_LPC_RID_B, "(B3 Stepping)"},
  52. {V_PCH_LPC_RID_C, "(C0 Stepping)"},
  53. {V_PCH_LPC_RID_D, "(C0 Stepping)"}
  54. };
  55. #define LEFT_JUSTIFY 0x01
  56. #define PREFIX_SIGN 0x02
  57. #define PREFIX_BLANK 0x04
  58. #define COMMA_TYPE 0x08
  59. #define LONG_TYPE 0x10
  60. #define PREFIX_ZERO 0x20
  61. #define ICH_REG_REV 0x08
  62. #define MSR_IA32_PLATFORM_ID 0x17
  63. BOOLEAN mSetupInfoDone = FALSE;
  64. UINT8 mUseProductKey = 0;
  65. EFI_GUID mProcessorProducerGuid;
  66. EFI_HII_HANDLE mHiiHandle;
  67. EFI_PLATFORM_CPU_INFO mPlatformCpuInfo;
  68. SYSTEM_CONFIGURATION mSystemConfiguration;
  69. EFI_PLATFORM_INFO_HOB *mPlatformInfo;
  70. #define memset SetMem
  71. #define CHARACTER_NUMBER_FOR_VALUE 30
  72. typedef enum {
  73. PCH_SATA_MODE_IDE = 0,
  74. PCH_SATA_MODE_AHCI,
  75. PCH_SATA_MODE_RAID,
  76. PCH_SATA_MODE_MAX
  77. } PCH_SATA_MODE;
  78. /**
  79. Acquire the string associated with the Index from smbios structure and return it.
  80. The caller is responsible for free the string buffer.
  81. @param OptionalStrStart The start position to search the string
  82. @param Index The index of the string to extract
  83. @param String The string that is extracted
  84. @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
  85. **/
  86. EFI_STATUS
  87. GetOptionalStringByIndex (
  88. IN CHAR8 *OptionalStrStart,
  89. IN UINT8 Index,
  90. OUT CHAR16 **String
  91. )
  92. {
  93. UINTN StrSize;
  94. if (Index == 0) {
  95. *String = AllocateZeroPool (sizeof (CHAR16));
  96. return EFI_SUCCESS;
  97. }
  98. StrSize = 0;
  99. do {
  100. Index--;
  101. OptionalStrStart += StrSize;
  102. StrSize = AsciiStrSize (OptionalStrStart);
  103. } while (OptionalStrStart[StrSize] != 0 && Index != 0);
  104. if ((Index != 0) || (StrSize == 1)) {
  105. //
  106. // Meet the end of strings set but Index is non-zero, or
  107. // Find an empty string
  108. //
  109. return EFI_NOT_FOUND;
  110. } else {
  111. *String = AllocatePool (StrSize * sizeof (CHAR16));
  112. AsciiStrToUnicodeStr (OptionalStrStart, *String);
  113. }
  114. return EFI_SUCCESS;
  115. }
  116. /**
  117. VSPrint worker function that prints a Value as a decimal number in Buffer
  118. @param Buffer Location to place ascii decimal number string of Value.
  119. @param Value Decimal value to convert to a string in Buffer.
  120. @param Flags Flags to use in printing decimal string, see file header for details.
  121. @param Width Width of hex value.
  122. Number of characters printed.
  123. **/
  124. UINTN
  125. EfiValueToString (
  126. IN OUT CHAR16 *Buffer,
  127. IN INT64 Value,
  128. IN UINTN Flags,
  129. IN UINTN Width
  130. )
  131. {
  132. CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
  133. CHAR16 *TempStr;
  134. CHAR16 *BufferPtr;
  135. UINTN Count;
  136. UINTN ValueCharNum;
  137. UINTN Remainder;
  138. CHAR16 Prefix;
  139. UINTN Index;
  140. BOOLEAN ValueIsNegative;
  141. UINT64 TempValue;
  142. TempStr = TempBuffer;
  143. BufferPtr = Buffer;
  144. Count = 0;
  145. ValueCharNum = 0;
  146. ValueIsNegative = FALSE;
  147. if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
  148. Width = CHARACTER_NUMBER_FOR_VALUE - 1;
  149. }
  150. if (Value < 0) {
  151. Value = -Value;
  152. ValueIsNegative = TRUE;
  153. }
  154. do {
  155. TempValue = Value;
  156. Value = (INT64)DivU64x32 ((UINT64)Value, 10);
  157. Remainder = (UINTN)((UINT64)TempValue - 10 * Value);
  158. *(TempStr++) = (CHAR16)(Remainder + '0');
  159. ValueCharNum++;
  160. Count++;
  161. if ((Flags & COMMA_TYPE) == COMMA_TYPE) {
  162. if (ValueCharNum % 3 == 0 && Value != 0) {
  163. *(TempStr++) = ',';
  164. Count++;
  165. }
  166. }
  167. } while (Value != 0);
  168. if (ValueIsNegative) {
  169. *(TempStr++) = '-';
  170. Count++;
  171. }
  172. if ((Flags & PREFIX_ZERO) && !ValueIsNegative) {
  173. Prefix = '0';
  174. } else {
  175. Prefix = ' ';
  176. }
  177. Index = Count;
  178. if (!(Flags & LEFT_JUSTIFY)) {
  179. for (; Index < Width; Index++) {
  180. *(TempStr++) = Prefix;
  181. }
  182. }
  183. //
  184. // Reverse temp string into Buffer.
  185. //
  186. if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
  187. TempStr = TempBuffer + Width;
  188. }
  189. Index = 0;
  190. while (TempStr != TempBuffer) {
  191. *(BufferPtr++) = *(--TempStr);
  192. Index++;
  193. }
  194. *BufferPtr = 0;
  195. return Index;
  196. }
  197. static CHAR16 mHexStr[] = { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
  198. L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F' };
  199. /**
  200. VSPrint worker function that prints a Value as a hex number in Buffer
  201. @param Buffer Location to place ascii hex string of Value.
  202. @param Value Hex value to convert to a string in Buffer.
  203. @param Flags Flags to use in printing Hex string, see file header for details.
  204. @param Width Width of hex value.
  205. @retval Number of characters printed.
  206. **/
  207. UINTN
  208. EfiValueToHexStr (
  209. IN OUT CHAR16 *Buffer,
  210. IN UINT64 Value,
  211. IN UINTN Flags,
  212. IN UINTN Width
  213. )
  214. {
  215. CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
  216. CHAR16 *TempStr;
  217. CHAR16 Prefix;
  218. CHAR16 *BufferPtr;
  219. UINTN Count;
  220. UINTN Index;
  221. TempStr = TempBuffer;
  222. BufferPtr = Buffer;
  223. //
  224. // Count starts at one since we will null terminate. Each iteration of the
  225. // loop picks off one nibble. Oh yea TempStr ends up backwards
  226. //
  227. Count = 0;
  228. if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
  229. Width = CHARACTER_NUMBER_FOR_VALUE - 1;
  230. }
  231. do {
  232. Index = ((UINTN)Value & 0xf);
  233. *(TempStr++) = mHexStr[Index];
  234. Value = RShiftU64 (Value, 4);
  235. Count++;
  236. } while (Value != 0);
  237. if (Flags & PREFIX_ZERO) {
  238. Prefix = '0';
  239. } else {
  240. Prefix = ' ';
  241. }
  242. Index = Count;
  243. if (!(Flags & LEFT_JUSTIFY)) {
  244. for (; Index < Width; Index++) {
  245. *(TempStr++) = Prefix;
  246. }
  247. }
  248. //
  249. // Reverse temp string into Buffer.
  250. //
  251. if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
  252. TempStr = TempBuffer + Width;
  253. }
  254. Index = 0;
  255. while (TempStr != TempBuffer) {
  256. *(BufferPtr++) = *(--TempStr);
  257. Index++;
  258. }
  259. *BufferPtr = 0;
  260. return Index;
  261. }
  262. /*++
  263. Converts MAC address to Unicode string.
  264. The value is 64-bit and the resulting string will be 12
  265. digit hex number in pairs of digits separated by dashes.
  266. @param String string that will contain the value
  267. @param MacAddr add argument and description to function comment
  268. @param AddrSize add argument and description to function comment
  269. **/
  270. CHAR16 *
  271. StrMacToString (
  272. OUT CHAR16 *String,
  273. IN EFI_MAC_ADDRESS *MacAddr,
  274. IN UINT32 AddrSize
  275. )
  276. {
  277. UINT32 i;
  278. for (i = 0; i < AddrSize; i++) {
  279. EfiValueToHexStr (
  280. &String[2 * i],
  281. MacAddr->Addr[i] & 0xFF,
  282. PREFIX_ZERO,
  283. 2
  284. );
  285. }
  286. //
  287. // Terminate the string.
  288. //
  289. String[2 * AddrSize] = L'\0';
  290. return String;
  291. }
  292. VOID UpdateLatestBootTime() {
  293. UINTN VarSize;
  294. EFI_STATUS Status;
  295. UINT64 TimeValue;
  296. CHAR16 Buffer[40];
  297. if (mSystemConfiguration.LogBootTime != 1) {
  298. return;
  299. }
  300. VarSize = sizeof(TimeValue);
  301. Status = gRT->GetVariable(
  302. BOOT_TIME_NAME,
  303. &gEfiNormalSetupGuid,
  304. NULL,
  305. &VarSize,
  306. &TimeValue
  307. );
  308. if (EFI_ERROR(Status)) {
  309. return;
  310. }
  311. UnicodeSPrint (Buffer, sizeof (Buffer), L"%d ms", (UINT32)TimeValue);
  312. HiiSetString(mHiiHandle,STRING_TOKEN(STR_LOG_BOOT_TIME_VALUE), Buffer, NULL);
  313. }
  314. /**
  315. Setup data filter function. This function is invoked when there is data records
  316. available in the Data Hub.
  317. Standard event notification function arguments:
  318. @param Event The event that is signaled.
  319. @param Context Not used here.
  320. @retval EFI_STATUS
  321. **/
  322. VOID
  323. PrepareSetupInformation (
  324. )
  325. {
  326. EFI_STATUS Status;
  327. CHAR16 *NewString;
  328. STRING_REF TokenToUpdate;
  329. CHAR16 Version[100]; //Assuming that strings are < 100 UCHAR
  330. CHAR16 ReleaseDate[100]; //Assuming that strings are < 100 UCHAR
  331. CHAR16 ReleaseTime[100]; //Assuming that strings are < 100 UCHAR
  332. NewString = AllocateZeroPool (0x100);
  333. SetMem(Version, sizeof(Version), 0);
  334. SetMem(ReleaseDate, sizeof(ReleaseDate), 0);
  335. SetMem(ReleaseTime, sizeof(ReleaseTime), 0);
  336. Status = GetBiosVersionDateTime (
  337. Version,
  338. ReleaseDate,
  339. ReleaseTime
  340. );
  341. DEBUG ((EFI_D_ERROR, "GetBiosVersionDateTime :%s %s %s \n", Version, ReleaseDate, ReleaseTime));
  342. if (!EFI_ERROR (Status)) {
  343. UINTN Length = 0;
  344. CHAR16 *BuildDateTime;
  345. Length = StrLen(ReleaseDate) + StrLen(ReleaseTime);
  346. BuildDateTime = AllocateZeroPool ((Length+2) * sizeof(CHAR16));
  347. StrCpy (BuildDateTime, ReleaseDate);
  348. StrCat (BuildDateTime, L" ");
  349. StrCat (BuildDateTime, ReleaseTime);
  350. TokenToUpdate = (STRING_REF)STR_BIOS_VERSION_VALUE;
  351. DEBUG ((EFI_D_ERROR, "update STR_BIOS_VERSION_VALUE\n"));
  352. HiiSetString(mHiiHandle, TokenToUpdate, Version, NULL);
  353. TokenToUpdate = (STRING_REF)STR_BIOS_BUILD_TIME_VALUE;
  354. DEBUG ((EFI_D_ERROR, "update STR_BIOS_BUILD_TIME_VALUE\n"));
  355. HiiSetString(mHiiHandle, TokenToUpdate, BuildDateTime, NULL);
  356. }
  357. gBS->FreePool(NewString);
  358. }
  359. /**
  360. Routine Description: update the SETUP info for "Additional Information" which is SMBIOS info.
  361. @retval EFI_STATUS
  362. **/
  363. EFI_STATUS
  364. UpdateAdditionalInformation (
  365. )
  366. {
  367. EFI_STATUS Status;
  368. EFI_SMBIOS_PROTOCOL *Smbios;
  369. EFI_SMBIOS_HANDLE SmbiosHandle;
  370. EFI_SMBIOS_TABLE_HEADER *SmbiosRecord;
  371. SMBIOS_TABLE_TYPE0 *Type0Record;
  372. SMBIOS_TABLE_TYPE4 *Type4Record;
  373. SMBIOS_TABLE_TYPE7 *Type7Record;
  374. SMBIOS_TABLE_TYPE17 *Type17Record;
  375. UINT8 StrIndex;
  376. CHAR16 *BiosVersion = NULL;
  377. CHAR16 *ProcessorVersion = NULL;
  378. CHAR16 *IfwiVersion = NULL;
  379. UINT16 SearchIndex;
  380. EFI_STRING_ID TokenToUpdate;
  381. UINT32 MicrocodeRevision;
  382. CHAR16 NewString[0x100];
  383. UINTN TotalMemorySize;
  384. UINT16 MemorySpeed;
  385. Status = gBS->LocateProtocol (
  386. &gEfiSmbiosProtocolGuid,
  387. NULL,
  388. (VOID **) &Smbios
  389. );
  390. ASSERT_EFI_ERROR (Status);
  391. SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  392. TotalMemorySize = 0;
  393. MemorySpeed = 0xffff;
  394. do {
  395. Status = Smbios->GetNext (
  396. Smbios,
  397. &SmbiosHandle,
  398. NULL,
  399. &SmbiosRecord,
  400. NULL
  401. );
  402. if (SmbiosRecord->Type == EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION) {
  403. Type4Record = (SMBIOS_TABLE_TYPE4 *) SmbiosRecord;
  404. UnicodeSPrint (NewString, sizeof (NewString), L"%d.%d GHz",
  405. Type4Record->CurrentSpeed / 1000,
  406. Type4Record->CurrentSpeed % 1000
  407. );
  408. HiiSetString (mHiiHandle, STR_PROCESSOR_SPEED_VALUE, NewString, NULL);
  409. StrIndex = Type4Record->ProcessorVersion;
  410. GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type4Record + Type4Record->Hdr.Length), StrIndex, &ProcessorVersion);
  411. HiiSetString (mHiiHandle, STR_PROCESSOR_VERSION_VALUE, ProcessorVersion, NULL);
  412. MicrocodeRevision = (UINT32) RShiftU64 (AsmReadMsr64 (EFI_MSR_IA32_BIOS_SIGN_ID), 32);
  413. UnicodeSPrint (NewString, sizeof (NewString), L"%8x", MicrocodeRevision);
  414. HiiSetString (mHiiHandle, STR_PROCESSOR_MICROCODE_VALUE, NewString, NULL);
  415. }
  416. if (SmbiosRecord->Type == SMBIOS_TYPE_CACHE_INFORMATION) {
  417. Type7Record = (SMBIOS_TABLE_TYPE7 *) SmbiosRecord;
  418. UnicodeSPrint (NewString, sizeof (NewString), L"%d KB", Type7Record->InstalledSize);
  419. switch (Type7Record->CacheConfiguration & 0x03) {
  420. case 0:
  421. //
  422. // Level 1 Cache
  423. //
  424. if (Type7Record->SystemCacheType == CacheTypeInstruction) {
  425. HiiSetString (mHiiHandle, STR_PROCESSOR_L1_INSTR_CACHE_VALUE, NewString, NULL);
  426. }
  427. if (Type7Record->SystemCacheType == CacheTypeData) {
  428. HiiSetString (mHiiHandle, STR_PROCESSOR_L1_DATA_CACHE_VALUE, NewString, NULL);
  429. }
  430. break;
  431. case 1:
  432. //
  433. // Level 2 Cache
  434. //
  435. HiiSetString (mHiiHandle, STR_PROCESSOR_L2_CACHE_VALUE, NewString, NULL);
  436. break;
  437. default:
  438. break;
  439. }
  440. HiiSetString (mHiiHandle, STR_PROCESSOR_MICROCODE_VALUE, NewString, NULL);
  441. }
  442. if (SmbiosRecord->Type == EFI_SMBIOS_TYPE_MEMORY_DEVICE) {
  443. Type17Record = (SMBIOS_TABLE_TYPE17 *) SmbiosRecord;
  444. if (Type17Record->Size > 0) {
  445. if ((Type17Record->Size & BIT15) != 0) {
  446. //
  447. // Size is in KB
  448. //
  449. TotalMemorySize = TotalMemorySize + Type17Record->Size;
  450. } else {
  451. //
  452. // Size is in MB
  453. //
  454. TotalMemorySize = TotalMemorySize + (UINTN)LShiftU64 (Type17Record->Size, 10);
  455. }
  456. if (Type17Record->Speed < MemorySpeed) {
  457. MemorySpeed = Type17Record->Speed;
  458. }
  459. }
  460. }
  461. if (SmbiosRecord->Type == EFI_SMBIOS_TYPE_BIOS_INFORMATION) {
  462. Type0Record = (SMBIOS_TABLE_TYPE0 *) SmbiosRecord;
  463. StrIndex = Type0Record->BiosVersion;
  464. GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type0Record + Type0Record->Hdr.Length), StrIndex, &BiosVersion);
  465. TokenToUpdate = STRING_TOKEN (STR_BIOS_VERSION_VALUE);
  466. for (SearchIndex = 0x0; SearchIndex < SMBIOS_STRING_MAX_LENGTH; SearchIndex++) {
  467. if (BiosVersion[SearchIndex] == 0x0020) {
  468. BiosVersion[SearchIndex] = 0x0000;
  469. IfwiVersion = (CHAR16 *)(&BiosVersion[SearchIndex+1]);
  470. break;
  471. } else if (BiosVersion[SearchIndex] == 0x0000) {
  472. break;
  473. }
  474. }
  475. HiiSetString (mHiiHandle, TokenToUpdate, BiosVersion, NULL);
  476. //
  477. // Check IfwiVersion, to avoid no IFWI version in SMBIOS Type 0 strucntion
  478. //
  479. if(IfwiVersion) {
  480. TokenToUpdate = STRING_TOKEN (STR_IFWI_VERSION_VALUE);
  481. HiiSetString (mHiiHandle, TokenToUpdate, IfwiVersion, NULL);
  482. }
  483. }
  484. } while (!EFI_ERROR(Status));
  485. if ((TotalMemorySize % 1024) != 0) {
  486. UnicodeSPrint (NewString, sizeof (NewString), L"%d.%d GB", TotalMemorySize / 1024, ((TotalMemorySize % 1024) * 100) / 1024);
  487. } else {
  488. UnicodeSPrint (NewString, sizeof (NewString), L"%d GB", TotalMemorySize / 1024);
  489. }
  490. HiiSetString (mHiiHandle, STR_TOTAL_MEMORY_SIZE_VALUE, NewString, NULL);
  491. UnicodeSPrint (NewString, sizeof (NewString), L"%d MHz", MemorySpeed);
  492. HiiSetString(mHiiHandle, STR_SYSTEM_MEMORY_SPEED_VALUE, NewString, NULL);
  493. UpdateLatestBootTime();
  494. return EFI_SUCCESS;
  495. }
  496. VOID
  497. UpdateCPUInformation ()
  498. {
  499. CHAR16 Buffer[40];
  500. UINT16 FamilyId;
  501. UINT8 Model;
  502. UINT8 SteppingId;
  503. UINT8 ProcessorType;
  504. EFI_STATUS Status;
  505. EFI_MP_SERVICES_PROTOCOL *MpService;
  506. UINTN MaximumNumberOfCPUs;
  507. UINTN NumberOfEnabledCPUs;
  508. UINT32 Buffer32 = 0xFFFFFFFF; // Keep buffer with unknown device
  509. EfiCpuVersion (&FamilyId, &Model, &SteppingId, &ProcessorType);
  510. //
  511. //we need raw Model data
  512. //
  513. Model = Model & 0xf;
  514. //
  515. //Family/Model/Step
  516. //
  517. UnicodeSPrint (Buffer, sizeof (Buffer), L"%d/%d/%d", FamilyId, Model, SteppingId);
  518. HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_ID_VALUE), Buffer, NULL);
  519. Status = gBS->LocateProtocol (
  520. &gEfiMpServiceProtocolGuid,
  521. NULL,
  522. (void **)&MpService
  523. );
  524. if (!EFI_ERROR (Status)) {
  525. //
  526. // Determine the number of processors
  527. //
  528. MpService->GetNumberOfProcessors (
  529. MpService,
  530. &MaximumNumberOfCPUs,
  531. &NumberOfEnabledCPUs
  532. );
  533. UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", MaximumNumberOfCPUs);
  534. HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_CORE_VALUE), Buffer, NULL);
  535. }
  536. //
  537. // Update Mobile / Desktop / Tablet SKU
  538. //
  539. Buffer32 =(UINT32) RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
  540. switch(Buffer32){
  541. case 0x0:
  542. UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - ISG SKU SOC", Buffer32);
  543. break;
  544. case 0x01:
  545. UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
  546. break;
  547. case 0x02:
  548. UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Desktop SKU SOC", Buffer32);
  549. break;
  550. case 0x03:
  551. UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
  552. break;
  553. default:
  554. UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Unknown SKU SOC", Buffer32);
  555. break;
  556. }
  557. HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_SKU_VALUE), Buffer, NULL);
  558. }
  559. EFI_STATUS
  560. SearchChildHandle(
  561. EFI_HANDLE Father,
  562. EFI_HANDLE *Child
  563. )
  564. {
  565. EFI_STATUS Status;
  566. UINTN HandleIndex;
  567. EFI_GUID **ProtocolGuidArray = NULL;
  568. UINTN ArrayCount;
  569. UINTN ProtocolIndex;
  570. UINTN OpenInfoCount;
  571. UINTN OpenInfoIndex;
  572. EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo = NULL;
  573. UINTN mHandleCount;
  574. EFI_HANDLE *mHandleBuffer= NULL;
  575. //
  576. // Retrieve the list of all handles from the handle database
  577. //
  578. Status = gBS->LocateHandleBuffer (
  579. AllHandles,
  580. NULL,
  581. NULL,
  582. &mHandleCount,
  583. &mHandleBuffer
  584. );
  585. for (HandleIndex = 0; HandleIndex < mHandleCount; HandleIndex++)
  586. {
  587. //
  588. // Retrieve the list of all the protocols on each handle
  589. //
  590. Status = gBS->ProtocolsPerHandle (
  591. mHandleBuffer[HandleIndex],
  592. &ProtocolGuidArray,
  593. &ArrayCount
  594. );
  595. if (!EFI_ERROR (Status))
  596. {
  597. for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++)
  598. {
  599. Status = gBS->OpenProtocolInformation (
  600. mHandleBuffer[HandleIndex],
  601. ProtocolGuidArray[ProtocolIndex],
  602. &OpenInfo,
  603. &OpenInfoCount
  604. );
  605. if (!EFI_ERROR (Status))
  606. {
  607. for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++)
  608. {
  609. if(OpenInfo[OpenInfoIndex].AgentHandle == Father)
  610. {
  611. if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER)
  612. {
  613. *Child = mHandleBuffer[HandleIndex];
  614. Status = EFI_SUCCESS;
  615. goto TryReturn;
  616. }
  617. }
  618. }
  619. Status = EFI_NOT_FOUND;
  620. }
  621. }
  622. if(OpenInfo != NULL)
  623. {
  624. FreePool(OpenInfo);
  625. OpenInfo = NULL;
  626. }
  627. }
  628. FreePool (ProtocolGuidArray);
  629. ProtocolGuidArray = NULL;
  630. }
  631. TryReturn:
  632. if(OpenInfo != NULL)
  633. {
  634. FreePool (OpenInfo);
  635. OpenInfo = NULL;
  636. }
  637. if(ProtocolGuidArray != NULL)
  638. {
  639. FreePool(ProtocolGuidArray);
  640. ProtocolGuidArray = NULL;
  641. }
  642. if(mHandleBuffer != NULL)
  643. {
  644. FreePool (mHandleBuffer);
  645. mHandleBuffer = NULL;
  646. }
  647. return Status;
  648. }
  649. EFI_STATUS
  650. JudgeHandleIsPCIDevice(
  651. EFI_HANDLE Handle,
  652. UINT8 Device,
  653. UINT8 Funs
  654. )
  655. {
  656. EFI_STATUS Status;
  657. EFI_DEVICE_PATH *DPath;
  658. Status = gBS->HandleProtocol (
  659. Handle,
  660. &gEfiDevicePathProtocolGuid,
  661. (VOID **) &DPath
  662. );
  663. if(!EFI_ERROR(Status))
  664. {
  665. while(!IsDevicePathEnd(DPath))
  666. {
  667. if((DPath->Type == HARDWARE_DEVICE_PATH) && (DPath->SubType == HW_PCI_DP))
  668. {
  669. PCI_DEVICE_PATH *PCIPath;
  670. PCIPath = (PCI_DEVICE_PATH*) DPath;
  671. DPath = NextDevicePathNode(DPath);
  672. if(IsDevicePathEnd(DPath) && (PCIPath->Device == Device) && (PCIPath->Function == Funs))
  673. {
  674. return EFI_SUCCESS;
  675. }
  676. }
  677. else
  678. {
  679. DPath = NextDevicePathNode(DPath);
  680. }
  681. }
  682. }
  683. return EFI_UNSUPPORTED;
  684. }
  685. EFI_STATUS
  686. GetDriverName(
  687. EFI_HANDLE Handle,
  688. CHAR16 *Name
  689. )
  690. {
  691. EFI_DRIVER_BINDING_PROTOCOL *BindHandle = NULL;
  692. EFI_STATUS Status;
  693. UINT32 Version;
  694. UINT16 *Ptr;
  695. Status = gBS->OpenProtocol(
  696. Handle,
  697. &gEfiDriverBindingProtocolGuid,
  698. (VOID**)&BindHandle,
  699. NULL,
  700. NULL,
  701. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  702. );
  703. if (EFI_ERROR(Status))
  704. {
  705. return EFI_NOT_FOUND;
  706. }
  707. Version = BindHandle->Version;
  708. Ptr = (UINT16*)&Version;
  709. UnicodeSPrint(Name, 40, L"%d.%d.%d", Version >> 24 , (Version >>16)& 0x0f ,*(Ptr));
  710. return EFI_SUCCESS;
  711. }
  712. EFI_STATUS
  713. GetGOPDriverName(
  714. CHAR16 *Name
  715. )
  716. {
  717. UINTN HandleCount;
  718. EFI_HANDLE *Handles= NULL;
  719. UINTN Index;
  720. EFI_STATUS Status;
  721. EFI_HANDLE Child = 0;
  722. Status = gBS->LocateHandleBuffer(
  723. ByProtocol,
  724. &gEfiDriverBindingProtocolGuid,
  725. NULL,
  726. &HandleCount,
  727. &Handles
  728. );
  729. for (Index = 0; Index < HandleCount ; Index++)
  730. {
  731. Status = SearchChildHandle(Handles[Index], &Child);
  732. if(!EFI_ERROR(Status))
  733. {
  734. Status = JudgeHandleIsPCIDevice(
  735. Child,
  736. 0x02,
  737. 0x00
  738. );
  739. if(!EFI_ERROR(Status))
  740. {
  741. return GetDriverName(Handles[Index], Name);
  742. }
  743. }
  744. }
  745. return EFI_UNSUPPORTED;
  746. }
  747. EFI_STATUS
  748. UpdatePlatformInformation (
  749. )
  750. {
  751. UINT32 MicroCodeVersion;
  752. CHAR16 Buffer[40];
  753. EFI_STATUS Status;
  754. UINT8 CpuFlavor=0;
  755. EFI_PEI_HOB_POINTERS GuidHob;
  756. UINTN NumHandles;
  757. EFI_HANDLE *HandleBuffer;
  758. UINTN Index;
  759. DXE_PCH_PLATFORM_POLICY_PROTOCOL *PchPlatformPolicy;
  760. UINTN PciD31F0RegBase;
  761. UINT8 count;
  762. UINT8 Data8;
  763. UINT8 PIDData8;
  764. CHAR16 Name[40];
  765. UINT32 MrcVersion;
  766. //
  767. // Get the HOB list. If it is not present, then ASSERT.
  768. //
  769. GuidHob.Raw = GetHobList ();
  770. if (GuidHob.Raw != NULL) {
  771. if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
  772. mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
  773. }
  774. }
  775. Status = GetGOPDriverName(Name);
  776. if (!EFI_ERROR(Status))
  777. {
  778. HiiSetString(mHiiHandle, STRING_TOKEN(STR_GOP_VALUE), Name, NULL);
  779. }
  780. //
  781. // CpuFlavor
  782. // ISG-DC Tablet 000
  783. // VLV-QC Tablet 001
  784. // VLV-QC Desktop 010
  785. // VLV-QC Notebook 011
  786. //
  787. CpuFlavor = RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
  788. switch(CpuFlavor){
  789. case 0x0:
  790. UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-DC Tablet", CpuFlavor);
  791. break;
  792. case 0x01:
  793. UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
  794. break;
  795. case 0x02:
  796. UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Desktop", CpuFlavor);
  797. break;
  798. case 0x03:
  799. UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
  800. break;
  801. default:
  802. UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"Unknown CPU", CpuFlavor);
  803. break;
  804. }
  805. HiiSetString(mHiiHandle,STRING_TOKEN(STR_CPU_FLAVOR_VALUE), Buffer, NULL);
  806. if ( NULL != mPlatformInfo) {
  807. //
  808. //BoardId
  809. //
  810. switch(mPlatformInfo->BoardId){
  811. case 0x2:
  812. UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE RVP(%02x)", mPlatformInfo->BoardId);
  813. break;
  814. case 0x4:
  815. UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFRD(%02x)", mPlatformInfo->BoardId);
  816. break;
  817. case 0x5:
  818. UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY ROCK RVP DDR3L (%02x)", mPlatformInfo->BoardId);
  819. break;
  820. case 0x20:
  821. UnicodeSPrint (Buffer, sizeof (Buffer), L"BAYLEY BAY (%02x)", mPlatformInfo->BoardId);
  822. break;
  823. case 0x30:
  824. UnicodeSPrint (Buffer, sizeof (Buffer), L"BAKER SPORT (%02x)", mPlatformInfo->BoardId);
  825. break;
  826. case 0x0:
  827. UnicodeSPrint (Buffer, sizeof (Buffer), L"ALPINE VALLEY (%x)", mPlatformInfo->BoardId);
  828. break;
  829. case 0x3:
  830. UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFD8 (%x)", mPlatformInfo->BoardId);
  831. break;
  832. default:
  833. UnicodeSPrint (Buffer, sizeof (Buffer), L"Unknown BOARD (%02x)", mPlatformInfo->BoardId);
  834. break;
  835. }
  836. HiiSetString(mHiiHandle,STRING_TOKEN(STR_BOARD_ID_VALUE), Buffer, NULL);
  837. //
  838. // Get Board FAB ID Info from protocol, update into the NVS area.
  839. // bit0~bit3 are for Fab ID, 0x0F means unknow FAB.
  840. //
  841. if(mPlatformInfo->BoardRev == 0x0F) {
  842. UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", L"Unknown FAB");
  843. HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
  844. } else {
  845. UnicodeSPrint (Buffer, sizeof (Buffer), L"%2x", mPlatformInfo->BoardRev);
  846. HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
  847. }
  848. }
  849. //
  850. //Update MRC Version
  851. //
  852. MrcVersion = 0x00000000;
  853. MrcVersion &= 0xffff;
  854. Index = EfiValueToString (Buffer, MrcVersion/100, PREFIX_ZERO, 0);
  855. StrCat (Buffer, L".");
  856. EfiValueToString (Buffer + Index + 1, (MrcVersion%100)/10, PREFIX_ZERO, 0);
  857. EfiValueToString (Buffer + Index + 2, (MrcVersion%100)%10, PREFIX_ZERO, 0);
  858. HiiSetString(mHiiHandle,STRING_TOKEN(STR_MRC_VERSION_VALUE), Buffer, NULL);
  859. //
  860. //Update Soc Version
  861. //
  862. //
  863. // Retrieve all instances of PCH Platform Policy protocol
  864. //
  865. Status = gBS->LocateHandleBuffer (
  866. ByProtocol,
  867. &gDxePchPlatformPolicyProtocolGuid,
  868. NULL,
  869. &NumHandles,
  870. &HandleBuffer
  871. );
  872. if (!EFI_ERROR (Status)) {
  873. //
  874. // Find the matching PCH Policy protocol
  875. //
  876. for (Index = 0; Index < NumHandles; Index++) {
  877. Status = gBS->HandleProtocol (
  878. HandleBuffer[Index],
  879. &gDxePchPlatformPolicyProtocolGuid,
  880. (void **)&PchPlatformPolicy
  881. );
  882. if (!EFI_ERROR (Status)) {
  883. PciD31F0RegBase = MmPciAddress (
  884. 0,
  885. PchPlatformPolicy->BusNumber,
  886. PCI_DEVICE_NUMBER_PCH_LPC,
  887. PCI_FUNCTION_NUMBER_PCH_LPC,
  888. 0
  889. );
  890. Data8 = MmioRead8 (PciD31F0RegBase + R_PCH_LPC_RID_CC);
  891. count = ARRAY_SIZE (SBRevisionTable);
  892. for (Index = 0; Index < count; Index++) {
  893. if(Data8 == SBRevisionTable[Index].RevId) {
  894. UnicodeSPrint (Buffer, sizeof (Buffer), L"%02x %a", Data8, SBRevisionTable[Index].String);
  895. HiiSetString(mHiiHandle,STRING_TOKEN(STR_SOC_VALUE), Buffer, NULL);
  896. break;
  897. }
  898. }
  899. break;
  900. }
  901. }
  902. }
  903. //
  904. // Microcode Revision
  905. //
  906. EfiWriteMsr (EFI_MSR_IA32_BIOS_SIGN_ID, 0);
  907. EfiCpuid (EFI_CPUID_VERSION_INFO, NULL);
  908. MicroCodeVersion = (UINT32) RShiftU64 (EfiReadMsr (EFI_MSR_IA32_BIOS_SIGN_ID), 32);
  909. UnicodeSPrint (Buffer, sizeof (Buffer), L"%x", MicroCodeVersion);
  910. HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_MICROCODE_VALUE), Buffer, NULL);
  911. //
  912. // Punit Version
  913. //
  914. Data8 = 0;
  915. UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%x", Data8);
  916. HiiSetString(mHiiHandle,STRING_TOKEN(STR_PUNIT_FW_VALUE), Buffer, NULL);
  917. //
  918. // PMC Version
  919. //
  920. Data8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>16)&0x00FF);
  921. PIDData8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>24)&0x00FF);
  922. UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%X_%X",PIDData8, Data8);
  923. HiiSetString(mHiiHandle,STRING_TOKEN(STR_PMC_FW_VALUE), Buffer, NULL);
  924. return EFI_SUCCESS;
  925. }
  926. /**
  927. Update SATA Drivesize Strings for Setup and Boot order
  928. @param NewString - pointer to string.
  929. @param DeviceSpeed - speed of drive.
  930. **/
  931. VOID
  932. GetDeviceSpeedString (
  933. CHAR16 *NewString,
  934. IN UINTN DeviceSpeed
  935. )
  936. {
  937. if (DeviceSpeed == 0x01) {
  938. StrCat (NewString, L"1.5Gb/s");
  939. } else if (DeviceSpeed == 0x02) {
  940. StrCat (NewString, L"3.0Gb/s");
  941. } else if (DeviceSpeed == 0x03) {
  942. StrCat (NewString, L"6.0Gb/s");
  943. } else if (DeviceSpeed == 0x0) {
  944. }
  945. }
  946. UINT8
  947. GetChipsetSataPortSpeed (
  948. UINTN PortNum
  949. )
  950. {
  951. UINT32 DeviceSpeed;
  952. UINT8 DeviceConfigStatus;
  953. UINT32 IdeAhciBar;
  954. EFI_PHYSICAL_ADDRESS MemBaseAddress = 0;
  955. UINT8 FunNum;
  956. DeviceSpeed = 0x01; // generation 1
  957. //
  958. // Allocate the AHCI BAR
  959. //
  960. FunNum = PCI_FUNCTION_NUMBER_PCH_SATA;
  961. MemBaseAddress = 0x0ffffffff;
  962. gDS->AllocateMemorySpace (
  963. EfiGcdAllocateMaxAddressSearchBottomUp,
  964. EfiGcdMemoryTypeMemoryMappedIo,
  965. N_PCH_SATA_ABAR_ALIGNMENT, // 2^11: 2K Alignment
  966. V_PCH_SATA_ABAR_LENGTH, // 2K Length
  967. &MemBaseAddress,
  968. mImageHandle,
  969. NULL
  970. );
  971. IdeAhciBar = MmioRead32 (
  972. MmPciAddress (
  973. 0,
  974. 0,
  975. PCI_DEVICE_NUMBER_PCH_SATA,
  976. FunNum,
  977. R_PCH_SATA_ABAR
  978. )
  979. );
  980. IdeAhciBar &= 0xFFFFF800;
  981. DeviceConfigStatus = 0;
  982. if (IdeAhciBar == 0) {
  983. DeviceConfigStatus = 1;
  984. IdeAhciBar = (UINT32)MemBaseAddress;
  985. MmioWrite32 (
  986. MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
  987. IdeAhciBar
  988. );
  989. MmioOr16 (
  990. MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_COMMAND),
  991. B_PCH_SATA_COMMAND_MSE
  992. );
  993. }
  994. if (mSystemConfiguration.SataType == PCH_SATA_MODE_IDE){
  995. //
  996. // Program the "Ports Implemented Register"
  997. //
  998. 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));
  999. }
  1000. switch (PortNum)
  1001. {
  1002. case 0:
  1003. DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P0SSTS);
  1004. break;
  1005. case 1:
  1006. DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P1SSTS);
  1007. break;
  1008. }
  1009. if (MemBaseAddress) {
  1010. gDS->FreeMemorySpace (
  1011. MemBaseAddress,
  1012. V_PCH_SATA_ABAR_LENGTH
  1013. );
  1014. }
  1015. if (DeviceConfigStatus) {
  1016. IdeAhciBar = 0;
  1017. MmioWrite32 (
  1018. MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
  1019. IdeAhciBar
  1020. );
  1021. }
  1022. DeviceSpeed = (UINT8)((DeviceSpeed >> 4) & 0x0F);
  1023. return (UINT8)DeviceSpeed;
  1024. }
  1025. /**
  1026. IDE data filter function.
  1027. **/
  1028. void
  1029. IdeDataFilter (void)
  1030. {
  1031. EFI_STATUS Status;
  1032. UINTN HandleCount;
  1033. EFI_HANDLE *HandleBuffer;
  1034. EFI_DISK_INFO_PROTOCOL *DiskInfo;
  1035. EFI_DEVICE_PATH_PROTOCOL *DevicePath, *DevicePathNode;
  1036. PCI_DEVICE_PATH *PciDevicePath;
  1037. UINTN Index;
  1038. UINT8 Index1;
  1039. UINT32 BufferSize;
  1040. UINT32 DriveSize;
  1041. UINT32 IdeChannel;
  1042. UINT32 IdeDevice;
  1043. EFI_ATA_IDENTIFY_DATA *IdentifyDriveInfo;
  1044. CHAR16 *NewString;
  1045. CHAR16 SizeString[20];
  1046. STRING_REF NameToUpdate;
  1047. CHAR8 StringBuffer[0x100];
  1048. UINT32 DeviceSpeed;
  1049. UINTN PortNumber;
  1050. //
  1051. // Assume no line strings is longer than 256 bytes.
  1052. //
  1053. NewString = AllocateZeroPool (0x100);
  1054. PciDevicePath = NULL;
  1055. //
  1056. // Fill IDE Infomation
  1057. //
  1058. Status = gBS->LocateHandleBuffer (
  1059. ByProtocol,
  1060. &gEfiDiskInfoProtocolGuid,
  1061. NULL,
  1062. &HandleCount,
  1063. &HandleBuffer
  1064. );
  1065. if (EFI_ERROR (Status)) {
  1066. return;
  1067. }
  1068. for (Index = 0; Index < HandleCount; Index++) {
  1069. Status = gBS->HandleProtocol (
  1070. HandleBuffer[Index],
  1071. &gEfiDevicePathProtocolGuid,
  1072. (VOID*)&DevicePath
  1073. );
  1074. ASSERT_EFI_ERROR (Status);
  1075. DevicePathNode = DevicePath;
  1076. while (!IsDevicePathEnd (DevicePathNode) ) {
  1077. if ((DevicePathType (DevicePathNode) == HARDWARE_DEVICE_PATH) &&
  1078. ( DevicePathSubType (DevicePathNode) == HW_PCI_DP)) {
  1079. PciDevicePath = (PCI_DEVICE_PATH *) DevicePathNode;
  1080. break;
  1081. }
  1082. DevicePathNode = NextDevicePathNode (DevicePathNode);
  1083. }
  1084. if (PciDevicePath == NULL) {
  1085. continue;
  1086. }
  1087. //
  1088. // Check for onboard IDE
  1089. //
  1090. if (PciDevicePath->Device== PCI_DEVICE_NUMBER_PCH_SATA) {
  1091. Status = gBS->HandleProtocol (
  1092. HandleBuffer[Index],
  1093. &gEfiDiskInfoProtocolGuid,
  1094. (void **)&DiskInfo
  1095. );
  1096. ASSERT_EFI_ERROR (Status);
  1097. Status = DiskInfo->WhichIde (
  1098. DiskInfo,
  1099. &IdeChannel,
  1100. &IdeDevice
  1101. );
  1102. ASSERT_EFI_ERROR (Status);
  1103. IdentifyDriveInfo = AllocatePool (sizeof(EFI_ATA_IDENTIFY_DATA));
  1104. BufferSize = sizeof(EFI_ATA_IDENTIFY_DATA);
  1105. Status = DiskInfo->Identify (
  1106. DiskInfo,
  1107. IdentifyDriveInfo,
  1108. &BufferSize
  1109. );
  1110. ASSERT_EFI_ERROR(Status);
  1111. //
  1112. // Onboard SATA Devices
  1113. //
  1114. if (PciDevicePath->Function == PCI_FUNCTION_NUMBER_PCH_SATA) {
  1115. if (IdeChannel == 0 && IdeDevice == 0) {
  1116. NameToUpdate = (STRING_REF)STR_SATA0_NAME;
  1117. } else if (IdeChannel == 1 && IdeDevice == 0) {
  1118. NameToUpdate = (STRING_REF)STR_SATA1_NAME;
  1119. } else {
  1120. continue;
  1121. }
  1122. } else {
  1123. continue;
  1124. }
  1125. ZeroMem(StringBuffer, sizeof(StringBuffer));
  1126. CopyMem(
  1127. StringBuffer,
  1128. (CHAR8 *)&IdentifyDriveInfo->ModelName,
  1129. sizeof(IdentifyDriveInfo->ModelName)
  1130. );
  1131. SwapEntries(StringBuffer);
  1132. AsciiToUnicode(StringBuffer, NewString);
  1133. //
  1134. // Chap it off after 16 characters
  1135. //
  1136. NewString[16] = 0;
  1137. //
  1138. // For HardDisk append the size. Otherwise display atapi
  1139. //
  1140. if ((IdentifyDriveInfo->config & 0x8000) == 00) {
  1141. //
  1142. // 48 bit address feature set is supported, get maximum capacity
  1143. //
  1144. if ((IdentifyDriveInfo->command_set_supported_83 & 0x0400) == 0) {
  1145. DriveSize = (((((IdentifyDriveInfo->user_addressable_sectors_hi << 16) +
  1146. IdentifyDriveInfo->user_addressable_sectors_lo) / 1000) * 512) / 1000);
  1147. } else {
  1148. DriveSize = IdentifyDriveInfo->maximum_lba_for_48bit_addressing[0];
  1149. for (Index1 = 1; Index1 < 4; Index1++) {
  1150. //
  1151. // Lower byte goes first: word[100] is the lowest word, word[103] is highest
  1152. //
  1153. DriveSize |= LShiftU64(IdentifyDriveInfo->maximum_lba_for_48bit_addressing[Index1], 16 * Index1);
  1154. }
  1155. DriveSize = (UINT32) DivU64x32(MultU64x32(DivU64x32(DriveSize, 1000), 512), 1000);
  1156. }
  1157. StrCat (NewString, L"(");
  1158. EfiValueToString (SizeString, DriveSize/1000, PREFIX_BLANK, 0);
  1159. StrCat (NewString, SizeString);
  1160. StrCat (NewString, L".");
  1161. EfiValueToString (SizeString, (DriveSize%1000)/100, PREFIX_BLANK, 0);
  1162. StrCat (NewString, SizeString);
  1163. StrCat (NewString, L"GB");
  1164. } else {
  1165. StrCat (NewString, L"(ATAPI");
  1166. }
  1167. //
  1168. // Update SPEED.
  1169. //
  1170. PortNumber = (IdeDevice << 1) + IdeChannel;
  1171. DeviceSpeed = GetChipsetSataPortSpeed(PortNumber);
  1172. if (DeviceSpeed) {
  1173. StrCat (NewString, L"-");
  1174. GetDeviceSpeedString( NewString, DeviceSpeed);
  1175. }
  1176. StrCat (NewString, L")");
  1177. HiiSetString(mHiiHandle, NameToUpdate, NewString, NULL);
  1178. }
  1179. }
  1180. if (HandleBuffer != NULL) {
  1181. gBS->FreePool (HandleBuffer);
  1182. }
  1183. gBS->FreePool(NewString);
  1184. return;
  1185. }
  1186. VOID
  1187. EFIAPI
  1188. SetupInfo (void)
  1189. {
  1190. EFI_STATUS Status;
  1191. UINTN VarSize;
  1192. EFI_PEI_HOB_POINTERS GuidHob;
  1193. if (mSetupInfoDone) {
  1194. return;
  1195. }
  1196. VarSize = sizeof(SYSTEM_CONFIGURATION);
  1197. Status = gRT->GetVariable(
  1198. NORMAL_SETUP_NAME,
  1199. &gEfiNormalSetupGuid,
  1200. NULL,
  1201. &VarSize,
  1202. &mSystemConfiguration
  1203. );
  1204. if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
  1205. //The setup variable is corrupted
  1206. VarSize = sizeof(SYSTEM_CONFIGURATION);
  1207. Status = gRT->GetVariable(
  1208. L"SetupRecovery",
  1209. &gEfiNormalSetupGuid,
  1210. NULL,
  1211. &VarSize,
  1212. &mSystemConfiguration
  1213. );
  1214. ASSERT_EFI_ERROR (Status);
  1215. }
  1216. //
  1217. // Update HOB variable for PCI resource information
  1218. // Get the HOB list. If it is not present, then ASSERT.
  1219. //
  1220. GuidHob.Raw = GetHobList ();
  1221. if (GuidHob.Raw != NULL) {
  1222. if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
  1223. mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
  1224. }
  1225. }
  1226. PrepareSetupInformation();
  1227. UpdateAdditionalInformation ();
  1228. UpdatePlatformInformation();
  1229. UpdateCPUInformation();
  1230. IdeDataFilter();
  1231. mSetupInfoDone = TRUE;
  1232. return;
  1233. }
  1234. #define EFI_SECURE_BOOT_MODE_NAME L"SecureBoot"
  1235. VOID
  1236. CheckSystemConfigLoad(SYSTEM_CONFIGURATION *SystemConfigPtr)
  1237. {
  1238. EFI_STATUS Status;
  1239. UINT8 SecureBoot;
  1240. UINTN DataSize;
  1241. DataSize = sizeof(SecureBoot);
  1242. Status = gRT->GetVariable (
  1243. EFI_SECURE_BOOT_MODE_NAME,
  1244. &gEfiGlobalVariableGuid,
  1245. NULL,
  1246. &DataSize,
  1247. &SecureBoot
  1248. );
  1249. if (EFI_ERROR(Status)) {
  1250. SystemConfigPtr->SecureBoot = 0;
  1251. } else {
  1252. SystemConfigPtr->SecureBoot = SecureBoot;
  1253. }
  1254. }
  1255. VOID
  1256. CheckSystemConfigSave(SYSTEM_CONFIGURATION *SystemConfigPtr)
  1257. {
  1258. }
  1259. VOID
  1260. ConfirmSecureBootTest()
  1261. {
  1262. }