PeiWhiskeylakeURvpInitPostMemLib.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /** @file
  2. Copyright (c) 2019 - 2020 Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include <PiPei.h>
  6. #include <SaPolicyCommon.h>
  7. #include <Library/DebugLib.h>
  8. #include <Library/BaseMemoryLib.h>
  9. #include <Library/HdaVerbTableLib.h>
  10. #include <Library/IoLib.h>
  11. #include <Library/HobLib.h>
  12. #include <Library/PcdLib.h>
  13. #include <Library/PchCycleDecodingLib.h>
  14. #include <Library/PciLib.h>
  15. #include <Library/PeiSaPolicyLib.h>
  16. #include <Library/BoardInitLib.h>
  17. #include <PchAccess.h>
  18. #include <Library/GpioNativeLib.h>
  19. #include <Library/GpioLib.h>
  20. #include <GpioPinsSklLp.h>
  21. #include <GpioPinsSklH.h>
  22. #include <Library/GpioExpanderLib.h>
  23. #include <SioRegs.h>
  24. #include <Library/PchPcrLib.h>
  25. #include <IoExpander.h>
  26. #include <AttemptUsbFirst.h>
  27. #include <PeiPlatformHookLib.h>
  28. #include <Library/PeiPolicyInitLib.h>
  29. #include <Library/PchInfoLib.h>
  30. #include <FirwmareConfigurations.h>
  31. #include "WhiskeylakeURvpInit.h"
  32. #include <Library/ConfigBlockLib.h>
  33. EFI_STATUS
  34. BoardFunctionInit (
  35. IN UINT16 BoardId
  36. );
  37. /**
  38. GPIO init function for PEI post memory phase.
  39. @param[in] BoardId An unsigned integrer represent the board id.
  40. @retval EFI_SUCCESS The function completed successfully.
  41. **/
  42. EFI_STATUS
  43. BoardGpioInit(
  44. IN UINT16 BoardId
  45. )
  46. {
  47. //
  48. // GPIO Table Init.
  49. //
  50. switch (BoardId) {
  51. case BoardIdWhiskeyLakeRvp:
  52. PcdSet32S (PcdBoardGpioTable, (UINTN) mGpioTableWhlUDdr4_0);
  53. PcdSet16S (PcdBoardGpioTableSize, mGpioTableWhlUDdr4_0Size);
  54. PcdSet32S (PcdBoardGpioTable2, (UINTN) mGpioTableWhlUDdr4);
  55. PcdSet16S (PcdBoardGpioTable2Size, mGpioTableWhlUDdr4Size);
  56. break;
  57. default:
  58. DEBUG ((DEBUG_INFO, "For Unknown Board ID..Use Default GPIO Table...\n"));
  59. PcdSet32S (PcdBoardGpioTable, (UINTN) mGpioTableDefault);
  60. PcdSet16S (PcdBoardGpioTableSize, mGpioTableDefaultSize);
  61. break;
  62. }
  63. return EFI_SUCCESS;
  64. }
  65. /**
  66. Touch panel GPIO init function for PEI post memory phase.
  67. @param[in] BoardId An unsigned integrer represent the board id.
  68. @retval EFI_SUCCESS The function completed successfully.
  69. **/
  70. EFI_STATUS
  71. TouchPanelGpioInit (
  72. IN UINT16 BoardId
  73. )
  74. {
  75. switch (BoardId) {
  76. default:
  77. PcdSet32S (PcdBoardGpioTableTouchPanel, 0);
  78. break;
  79. }
  80. return EFI_SUCCESS;
  81. }
  82. /**
  83. Misc. init function for PEI post memory phase.
  84. @param[in] BoardId An unsigned integrer represent the board id.
  85. @retval EFI_SUCCESS The function completed successfully.
  86. **/
  87. EFI_STATUS
  88. BoardMiscInit (
  89. IN UINT16 BoardId
  90. )
  91. {
  92. PcdSetBoolS (PcdDebugUsbUartEnable, FALSE);
  93. switch (BoardId) {
  94. case BoardIdWhiskeyLakeRvp:
  95. PcdSetBoolS (PcdMipiCamGpioEnable, TRUE);
  96. break;
  97. default:
  98. PcdSetBoolS (PcdMipiCamGpioEnable, FALSE);
  99. break;
  100. }
  101. return EFI_SUCCESS;
  102. }
  103. /**
  104. Security GPIO init function for PEI post memory phase.
  105. @param[in] BoardId An unsigned integrer represent the board id.
  106. @retval EFI_SUCCESS The function completed successfully.
  107. **/
  108. EFI_STATUS
  109. BoardSecurityInit (
  110. IN UINT16 BoardId
  111. )
  112. {
  113. switch (BoardId) {
  114. case BoardIdWhiskeyLakeRvp:
  115. // TPM interrupt connects to GPIO_CNL_H_GPP_A_7
  116. PcdSet32S (PcdTpm2CurrentIrqNum, 0x1F);
  117. break;
  118. }
  119. return EFI_SUCCESS;
  120. }
  121. /**
  122. Board configuration initialization in the post-memory boot phase.
  123. **/
  124. VOID
  125. BoardConfigInit (
  126. VOID
  127. )
  128. {
  129. EFI_STATUS Status;
  130. UINT16 BoardId;
  131. BoardId = BoardIdWhiskeyLakeRvp;
  132. Status = BoardGpioInit (BoardId);
  133. ASSERT_EFI_ERROR (Status);
  134. Status = TouchPanelGpioInit (BoardId);
  135. ASSERT_EFI_ERROR (Status);
  136. Status = HdaVerbTableInit (BoardId);
  137. ASSERT_EFI_ERROR (Status);
  138. Status = BoardMiscInit (BoardId);
  139. ASSERT_EFI_ERROR (Status);
  140. Status = BoardFunctionInit (BoardId);
  141. ASSERT_EFI_ERROR (Status);
  142. Status = BoardSecurityInit (BoardId);
  143. ASSERT_EFI_ERROR (Status);
  144. }
  145. /**
  146. Create the HOB for hotkey status for 'Attempt USB First' feature
  147. @retval EFI_SUCCESS HOB Creating successful.
  148. @retval Others HOB Creating failed.
  149. **/
  150. EFI_STATUS
  151. CreateAttemptUsbFirstHotkeyInfoHob (
  152. VOID
  153. )
  154. {
  155. EFI_STATUS Status;
  156. ATTEMPT_USB_FIRST_HOTKEY_INFO AttemptUsbFirstHotkeyInfo;
  157. Status = EFI_SUCCESS;
  158. ZeroMem (
  159. &AttemptUsbFirstHotkeyInfo,
  160. sizeof (AttemptUsbFirstHotkeyInfo)
  161. );
  162. AttemptUsbFirstHotkeyInfo.RevisonId = 0;
  163. AttemptUsbFirstHotkeyInfo.HotkeyTriggered = FALSE;
  164. ///
  165. /// Build HOB for Attempt USB First feature
  166. ///
  167. BuildGuidDataHob (
  168. &gAttemptUsbFirstHotkeyInfoHobGuid,
  169. &(AttemptUsbFirstHotkeyInfo),
  170. sizeof (ATTEMPT_USB_FIRST_HOTKEY_INFO)
  171. );
  172. return Status;
  173. }
  174. /**
  175. Search and identify the physical address of a
  176. file module inside the FW_BINARIES_FV_SIGNED FV
  177. @retval EFI_SUCCESS If address has been found
  178. @retval Others If address has not been found
  179. **/
  180. EFI_STATUS
  181. FindModuleInFlash2 (
  182. IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,
  183. IN EFI_GUID *GuidPtr,
  184. IN OUT UINT32 *ModulePtr,
  185. IN OUT UINT32 *ModuleSize
  186. )
  187. {
  188. EFI_FFS_FILE_HEADER *FfsHeader;
  189. EFI_FV_FILE_INFO FileInfo;
  190. EFI_PEI_FILE_HANDLE FileHandle;
  191. EFI_COMMON_SECTION_HEADER *SectionHeader;
  192. VOID *FileBuffer;
  193. EFI_STATUS Status;
  194. FfsHeader = NULL;
  195. FileHandle = NULL;
  196. SectionHeader = NULL;
  197. FileBuffer = NULL;
  198. while (TRUE) {
  199. //
  200. // Locate FV_IMAGE file type in the FW_BINARIES_FV_SIGNED firmware volume
  201. //
  202. Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, FvHeader, &FileHandle);
  203. if (EFI_ERROR (Status)) {
  204. // unable to find FV_IMAGE file in this FV
  205. break;
  206. }
  207. FfsHeader = (EFI_FFS_FILE_HEADER*)FileHandle;
  208. DEBUG ((DEBUG_INFO, "FfsHeader 0x%X:\n", FfsHeader));
  209. DEBUG ((DEBUG_INFO, " Name = 0x%g\n", &FfsHeader->Name));
  210. DEBUG ((DEBUG_INFO, " Type = 0x%X\n", FfsHeader->Type));
  211. if (IS_FFS_FILE2 (FfsHeader)) {
  212. DEBUG ((DEBUG_INFO, " Size = 0x%X\n", FFS_FILE2_SIZE(FfsHeader)));
  213. }
  214. else {
  215. DEBUG ((DEBUG_INFO, " Size = 0x%X\n", FFS_FILE_SIZE(FfsHeader)));
  216. }
  217. //
  218. // Locate FW_BINARIES_FV FV_IMAGE Section
  219. //
  220. Status = PeiServicesFfsFindSectionData (EFI_SECTION_FIRMWARE_VOLUME_IMAGE, FileHandle, &FileBuffer);
  221. if (EFI_ERROR (Status)) {
  222. // continue to search for the next FV_IMAGE file
  223. DEBUG ((DEBUG_INFO, "FW_BINARIES_FV section not found. Status = %r\n", Status));
  224. continue;
  225. }
  226. SectionHeader = (EFI_COMMON_SECTION_HEADER *)FileBuffer;
  227. DEBUG ((DEBUG_INFO, "GUIDED SectionHeader 0x%X:\n",
  228. (UINT32)(UINT8 *)SectionHeader));
  229. if (IS_SECTION2(SectionHeader)) {
  230. DEBUG ((DEBUG_INFO, " Guid = 0x%g\n",
  231. &((EFI_GUID_DEFINED_SECTION2 *)SectionHeader)->SectionDefinitionGuid));
  232. DEBUG ((DEBUG_INFO, " DataOfset = 0x%X\n",
  233. ((EFI_GUID_DEFINED_SECTION2 *)SectionHeader)->DataOffset));
  234. }
  235. else {
  236. DEBUG ((DEBUG_INFO, " Guid = 0x%g\n",
  237. &((EFI_GUID_DEFINED_SECTION *)SectionHeader)->SectionDefinitionGuid));
  238. DEBUG ((DEBUG_INFO, " DataOfset = 0x%X\n",
  239. ((EFI_GUID_DEFINED_SECTION *)SectionHeader)->DataOffset));
  240. }
  241. DEBUG ((DEBUG_INFO, " Type = 0x%X\n", SectionHeader->Type));
  242. //
  243. // Locate Firmware File System file within Firmware Volume
  244. //
  245. Status = PeiServicesFfsFindFileByName (GuidPtr, FileBuffer, (VOID **)&FfsHeader);
  246. if (EFI_ERROR (Status)) {
  247. // continue to search for the next FV_IMAGE file
  248. DEBUG ((DEBUG_INFO, "Module not found. Status = %r\n", Status));
  249. continue;
  250. }
  251. *ModulePtr = (UINT32)((UINT8 *)FfsHeader + sizeof(EFI_FFS_FILE_HEADER));
  252. //
  253. // Get File Information
  254. //
  255. Status = PeiServicesFfsGetFileInfo (FfsHeader, &FileInfo);
  256. if (!EFI_ERROR (Status)) {
  257. *ModuleSize = (UINT32)FileInfo.BufferSize;
  258. DEBUG ((DEBUG_INFO, "Module {0x%g} found at = 0x%X, Size = 0x%X\n",
  259. &FfsHeader->Name, *ModulePtr, *ModuleSize));
  260. return Status;
  261. }
  262. }
  263. return EFI_NOT_FOUND;
  264. }
  265. /**
  266. Get the ChipsetInit Binary pointer.
  267. @retval EFI_SUCCESS - ChipsetInit Binary found.
  268. @retval EFI_NOT_FOUND - ChipsetInit Binary not found.
  269. **/
  270. EFI_STATUS
  271. UpdateChipsetInitPtr (
  272. VOID
  273. )
  274. {
  275. EFI_STATUS Status;
  276. PCH_STEPPING PchStep;
  277. EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
  278. EFI_GUID *ChipsetInitBinaryGuidPtr;
  279. SI_POLICY_PPI *SiPolicyPpi;
  280. PCH_HSIO_CONFIG *HsioConfig;
  281. UINT32 ModuleAddr;
  282. UINT32 ModuleSize;
  283. ModuleAddr = 0;
  284. ModuleSize = 0;
  285. PchStep = PchStepping ();
  286. Status = PeiServicesLocatePpi (
  287. &gSiPolicyPpiGuid,
  288. 0,
  289. NULL,
  290. (VOID **)&SiPolicyPpi
  291. );
  292. ASSERT_EFI_ERROR (Status);
  293. Status = GetConfigBlock ((VOID *)SiPolicyPpi, &gHsioConfigGuid, (VOID *)&HsioConfig);
  294. ASSERT_EFI_ERROR (Status);
  295. ChipsetInitBinaryGuidPtr = NULL;
  296. if (IsPchLp()) {
  297. switch (PchStep) {
  298. case PCH_D0:
  299. case PCH_D1:
  300. ChipsetInitBinaryGuidPtr = &gCnlPchLpChipsetInitTableDxGuid;
  301. DEBUG ((DEBUG_INFO, "Using CnlPchLpChipsetInitTable_Dx table \n"));
  302. break;
  303. default:
  304. return EFI_NOT_FOUND;
  305. }
  306. } else {
  307. return EFI_NOT_FOUND;
  308. }
  309. //
  310. // Locate Firmware Volume header
  311. //
  312. FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FixedPcdGet32 (PcdFlashFvPostMemoryBase);
  313. Status = FindModuleInFlash2 (FvHeader, ChipsetInitBinaryGuidPtr, &ModuleAddr, &ModuleSize);
  314. //
  315. // Get ChipsetInit Binary Pointer
  316. //
  317. HsioConfig->ChipsetInitBinPtr = ModuleAddr;
  318. //
  319. // Get File Size
  320. //
  321. HsioConfig->ChipsetInitBinLen = ModuleSize;
  322. DEBUG ((DEBUG_INFO, "ChipsetInit Binary Location: %x\n", HsioConfig->ChipsetInitBinPtr));
  323. DEBUG ((DEBUG_INFO, "ChipsetInit Binary Size: %x\n", HsioConfig->ChipsetInitBinLen));
  324. return Status;
  325. }
  326. /**
  327. Configure GPIO and SIO
  328. @retval EFI_SUCCESS Operation success.
  329. **/
  330. EFI_STATUS
  331. EFIAPI
  332. WhiskeylakeURvpBoardInitBeforeSiliconInit (
  333. VOID
  334. )
  335. {
  336. EFI_STATUS Status;
  337. UINT8 FwConfig;
  338. BoardConfigInit ();
  339. //
  340. // Configure GPIO and SIO
  341. //
  342. Status = BoardInit ();
  343. ASSERT_EFI_ERROR (Status);
  344. FwConfig = FwConfigProduction;
  345. PeiPolicyInit (FwConfig);
  346. //
  347. // Create USB Boot First hotkey information HOB
  348. //
  349. CreateAttemptUsbFirstHotkeyInfoHob ();
  350. //
  351. // Initializing Platform Specific Programming
  352. //
  353. Status = PlatformSpecificInit ();
  354. ASSERT_EFI_ERROR(Status);
  355. //
  356. // Update ChipsetInitPtr
  357. //
  358. Status = UpdateChipsetInitPtr ();
  359. ///
  360. /// Do Late PCH init
  361. ///
  362. LateSiliconInit ();
  363. return EFI_SUCCESS;
  364. }