SetupInfoRecords.c 42 KB

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