/** This function initializes the mCapsulePtr, mCapsuleStatusArray and mCapsuleTotalNumber. **/ VOID InitCapsulePtr ( VOID ) { EFI_PEI_HOB_POINTERS HobPointer; UINTN Index; // // Find all capsule images from hob // HobPointer.Raw = GetHobList (); while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) { if (!IsValidCapsuleHeader((VOID *)(UINTN)HobPointer.Capsule->BaseAddress, HobPointer.Capsule->Length)) { HobPointer.Header->HobType = EFI_HOB_TYPE_UNUSED; // Mark this hob as invalid } else { mCapsuleTotalNumber++; } HobPointer.Raw = GET_NEXT_HOB (HobPointer); } DEBUG ((DEBUG_INFO, "mCapsuleTotalNumber - 0x%x\n", mCapsuleTotalNumber)); if (mCapsuleTotalNumber == 0) { return ; } // // Init temp Capsule Data table. // mCapsulePtr = (VOID **) AllocateZeroPool (sizeof (VOID *) * mCapsuleTotalNumber); if (mCapsulePtr == NULL) { DEBUG ((DEBUG_ERROR, "Allocate mCapsulePtr fail!\n")); mCapsuleTotalNumber = 0; return ; } mCapsuleStatusArray = (EFI_STATUS *) AllocateZeroPool (sizeof (EFI_STATUS) * mCapsuleTotalNumber); if (mCapsuleStatusArray == NULL) { DEBUG ((DEBUG_ERROR, "Allocate mCapsuleStatusArray fail!\n")); FreePool (mCapsulePtr); mCapsulePtr = NULL; mCapsuleTotalNumber = 0; return ; } SetMemN (mCapsuleStatusArray, sizeof (EFI_STATUS) * mCapsuleTotalNumber, EFI_NOT_READY); // // Find all capsule images from hob // HobPointer.Raw = GetHobList (); Index = 0; while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) { mCapsulePtr [Index++] = (VOID *) (UINTN) HobPointer.Capsule->BaseAddress; HobPointer.Raw = GET_NEXT_HOB (HobPointer); } }
EFIAPI AllocatePages ( IN UINTN Pages ) { EFI_PEI_HOB_POINTERS Hob; EFI_PHYSICAL_ADDRESS Offset; Hob.Raw = GetHobList (); // Check to see if on 4k boundary Offset = Hob.HandoffInformationTable->EfiFreeMemoryTop & 0xFFF; if (Offset != 0) { // If not aligned, make the allocation aligned. Hob.HandoffInformationTable->EfiFreeMemoryTop -= Offset; } // // Verify that there is sufficient memory to satisfy the allocation // if (Hob.HandoffInformationTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < Hob.HandoffInformationTable->EfiFreeMemoryBottom) { return 0; } else { // // Update the PHIT to reflect the memory usage // Hob.HandoffInformationTable->EfiFreeMemoryTop -= Pages * EFI_PAGE_SIZE; // This routine used to create a memory allocation HOB a la PEI, but that's not // necessary for us. return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop; } }
/** Update the Stack Hob if the stack has been moved @param BaseAddress The 64 bit physical address of the Stack. @param Length The length of the stack in bytes. **/ VOID UpdateStackHob ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length ) { EFI_PEI_HOB_POINTERS Hob; Hob.Raw = GetHobList (); while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) { if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) { // // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type // to be reclaimed by DXE core. // BuildMemoryAllocationHob ( Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress, Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength, EfiConventionalMemory ); // // Update the BSP Stack Hob to reflect the new stack info. // Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress; Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length; break; } Hob.Raw = GET_NEXT_HOB (Hob); } }
EFIAPI FspGetResourceDescriptorByOwner ( IN EFI_GUID *OwnerGuid ) { EFI_PEI_HOB_POINTERS Hob; // // Get the HOB list for processing // Hob.Raw = GetHobList (); // // Collect memory ranges // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) && \ (CompareGuid (&Hob.ResourceDescriptor->Owner, OwnerGuid))) { return Hob.ResourceDescriptor; } } Hob.Raw = GET_NEXT_HOB (Hob); } return NULL; }
/** Check if AP wakeup buffer is overlapped with existing allocated buffer. @param[in] WakeupBufferStart AP wakeup buffer start address. @param[in] WakeupBufferEnd AP wakeup buffer end address. @retval TRUE There is overlap. @retval FALSE There is no overlap. **/ BOOLEAN CheckOverlapWithAllocatedBuffer ( IN UINT64 WakeupBufferStart, IN UINT64 WakeupBufferEnd ) { EFI_PEI_HOB_POINTERS Hob; EFI_HOB_MEMORY_ALLOCATION *MemoryHob; BOOLEAN Overlapped; UINT64 MemoryStart; UINT64 MemoryEnd; Overlapped = FALSE; // // Get the HOB list for processing // Hob.Raw = GetHobList (); // // Collect memory ranges // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) { MemoryHob = Hob.MemoryAllocation; MemoryStart = MemoryHob->AllocDescriptor.MemoryBaseAddress; MemoryEnd = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength; if (!((WakeupBufferStart >= MemoryEnd) || (WakeupBufferEnd <= MemoryStart))) { Overlapped = TRUE; break; } } Hob.Raw = GET_NEXT_HOB (Hob); } return Overlapped; }
void GetHighMemorySize ( uint64_t *HighMemoryLength ) { EFI_PEI_HOB_POINTERS Hob; *HighMemoryLength = 0x0; // // Get the HOB list for processing // Hob.Raw = GetHobList(); // // Collect memory ranges // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) { // // Need memory above 4GB to be collected here // if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) 0x100000000) { *HighMemoryLength += (uint64_t) (Hob.ResourceDescriptor->ResourceLength); } } } Hob.Raw = GET_NEXT_HOB (Hob); } return; }
EFI_STATUS GetPlatformInfoHob ( IN CONST EFI_PEI_SERVICES **PeiServices, OUT EFI_PLATFORM_INFO_HOB **PlatformInfoHob ) { EFI_PEI_HOB_POINTERS GuidHob; // // Find the PlatformInfo HOB // GuidHob.Raw = GetHobList (); if (GuidHob.Raw == NULL) { return EFI_NOT_FOUND; } if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) { *PlatformInfoHob = GET_GUID_HOB_DATA (GuidHob.Guid); } // // PlatformInfo PEIM should provide this HOB data, if not ASSERT and return error. // ASSERT (*PlatformInfoHob != NULL); if (!(*PlatformInfoHob)) { return EFI_NOT_FOUND; } return EFI_SUCCESS; }
void GetFspReservedMemoryFromGuid ( uint32_t *FspMemoryBase, uint32_t *FspMemoryLength, EFI_GUID FspReservedMemoryGuid ) { EFI_PEI_HOB_POINTERS Hob; // // Get the HOB list for processing // Hob.Raw = GetHobList(); *FspMemoryBase = 0; *FspMemoryLength = 0; // // Collect memory ranges // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) { if (CompareGuid(&Hob.ResourceDescriptor->Owner, &FspReservedMemoryGuid)) { *FspMemoryBase = (uint32_t) (Hob.ResourceDescriptor->PhysicalStart); *FspMemoryLength = (uint32_t) (Hob.ResourceDescriptor->ResourceLength); break; } } } Hob.Raw = GET_NEXT_HOB (Hob); } return; }
/** The generic memory test driver's entry point. It initializes private data to default value. @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The entry point is executed successfully. @retval EFI_NOT_FOUND Can't find HandOff Hob in HobList. @retval other Some error occurs when executing this entry point. **/ EFI_STATUS EFIAPI GenericMemoryTestEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; VOID *HobList; EFI_BOOT_MODE BootMode; EFI_PEI_HOB_POINTERS Hob; // // Use the generic pattern to test compatible memory range // mGenericMemoryTestPrivate.MonoPattern = GenericMemoryTestMonoPattern; mGenericMemoryTestPrivate.MonoTestSize = GENERIC_CACHELINE_SIZE; // // Get the platform boot mode // HobList = GetHobList (); Hob.Raw = HobList; if (Hob.Header->HobType != EFI_HOB_TYPE_HANDOFF) { return EFI_NOT_FOUND; } BootMode = Hob.HandoffInformationTable->BootMode; // // Get the platform boot mode and create the default memory test coverage // level and span size for compatible memory test using // switch (BootMode) { case BOOT_WITH_FULL_CONFIGURATION: case BOOT_WITH_DEFAULT_SETTINGS: mGenericMemoryTestPrivate.CoverageSpan = SPARSE_SPAN_SIZE; break; case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS: mGenericMemoryTestPrivate.CoverageSpan = GENERIC_CACHELINE_SIZE; break; default: mGenericMemoryTestPrivate.CoverageSpan = QUICK_SPAN_SIZE; break; } // // Install the protocol // Status = gBS->InstallProtocolInterface ( &mGenericMemoryTestPrivate.Handle, &gEfiGenericMemTestProtocolGuid, EFI_NATIVE_INTERFACE, &mGenericMemoryTestPrivate.GenericMemoryTest ); return Status; }
// // Return list of cores in the system // EFI_STATUS PrePeiCoreGetMpCoreInfo ( OUT UINTN *ArmCoreCount, OUT ARM_CORE_INFO **ArmCoreInfoTable ) { EFI_PEI_HOB_POINTERS Hob; if (ArmIsMpCore()) { // Iterate through the HOBs and find if there is ARM PROCESSOR ENTRY HOB for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) { // Check for Correct HOB type if ((GET_HOB_TYPE (Hob)) == EFI_HOB_TYPE_GUID_EXTENSION) { // Check for correct GUID type if (CompareGuid(&(Hob.Guid->Name), &gAmdStyxMpCoreInfoGuid)) { *ArmCoreInfoTable = (ARM_CORE_INFO *) GET_GUID_HOB_DATA(Hob); *ArmCoreCount = GET_GUID_HOB_DATA_SIZE(Hob)/sizeof(ARM_CORE_INFO); return EFI_SUCCESS; } } } } return EFI_UNSUPPORTED; }
/** Updates the Stack HOB passed to DXE phase. This function traverses the whole HOB list and update the stack HOB to reflect the real stack that is used by DXE core. @param BaseAddress The lower address of stack used by DxeCore. @param Length The length of stack used by DxeCore. **/ VOID UpdateStackHob ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length ) { EFI_PEI_HOB_POINTERS Hob; Hob.Raw = GetHobList (); while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) { if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) { // // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some // PEIMs may also keep key information on stack // BuildMemoryAllocationHob ( Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress, Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength, EfiBootServicesData ); // // Update the BSP Stack Hob to reflect the new stack info. // Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress; Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length; break; } Hob.Raw = GET_NEXT_HOB (Hob); } }
EFIAPI AllocatePeiAccessiblePages ( IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages ) { EFI_STATUS Status; EFI_ALLOCATE_TYPE AllocType; EFI_PHYSICAL_ADDRESS Memory; EFI_HOB_HANDOFF_INFO_TABLE *PhitHob; if (Pages == 0) { return NULL; } AllocType = AllocateAnyPages; // // A X64 build of DXE may be combined with a 32-bit build of PEI, and so we // need to check the memory limit set by PEI, and allocate below 4 GB if the // limit is set to 4 GB or lower. // PhitHob = (EFI_HOB_HANDOFF_INFO_TABLE *)GetHobList (); if (PhitHob->EfiFreeMemoryTop <= MAX_UINT32) { AllocType = AllocateMaxAddress; Memory = MAX_UINT32; } Status = gBS->AllocatePages (AllocType, MemoryType, Pages, &Memory); if (EFI_ERROR (Status)) { return NULL; } return (VOID *)(UINTN)Memory; }
/** Get system memory from HOB. @param[in,out] LowMemoryLength less than 4G memory length @param[in,out] HighMemoryLength greater than 4G memory length **/ VOID EFIAPI FspGetSystemMemorySize ( IN OUT UINT64 *LowMemoryLength, IN OUT UINT64 *HighMemoryLength ) { EFI_STATUS Status; EFI_BOOT_MODE BootMode; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute; EFI_PEI_HOB_POINTERS Hob; ResourceAttribute = ( EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE ); Status = PeiServicesGetBootMode (&BootMode); ASSERT_EFI_ERROR (Status); if (BootMode != BOOT_ON_S3_RESUME) { ResourceAttribute |= EFI_RESOURCE_ATTRIBUTE_TESTED; } *HighMemoryLength = 0; *LowMemoryLength = SIZE_1MB; // // Get the HOB list for processing // Hob.Raw = GetHobList (); // // Collect memory ranges // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) || ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) && (Hob.ResourceDescriptor->ResourceAttribute == ResourceAttribute))) { // // Need memory above 1MB to be collected here // if (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB && Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) BASE_4GB) { *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength); } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) BASE_4GB) { *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength); } } } Hob.Raw = GET_NEXT_HOB (Hob); } }
EFIAPI GetFirstHob ( IN UINT16 Type ) { VOID *HobList; HobList = GetHobList (); return GetNextHob (Type, HobList); }
EFIAPI GetFirstGuidHob ( IN CONST EFI_GUID *Guid ) { VOID *HobList; HobList = GetHobList (); return GetNextGuidHob (Guid, HobList); }
/** The constructor function caches the pointer to HOB list by calling GetHobList() and will always return EFI_SUCCESS. @param ImageHandle The firmware allocated handle for the EFI image. @param SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The constructor successfully gets HobList. **/ EFI_STATUS EFIAPI HobLibConstructor ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { GetHobList (); return EFI_SUCCESS; }
/**************************************************************************** 函 数 名 : SaveMemoryConfigDxeEntry 功能描述 : 读取Memory相关配置hob数据,存入Flash 输入参数 : IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable 输出参数 : 无 返 回 值 : EFI_STATUS 修改历史 : 1.日 期 : 2014年12月18日 作 者 : l00228991 修改内容 : 新生成函数 ****************************************************************************/ EFI_STATUS EFIAPI SaveMemoryConfigDxeEntry ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) { EFI_STATUS Status = EFI_SUCCESS; NVRAM *Nvram; GBL_DATA *Gbl_Data; SPI_FLASH_PROTOCOL *Flash; VOID* HobList; UINT32 NvramCrc; HobList = GetHobList(); Gbl_Data = (GBL_DATA*)GetNextGuidHob(&gEfiMemoryMapGuid, HobList); Gbl_Data = GET_GUID_HOB_DATA(Gbl_Data); Nvram = &(Gbl_Data->nvram); Status = gBS->CalculateCrc32(((UINT8 *)Nvram+sizeof(UINT32)),(sizeof(NVRAM)-sizeof(UINT32)),&NvramCrc); if(EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR,"Nvram CalculateCrc32 Failed\n")); return Status; } if( Nvram->NvramCrc != NvramCrc) { Nvram->NvramCrc = NvramCrc; Status = gBS->LocateProtocol (&gSpiFlashProtocolGuid, NULL, (VOID *) &Flash); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a - %d Status=%r\n", __FILE__, __LINE__, Status)); return Status; } Status = Flash->Erase(Flash,NVRAM_ADDR,sizeof(NVRAM)); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a - %d SpiFlash Erase Error,Status=%r\n", __FILE__, __LINE__,Status)); return Status; } Status = Flash->Write(Flash, NVRAM_ADDR, (UINT8*)(Nvram), sizeof(NVRAM)); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a - %d Flash Write Error,Status=%r\n", __FILE__, __LINE__,Status)); return Status; } } return EFI_SUCCESS; }
/** Get the Boot Mode from the HOB list. This function returns the system boot mode information from the PHIT HOB in HOB list. @param VOID @return The Boot Mode. **/ EFI_BOOT_MODE EFIAPI GetBootMode ( VOID ) { EFI_PEI_HOB_POINTERS Hob; Hob.Raw = GetHobList (); return Hob.HandoffInformationTable->BootMode; }
/** Get the system boot mode from the HOB list. This function returns the system boot mode information from the PHIT HOB in HOB list. If the pointer to the HOB list is NULL, then ASSERT(). @param VOID @return The Boot Mode. **/ EFI_BOOT_MODE EFIAPI GetBootModeHob ( VOID ) { EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob; HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList (); return HandOffHob->BootMode; }
/** Get the Boot Mode from the HOB list. This function returns the system boot mode information from the PHIT HOB in HOB list. @param VOID @return The Boot Mode. **/ EFI_STATUS EFIAPI SetBootMode ( IN EFI_BOOT_MODE BootMode ) { EFI_PEI_HOB_POINTERS Hob; Hob.Raw = GetHobList (); Hob.HandoffInformationTable->BootMode = BootMode; return BootMode; }
EFI_STATUS testHotKey() { EFI_STATUS Status = 0; EFI_HOB_GENERIC_HEADER *Hob; UINT16 HobType; UINT16 HobLength; for(Hob = GetHobList();!END_OF_HOB_LIST(Hob);Hob = GET_NEXT_HOB(Hob)) { HobType = GET_HOB_TYPE (Hob); HobLength = GET_HOB_LENGTH (Hob); Print((CONST CHAR16*)L"Hob %x %x\n", HobType, HobLength); } return Status; }
/** Notify function on End Of PEI PPI. On S3 boot, this function will restore wakeup buffer data. On normal boot, this function will flag wakeup buffer to be un-used type. @param[in] PeiServices The pointer to the PEI Services Table. @param[in] NotifyDescriptor Address of the notification descriptor data structure. @param[in] Ppi Address of the PPI that was installed. @retval EFI_SUCCESS When everything is OK. **/ EFI_STATUS EFIAPI CpuMpEndOfPeiCallback ( IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi ) { EFI_STATUS Status; EFI_BOOT_MODE BootMode; CPU_MP_DATA *CpuMpData; EFI_PEI_HOB_POINTERS Hob; EFI_HOB_MEMORY_ALLOCATION *MemoryHob; DEBUG ((DEBUG_INFO, "PeiMpInitLib: CpuMpEndOfPeiCallback () invoked\n")); Status = PeiServicesGetBootMode (&BootMode); ASSERT_EFI_ERROR (Status); CpuMpData = GetCpuMpData (); if (BootMode != BOOT_ON_S3_RESUME) { // // Get the HOB list for processing // Hob.Raw = GetHobList (); // // Collect memory ranges // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) { MemoryHob = Hob.MemoryAllocation; if (MemoryHob->AllocDescriptor.MemoryBaseAddress == CpuMpData->WakeupBuffer) { // // Flag this HOB type to un-used // GET_HOB_TYPE (Hob) = EFI_HOB_TYPE_UNUSED; break; } } Hob.Raw = GET_NEXT_HOB (Hob); } } else { CpuMpData->SaveRestoreFlag = TRUE; RestoreWakeupBuffer (CpuMpData); } return EFI_SUCCESS; }
/** Adds SMBIOS records to tables @param[in] ImageHandle Image handle of this driver. @param[in] SystemTable Global system service table. @retval EFI_UNSUPPORTED - Could not locate SMBIOS protocol @retval EFI_OUT_OF_RESOURCES - Failed to allocate memory for SMBIOS HOB type. @retval EFI_SUCCESS - Successfully added SMBIOS records based on HOB. **/ EFI_STATUS EFIAPI DxeSmbiosDataHobLibConstructor ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_PEI_HOB_POINTERS Hob; EFI_SMBIOS_HANDLE SmbiosHandle; EFI_SMBIOS_PROTOCOL *Smbios; EFI_STATUS Status; UINT8 *RecordPtr; UINT16 RecordCount; RecordCount = 0; DEBUG ((DEBUG_INFO, "Adding SMBIOS records from HOB..\n")); Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios); if (Smbios == NULL) { DEBUG ((DEBUG_WARN, "Can't locate SMBIOS protocol\n")); return EFI_UNSUPPORTED; } /// /// Get SMBIOS HOB data (each hob contains one SMBIOS record) /// for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_GUID_EXTENSION) && (CompareGuid (&Hob.Guid->Name, &gIntelSmbiosDataHobGuid))) { RecordPtr = GET_GUID_HOB_DATA (Hob.Raw); /// /// Add generic SMBIOS HOB to SMBIOS table /// DEBUG ((DEBUG_VERBOSE, "Add SMBIOS record type: %x\n", ((EFI_SMBIOS_TABLE_HEADER *) RecordPtr)->Type)); SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; Status = Smbios->Add (Smbios, NULL, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) RecordPtr); if (!EFI_ERROR (Status)) { RecordCount++; } } } DEBUG ((DEBUG_INFO, "Found %d Records and added to SMBIOS table.\n", RecordCount)); return EFI_SUCCESS; }
/** This function transfer control to the ContinuationFunc passed in by the BootLoader. **/ VOID EFIAPI FspInitDone ( VOID ) { FSP_INIT_PARAMS *FspInitParams; if (GetFspApiCallingMode() == 0) { // // FspInit API is used, so jump into the ContinuationFunc // FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter (); // // Modify the parameters for ContinuationFunc // SetFspContinuationFuncParameter(EFI_SUCCESS, 0); SetFspContinuationFuncParameter((UINT32)GetHobList(), 1); // // Modify the return address to ContinuationFunc // SetFspApiReturnAddress((UINT32)FspInitParams->ContinuationFunc); // // Give control back to the boot loader framework caller after FspInit is done // It is done throught the continuation function // SetFspMeasurePoint (FSP_PERF_ID_API_FSPINIT_EXIT); } else { // // FspMemoryInit API is used, so return directly // // // This is the end of the FspSiliconInit API // Give control back to the boot loader // DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspSiliconInitApi() - End\n")); SetFspApiReturnStatus (EFI_SUCCESS); } Pei2LoaderSwitchStack(); }
/** This function returns control to BootLoader after MemoryInitApi. @param[in,out] HobListPtr The address of HobList pointer. **/ VOID EFIAPI FspMemoryInitDone ( IN OUT VOID **HobListPtr ) { // // Calling use FspMemoryInit API // Update HOB and return the control directly // if (HobListPtr != NULL) { *HobListPtr = (VOID *) GetHobList (); } // // This is the end of the FspMemoryInit API // Give control back to the boot loader // SetFspMeasurePoint (FSP_PERF_ID_API_FSP_MEMORY_INIT_EXIT); DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspMemoryInitApi() - End\n")); REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT); SetFspApiReturnStatus (EFI_SUCCESS); Pei2LoaderSwitchStack (); // // The TempRamExitApi is called // if (GetFspApiCallingIndex () == TempRamExitApiIndex) { SetPhaseStatusCode (FSP_STATUS_CODE_TEMP_RAM_EXIT); REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_TEMP_RAM_EXIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY); SetFspMeasurePoint (FSP_PERF_ID_API_TEMP_RAM_EXIT_ENTRY); DEBUG ((DEBUG_INFO | DEBUG_INIT, "TempRamExitApi() - Begin\n")); } else { SetFspMeasurePoint (FSP_PERF_ID_API_FSP_SILICON_INIT_ENTRY); DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspSiliconInitApi() - Begin\n")); SetPhaseStatusCode (FSP_STATUS_CODE_SILICON_INIT); REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY); } }
EFIAPI AllocatePool ( IN UINTN AllocationSize ) { EFI_HOB_MEMORY_POOL *Hob; Hob = GetHobList (); // // Verify that there is sufficient memory to satisfy the allocation // if (AllocationSize > 0x10000) { // Please call AllcoatePages for big allocations return 0; } else { Hob = (EFI_HOB_MEMORY_POOL *)CreateHob (EFI_HOB_TYPE_MEMORY_POOL, (UINT16)(sizeof (EFI_HOB_TYPE_MEMORY_POOL) + AllocationSize)); return (VOID *)(Hob + 1); } }
EFI_STATUS EFIAPI PlatformCpuInfoInit ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_PLATFORM_CPU_INFO *PlatformCpuInfoPtr; EFI_PEI_HOB_POINTERS GuidHob; // // Get Platform Cpu Info HOB // GuidHob.Raw = GetHobList (); while ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformCpuInfoGuid, GuidHob.Raw)) != NULL) { PlatformCpuInfoPtr = GET_GUID_HOB_DATA (GuidHob.Guid); GuidHob.Raw = GET_NEXT_HOB (GuidHob); // // Write the Platform CPU Info to volatile memory for runtime purposes. // This must be done in its own driver because SetVariable protocol is dependent on chipset, // which is dependent on CpuIo, PlatformInfo, and Metronome. // Status = gRT->SetVariable( EfiPlatformCpuInfoVariable, &gEfiVlv2VariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, sizeof(EFI_PLATFORM_CPU_INFO), PlatformCpuInfoPtr ); if (EFI_ERROR(Status)) { return Status; } } return EFI_SUCCESS; }
VOID CreatePlatformSmbiosMemoryRecords ( VOID ) { EFI_PEI_HOB_POINTERS HobPtr; SMBIOS_STRUCTURE_POINTER Smbios16; SMBIOS_STRUCTURE_POINTER Smbios17; EFI_SMBIOS_HANDLE PhyscialMemoryArrayHandle; EFI_SMBIOS_HANDLE SmbiosHandle; Smbios16.Hdr = SmbiosLibGetRecord (EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY, 0, &PhyscialMemoryArrayHandle); if (Smbios16.Hdr == NULL) { // Only make a Type19 entry if a Type16 entry exists. return; } Smbios17.Hdr = SmbiosLibGetRecord (EFI_SMBIOS_TYPE_MEMORY_DEVICE, 0, &SmbiosHandle); if (Smbios17.Hdr == NULL) { // if type17 exits update with type16 Smbios handle Smbios17.Type17->MemoryArrayHandle = PhyscialMemoryArrayHandle; } // Generate Type16 records gSmbiosType19Template.MemoryArrayHandle = PhyscialMemoryArrayHandle; HobPtr.Raw = GetHobList (); while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, HobPtr.Raw)) != NULL) { if (HobPtr.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) { gSmbiosType19Template.ExtendedStartingAddress = HobPtr.ResourceDescriptor->PhysicalStart; gSmbiosType19Template.ExtendedEndingAddress = HobPtr.ResourceDescriptor->PhysicalStart + HobPtr.ResourceDescriptor->ResourceLength - 1; SmbiosLibCreateEntry ((SMBIOS_STRUCTURE *)&gSmbiosType19Template, NULL); } HobPtr.Raw = GET_NEXT_HOB (HobPtr); } }
VOID * CreateHob ( IN UINT16 HobType, IN UINT16 HobLength ) { EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob; EFI_HOB_GENERIC_HEADER *HobEnd; EFI_PHYSICAL_ADDRESS FreeMemory; VOID *Hob; HandOffHob = GetHobList (); HobLength = (UINT16)((HobLength + 0x7) & (~0x7)); FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom; if (FreeMemory < HobLength) { return NULL; } Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList; ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType; ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength; ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0; HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength); HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd; HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER); HobEnd->Reserved = 0; HobEnd++; HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd; return Hob; }
/** Get system memory from HOB. @param[in,out] LowMemoryLength less than 4G memory length @param[in,out] HighMemoryLength greater than 4G memory length **/ VOID EFIAPI FspGetSystemMemorySize ( IN OUT UINT64 *LowMemoryLength, IN OUT UINT64 *HighMemoryLength ) { EFI_PEI_HOB_POINTERS Hob; *HighMemoryLength = 0; *LowMemoryLength = SIZE_1MB; // // Get the HOB list for processing // Hob.Raw = GetHobList (); // // Collect memory ranges // while (!END_OF_HOB_LIST (Hob)) { if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) { // // Need memory above 1MB to be collected here // if (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB && Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) BASE_4GB) { *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength); } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) BASE_4GB) { *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength); } } } Hob.Raw = GET_NEXT_HOB (Hob); } }