| 1 | /** @file\r |
| 2 | This will be invoked only once. It will call FspMemoryInit API,\r |
| 3 | register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi\r |
| 4 | notify to call FspSiliconInit API.\r |
| 5 | \r |
| 6 | Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r |
| 7 | This program and the accompanying materials\r |
| 8 | are licensed and made available under the terms and conditions of the BSD License\r |
| 9 | which accompanies this distribution. The full text of the license may be found at\r |
| 10 | http://opensource.org/licenses/bsd-license.php.\r |
| 11 | \r |
| 12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
| 13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
| 14 | \r |
| 15 | **/\r |
| 16 | \r |
| 17 | \r |
| 18 | #include <PiPei.h>\r |
| 19 | \r |
| 20 | #include <Library/PeimEntryPoint.h>\r |
| 21 | #include <Library/PeiServicesLib.h>\r |
| 22 | #include <Library/PeiServicesTablePointerLib.h>\r |
| 23 | #include <Library/BaseLib.h>\r |
| 24 | #include <Library/DebugLib.h>\r |
| 25 | #include <Library/BaseMemoryLib.h>\r |
| 26 | #include <Library/MemoryAllocationLib.h>\r |
| 27 | #include <Library/HobLib.h>\r |
| 28 | #include <Library/PcdLib.h>\r |
| 29 | #include <Library/TimerLib.h>\r |
| 30 | #include <Library/PerformanceLib.h>\r |
| 31 | #include <Library/FspWrapperPlatformLib.h>\r |
| 32 | #include <Library/FspWrapperHobProcessLib.h>\r |
| 33 | #include <Library/FspWrapperApiLib.h>\r |
| 34 | \r |
| 35 | #include <Ppi/FspSiliconInitDone.h>\r |
| 36 | #include <Ppi/EndOfPeiPhase.h>\r |
| 37 | #include <Ppi/MemoryDiscovered.h>\r |
| 38 | #include <Ppi/SecPlatformInformation.h>\r |
| 39 | #include <Library/FspWrapperApiTestLib.h>\r |
| 40 | #include <FspEas.h>\r |
| 41 | #include <FspStatusCode.h>\r |
| 42 | \r |
| 43 | extern EFI_GUID gFspHobGuid;\r |
| 44 | \r |
| 45 | /**\r |
| 46 | Call FspMemoryInit API.\r |
| 47 | \r |
| 48 | @return Status returned by FspMemoryInit API.\r |
| 49 | **/\r |
| 50 | EFI_STATUS\r |
| 51 | PeiFspMemoryInit (\r |
| 52 | VOID\r |
| 53 | )\r |
| 54 | {\r |
| 55 | FSP_INFO_HEADER *FspmHeaderPtr;\r |
| 56 | EFI_STATUS Status;\r |
| 57 | UINT64 TimeStampCounterStart;\r |
| 58 | VOID *FspHobListPtr;\r |
| 59 | VOID *HobData;\r |
| 60 | FSPM_UPD_COMMON *FspmUpdDataPtr;\r |
| 61 | UINTN *SourceData;\r |
| 62 | \r |
| 63 | DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));\r |
| 64 | \r |
| 65 | FspHobListPtr = NULL;\r |
| 66 | FspmUpdDataPtr = NULL;\r |
| 67 | \r |
| 68 | FspmHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));\r |
| 69 | DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr));\r |
| 70 | if (FspmHeaderPtr == NULL) {\r |
| 71 | return EFI_DEVICE_ERROR;\r |
| 72 | }\r |
| 73 | \r |
| 74 | if (PcdGet32 (PcdFspmUpdDataAddress) == 0 && (FspmHeaderPtr->CfgRegionSize != 0) && (FspmHeaderPtr->CfgRegionOffset != 0)) {\r |
| 75 | //\r |
| 76 | // Copy default FSP-M UPD data from Flash\r |
| 77 | //\r |
| 78 | FspmUpdDataPtr = (FSPM_UPD_COMMON *)AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);\r |
| 79 | ASSERT (FspmUpdDataPtr != NULL);\r |
| 80 | SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);\r |
| 81 | CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);\r |
| 82 | } else {\r |
| 83 | //\r |
| 84 | // External UPD is ready, get the buffer from PCD pointer.\r |
| 85 | //\r |
| 86 | FspmUpdDataPtr = (FSPM_UPD_COMMON *)PcdGet32 (PcdFspmUpdDataAddress);\r |
| 87 | ASSERT (FspmUpdDataPtr != NULL);\r |
| 88 | }\r |
| 89 | \r |
| 90 | DEBUG ((DEBUG_INFO, "UpdateFspmUpdData enter\n"));\r |
| 91 | UpdateFspmUpdData ((VOID *)FspmUpdDataPtr);\r |
| 92 | DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.NvsBufferPtr));\r |
| 93 | DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackBase));\r |
| 94 | DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackSize));\r |
| 95 | DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootLoaderTolumSize));\r |
| 96 | DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootMode));\r |
| 97 | DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));\r |
| 98 | \r |
| 99 | TimeStampCounterStart = AsmReadTsc ();\r |
| 100 | Status = CallFspMemoryInit (FspmUpdDataPtr, &FspHobListPtr);\r |
| 101 | // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here\r |
| 102 | PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r |
| 103 | PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r |
| 104 | DEBUG ((DEBUG_INFO, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r |
| 105 | \r |
| 106 | //\r |
| 107 | // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r |
| 108 | //\r |
| 109 | if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r |
| 110 | DEBUG((DEBUG_INFO, "FspMemoryInitApi requested reset 0x%x\n", Status));\r |
| 111 | CallFspWrapperResetSystem ((UINT32)Status);\r |
| 112 | }\r |
| 113 | \r |
| 114 | if (EFI_ERROR(Status)) {\r |
| 115 | DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status));\r |
| 116 | }\r |
| 117 | DEBUG((DEBUG_INFO, "FspMemoryInit status: 0x%x\n", Status));\r |
| 118 | ASSERT_EFI_ERROR (Status);\r |
| 119 | \r |
| 120 | \r |
| 121 | Status = TestFspMemoryInitApiOutput (FspmUpdDataPtr, &FspHobListPtr);\r |
| 122 | if (EFI_ERROR (Status)) {\r |
| 123 | DEBUG ((DEBUG_ERROR, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status));\r |
| 124 | }\r |
| 125 | \r |
| 126 | DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));\r |
| 127 | ASSERT (FspHobListPtr != NULL);\r |
| 128 | \r |
| 129 | PostFspmHobProcess (FspHobListPtr);\r |
| 130 | \r |
| 131 | //\r |
| 132 | // FspHobList is not complete at this moment.\r |
| 133 | // Save FspHobList pointer to hob, so that it can be got later\r |
| 134 | //\r |
| 135 | HobData = BuildGuidHob (\r |
| 136 | &gFspHobGuid,\r |
| 137 | sizeof (VOID *)\r |
| 138 | );\r |
| 139 | ASSERT (HobData != NULL);\r |
| 140 | CopyMem (HobData, &FspHobListPtr, sizeof (FspHobListPtr));\r |
| 141 | \r |
| 142 | return Status;\r |
| 143 | }\r |
| 144 | \r |
| 145 | /**\r |
| 146 | Do FSP initialization.\r |
| 147 | \r |
| 148 | @return FSP initialization status.\r |
| 149 | **/\r |
| 150 | EFI_STATUS\r |
| 151 | EFIAPI\r |
| 152 | FspmWrapperInit (\r |
| 153 | VOID\r |
| 154 | )\r |
| 155 | {\r |
| 156 | EFI_STATUS Status;\r |
| 157 | \r |
| 158 | Status = PeiFspMemoryInit ();\r |
| 159 | ASSERT_EFI_ERROR (Status);\r |
| 160 | \r |
| 161 | return Status;\r |
| 162 | }\r |
| 163 | \r |
| 164 | /**\r |
| 165 | This is the entrypoint of PEIM\r |
| 166 | \r |
| 167 | @param[in] FileHandle Handle of the file being invoked.\r |
| 168 | @param[in] PeiServices Describes the list of possible PEI Services.\r |
| 169 | \r |
| 170 | @retval EFI_SUCCESS if it completed successfully.\r |
| 171 | **/\r |
| 172 | EFI_STATUS\r |
| 173 | EFIAPI\r |
| 174 | FspmWrapperPeimEntryPoint (\r |
| 175 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
| 176 | IN CONST EFI_PEI_SERVICES **PeiServices\r |
| 177 | )\r |
| 178 | {\r |
| 179 | DEBUG((DEBUG_INFO, "FspmWrapperPeimEntryPoint\n"));\r |
| 180 | \r |
| 181 | FspmWrapperInit ();\r |
| 182 | \r |
| 183 | return EFI_SUCCESS;\r |
| 184 | }\r |