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; }
EFI_STATUS PlatformHobCreateFromFsp ( IN CONST EFI_PEI_SERVICES **PeiServices, VOID *HobList ) { VOID *HobData; VOID *NewHobData; UINTN DataSize; // // Other hob, todo: put this into FspWrapPlatformLib // if ((HobList = GetNextGuidHob (&gEfiMemoryConfigDataGuid, HobList)) != NULL) { HobData = GET_GUID_HOB_DATA (HobList); DataSize = GET_GUID_HOB_DATA_SIZE(HobList); DEBUG((EFI_D_ERROR, "gEfiMemoryConfigDataGuid Hob found: 0x%x.\n", DataSize)); NewHobData = BuildGuidHob (&gEfiMemoryConfigDataGuid, DataSize); (*PeiServices)->CopyMem ( NewHobData, HobData, DataSize ); } return EFI_SUCCESS; }
/** Remove a previously registered callback function from the notification list. ReportStatusCode() messages will no longer be forwarded to the Callback function. @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be unregistered. @retval EFI_SUCCESS The function was successfully unregistered. @retval EFI_INVALID_PARAMETER The callback function was NULL. @retval EFI_NOT_FOUND The callback function was not found to be unregistered. **/ EFI_STATUS EFIAPI Unregister ( IN EFI_PEI_RSC_HANDLER_CALLBACK Callback ) { EFI_PEI_HOB_POINTERS Hob; EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry; UINTN *NumberOfEntries; UINTN Index; if (Callback == NULL) { return EFI_INVALID_PARAMETER; } Hob.Raw = GetFirstGuidHob (&gStatusCodeCallbackGuid); while (Hob.Raw != NULL) { NumberOfEntries = GET_GUID_HOB_DATA (Hob); CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *) (NumberOfEntries + 1); for (Index = 0; Index < *NumberOfEntries; Index++) { if (CallbackEntry[Index] == Callback) { // // Set removed entry as NULL. // CallbackEntry[Index] = NULL; return EFI_SUCCESS; } } Hob.Raw = GET_NEXT_HOB (Hob); Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw); } return EFI_NOT_FOUND; }
EFIAPI GetFirstGuidHob ( IN CONST EFI_GUID *Guid ) { VOID *HobList; HobList = GetHobList (); return GetNextGuidHob (Guid, HobList); }
/**************************************************************************** 函 数 名 : 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; }
/** * Save the FSP memory HOB (mrc data) to the MRC area in CBMEM */ int save_mrc_data(void *hob_start) { u32 *mrc_hob; u32 *mrc_hob_data; u32 mrc_hob_size; struct mrc_data_container *mrc_data; int output_len; const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID; mrc_hob = GetNextGuidHob(&mrc_guid, hob_start); if (mrc_hob == NULL){ printk(BIOS_DEBUG, "Memory Configure Data Hob is not present\n"); return(0); } mrc_hob_data = GET_GUID_HOB_DATA (mrc_hob); mrc_hob_size = (u32) GET_HOB_LENGTH(mrc_hob); printk(BIOS_DEBUG, "Memory Configure Data Hob at %p (size = 0x%x).\n", (void *)mrc_hob_data, mrc_hob_size); output_len = ALIGN(mrc_hob_size, 16); /* Save the MRC S3/fast boot/ADR restore data to cbmem */ mrc_data = cbmem_add (CBMEM_ID_MRCDATA, output_len + sizeof(struct mrc_data_container)); /* Just return if there was a problem with getting CBMEM */ if (mrc_data == NULL) { printk(BIOS_WARNING, "CBMEM was not available to save the fast boot cache data.\n"); return 0; } printk(BIOS_DEBUG, "Copy FSP MRC DATA to HOB (source addr %p, dest addr %p, %u bytes)\n", (void *)mrc_hob_data, mrc_data, output_len); mrc_data->mrc_signature = MRC_DATA_SIGNATURE; mrc_data->mrc_data_size = output_len; mrc_data->reserved = 0; memcpy(mrc_data->mrc_data, (const void *)mrc_hob_data, mrc_hob_size); /* Zero the unused space in aligned buffer. */ if (output_len > mrc_hob_size) memset((mrc_data->mrc_data + mrc_hob_size), 0, output_len - mrc_hob_size); mrc_data->mrc_checksum = compute_ip_checksum(mrc_data->mrc_data, mrc_data->mrc_data_size); printk(BIOS_SPEW, "Fast boot data (includes align and checksum):\n"); hexdump32(BIOS_SPEW, (void *)mrc_data->mrc_data, output_len / 4); return (1); }
/** Get the pointer to Mailbox from the GUIDed HOB. @param[in] HobStart The starting HOB pointer to search from. @return Pointer to Mailbox. **/ DEBUG_AGENT_MAILBOX * GetMailboxFromHob ( IN VOID *HobStart ) { EFI_HOB_GUID_TYPE *GuidHob; GuidHob = GetNextGuidHob (&gEfiDebugAgentGuid, HobStart); if (GuidHob == NULL) { return NULL; } return (DEBUG_AGENT_MAILBOX *) (GET_GUID_HOB_DATA(GuidHob)); }
EFI_STATUS EfiInitializeWinNtDriverLib ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Intialize gWinNt and initialize debug console. Arguments: (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT) Returns: None --*/ // TODO: ImageHandle - add argument and description to function comment // TODO: SystemTable - add argument and description to function comment // TODO: EFI_NOT_FOUND - add return value to function comment // TODO: EFI_NOT_FOUND - add return value to function comment // TODO: EFI_SUCCESS - add return value to function comment { EFI_STATUS Status; VOID *HobList; VOID *Pointer; Status = EfiLibGetSystemConfigurationTable (&mEfiHobListGuid, &HobList); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } ASSERT (NULL != HobList); Status = GetNextGuidHob (&HobList, &gEfiWinNtThunkProtocolGuid, &Pointer, NULL); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } gWinNt = (VOID *) (*(UINTN *) (Pointer)); return EFI_SUCCESS; }
/** Get the pointer to Mailbox from the GUIDed HOB. @param[in] HobStart The starting HOB pointer to search from. @return Pointer to Mailbox. **/ DEBUG_AGENT_MAILBOX * GetMailboxFromHob ( IN VOID *HobStart ) { EFI_HOB_GUID_TYPE *GuidHob; UINT64 *MailboxLocation; DEBUG_AGENT_MAILBOX *Mailbox; GuidHob = GetNextGuidHob (&gEfiDebugAgentGuid, HobStart); if (GuidHob == NULL) { return NULL; } MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob)); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation); VerifyMailboxChecksum (Mailbox); return Mailbox; }
/** This function gets hash interface hob. @param Identifier Identifier to get hash interface hob. @retval hash interface hob. **/ HASH_INTERFACE_HOB * InternalGetHashInterfaceHob ( EFI_GUID *Identifier ) { EFI_PEI_HOB_POINTERS Hob; HASH_INTERFACE_HOB *HashInterfaceHob; Hob.Raw = GetFirstGuidHob (&mHashLibPeiRouterGuid); while (Hob.Raw != NULL) { HashInterfaceHob = GET_GUID_HOB_DATA (Hob); if (CompareGuid (&HashInterfaceHob->Identifier, Identifier)) { // // Found the matched one. // return HashInterfaceHob; } Hob.Raw = GET_NEXT_HOB (Hob); Hob.Raw = GetNextGuidHob (&mHashLibPeiRouterGuid, Hob.Raw); } return NULL; }
EFI_STATUS GetGuidedHobData ( IN VOID *HobList, IN CONST EFI_GUID *HobGuid, OUT VOID **HobData ) { EFI_HOB_GUID_TYPE *Hob; if (!HobList || !HobGuid || !HobData) return EFI_INVALID_PARAMETER; Hob = GetNextGuidHob (HobGuid, HobList); if (!Hob) return EFI_NOT_FOUND; *HobData = GET_GUID_HOB_DATA (Hob); if (!HobData) return EFI_NOT_FOUND; return EFI_SUCCESS; }
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 BdsLockNonUpdatableFlash ( VOID ) { EFI_FLASH_MAP_ENTRY_DATA *FlashMapEntryData; VOID *HobList; VOID *Buffer; EFI_STATUS Status; EFI_CPU_IO_PROTOCOL *CpuIo; Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &CpuIo); ASSERT_EFI_ERROR (Status); Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList); ASSERT_EFI_ERROR (Status); for (;;) { Status = GetNextGuidHob (&HobList, &gEfiFlashMapHobGuid, &Buffer, NULL); if (EFI_ERROR (Status)) { break; } FlashMapEntryData = (EFI_FLASH_MAP_ENTRY_DATA *) Buffer; // // Get the variable store area // if ((FlashMapEntryData->AreaType == EFI_FLASH_AREA_RECOVERY_BIOS) || (FlashMapEntryData->AreaType == EFI_FLASH_AREA_MAIN_BIOS) ) { BdsLockFv (CpuIo, &(FlashMapEntryData->Entries[0])); } } return ; }
EFI_STATUS EFIAPI PlatformInfoInit ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_PLATFORM_INFO_HOB *PlatformInfoHobPtr; EFI_PEI_HOB_POINTERS GuidHob; EFI_PLATFORM_INFO_HOB TmpHob; UINTN VarSize; EFI_OS_SELECTION_HOB *OsSlectionHobPtr; UINT8 Selection; SYSTEM_CONFIGURATION SystemConfiguration; UINT8 *LpssDataHobPtr; UINT8 *LpssDataVarPtr; UINTN i; VarSize = sizeof(SYSTEM_CONFIGURATION); Status = gRT->GetVariable( NORMAL_SETUP_NAME, &gEfiNormalSetupGuid, NULL, &VarSize, &SystemConfiguration ); VarSize = sizeof(Selection); Status = gRT->GetVariable( L"OsSelection", &gOsSelectionVariableGuid, NULL, &VarSize, &Selection ); if (EFI_ERROR(Status)) { Selection = SystemConfiguration.ReservedO; Status = gRT->SetVariable ( L"OsSelection", &gOsSelectionVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, sizeof(Selection), &Selection ); } GuidHob.Raw = GetHobList (); if (GuidHob.Raw != NULL) { if ((GuidHob.Raw = GetNextGuidHob (&gOsSelectionVariableGuid, GuidHob.Raw)) != NULL) { OsSlectionHobPtr = GET_GUID_HOB_DATA (GuidHob.Guid); if (OsSlectionHobPtr->OsSelectionChanged) { SystemConfiguration.ReservedO = OsSlectionHobPtr->OsSelection; // // Load Audio default configuration // SystemConfiguration.Lpe = OsSlectionHobPtr->Lpe; SystemConfiguration.PchAzalia = OsSlectionHobPtr->PchAzalia; // // Load LPSS and SCC default configurations // LpssDataHobPtr = &OsSlectionHobPtr->LpssData.LpssPciModeEnabled; LpssDataVarPtr = &SystemConfiguration.LpssPciModeEnabled; for (i = 0; i < sizeof(EFI_PLATFORM_LPSS_DATA); i++) { *LpssDataVarPtr = *LpssDataHobPtr; LpssDataVarPtr++; LpssDataHobPtr++; } SystemConfiguration.GOPEnable = TRUE; Status = gRT->SetVariable ( NORMAL_SETUP_NAME, &gEfiNormalSetupGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, sizeof(SYSTEM_CONFIGURATION), &SystemConfiguration ); ASSERT_EFI_ERROR (Status); } } } GuidHob.Raw = GetHobList (); if (GuidHob.Raw == NULL) { return EFI_NOT_FOUND; } if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) { PlatformInfoHobPtr = GET_GUID_HOB_DATA (GuidHob.Guid); VarSize = sizeof(EFI_PLATFORM_INFO_HOB); Status = gRT->GetVariable( L"PlatformInfo", &gEfiVlv2VariableGuid, NULL, &VarSize, &TmpHob ); if (EFI_ERROR(Status) || CompareMem (&TmpHob, PlatformInfoHobPtr, VarSize)) { // // Write the Platform Info to volatile memory // Status = gRT->SetVariable( L"PlatformInfo", &gEfiVlv2VariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, sizeof(EFI_PLATFORM_INFO_HOB), PlatformInfoHobPtr ); if (EFI_ERROR(Status)) { return Status; } } } return EFI_SUCCESS; }
/** Initialize the Event Log and log events passed from the PEI phase. @retval EFI_SUCCESS Operation completed successfully. @retval EFI_OUT_OF_RESOURCES Out of memory. **/ EFI_STATUS EFIAPI SetupEventLog ( VOID ) { EFI_STATUS Status; TCG_PCR_EVENT *TcgEvent; EFI_PEI_HOB_POINTERS GuidHob; EFI_PHYSICAL_ADDRESS Lasa; if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) { Lasa = mTcgClientAcpiTemplate.Lasa; Status = gBS->AllocatePages ( AllocateMaxAddress, EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)), &Lasa ); if (EFI_ERROR (Status)) { return Status; } mTcgClientAcpiTemplate.Lasa = Lasa; // // To initialize them as 0xFF is recommended // because the OS can know the last entry for that. // SetMem ((VOID *)(UINTN)mTcgClientAcpiTemplate.Lasa, PcdGet32 (PcdTcgLogAreaMinLen), 0xFF); mTcgClientAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen); } else { Lasa = mTcgServerAcpiTemplate.Lasa; Status = gBS->AllocatePages ( AllocateMaxAddress, EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)), &Lasa ); if (EFI_ERROR (Status)) { return Status; } mTcgServerAcpiTemplate.Lasa = Lasa; // // To initialize them as 0xFF is recommended // because the OS can know the last entry for that. // SetMem ((VOID *)(UINTN)mTcgServerAcpiTemplate.Lasa, PcdGet32 (PcdTcgLogAreaMinLen), 0xFF); mTcgServerAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen); } GuidHob.Raw = GetHobList (); while (!EFI_ERROR (Status) && (GuidHob.Raw = GetNextGuidHob (&gTcgEventEntryHobGuid, GuidHob.Raw)) != NULL) { TcgEvent = GET_GUID_HOB_DATA (GuidHob.Guid); GuidHob.Raw = GET_NEXT_HOB (GuidHob); Status = TcgDxeLogEventI ( &mTcgDxeData, (TCG_PCR_EVENT_HDR*)TcgEvent, TcgEvent->Event ); } return Status; }
/** Dispatch initialization request to sub status code devices based on customized feature flags. **/ VOID InitializationDispatcherWorker ( VOID ) { EFI_PEI_HOB_POINTERS Hob; EFI_STATUS Status; MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader; MEMORY_STATUSCODE_RECORD *Record; UINTN ExpectedPacketIndex; UINTN Index; VOID *HobStart; // // If enable UseSerial, then initialize serial port. // if enable UseRuntimeMemory, then initialize runtime memory status code worker. // if (FeaturePcdGet (PcdStatusCodeUseSerial)) { // // Call Serial Port Lib API to initialize serial port. // Status = SerialPortInitialize (); ASSERT_EFI_ERROR (Status); } if (FeaturePcdGet (PcdStatusCodeUseMemory)) { Status = RtMemoryStatusCodeInitializeWorker (); ASSERT_EFI_ERROR (Status); } // // Replay Status code which saved in GUID'ed HOB to all supported devices. // if (FeaturePcdGet (PcdStatusCodeReplayIn)) { // // Journal GUID'ed HOBs to find all record entry, if found, // then output record to support replay device. // ExpectedPacketIndex = 0; Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid); HobStart = Hob.Raw; while (Hob.Raw != NULL) { PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid); if (PacketHeader->PacketIndex == ExpectedPacketIndex) { Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1); for (Index = 0; Index < PacketHeader->RecordIndex; Index++) { // // Dispatch records to devices based on feature flag. // if (FeaturePcdGet (PcdStatusCodeUseSerial)) { SerialStatusCodeReportWorker ( Record[Index].CodeType, Record[Index].Value, Record[Index].Instance, NULL, NULL ); } if (FeaturePcdGet (PcdStatusCodeUseMemory)) { RtMemoryStatusCodeReportWorker ( Record[Index].CodeType, Record[Index].Value, Record[Index].Instance, NULL, NULL ); } } ExpectedPacketIndex++; // // See whether there is gap of packet or not // if (HobStart != NULL) { HobStart = NULL; Hob.Raw = HobStart; continue; } } else if (HobStart != NULL) { // // Cache the found packet for improve the performance // HobStart = Hob.Raw; } Hob.Raw = GetNextGuidHob (&gMemoryStatusCodeRecordGuid, Hob.Raw); } } }
EFI_STATUS GetPeiPerformance ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN UINT64 Ticker ) /*++ Routine Description: Transfer PEI performance data to gauge data node. Arguments: ImageHandle - Standard entry point parameter SystemTable - Standard entry point parameter Ticker - Start tick Returns: EFI_OUT_OF_RESOURCES - No enough resource to create data node. EFI_SUCCESS - Transfer done successfully. --*/ { EFI_STATUS Status; VOID *HobList; EFI_HOB_GUID_DATA_PERFORMANCE_LOG *LogHob; PEI_PERFORMANCE_MEASURE_LOG_ENTRY *LogEntry; UINT32 Index; EFI_PERF_DATA_LIST *Node; UINT64 TimerValue; Node = CreateDataNode (0, PEI_TOK, NULL); if (!Node) { return EFI_OUT_OF_RESOURCES; } if (Ticker != 0) { TimerValue = Ticker; } else { GetTimerValue (&TimerValue); } (Node->GaugeData).EndTick = TimerValue; InsertTailList (&mPerfDataHead, &(Node->Link)); EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList); do { Status = GetNextGuidHob (&HobList, &gEfiPeiPerformanceHobGuid, (VOID **) &LogHob, NULL); if (EFI_ERROR (Status)) { break; } for (Index = 0; Index < LogHob->NumberOfEntries; Index++) { LogEntry = &(LogHob->Log[Index]); Node = CreateDataNode (0, LogEntry->DescriptionString, NULL); if (!Node) { return EFI_OUT_OF_RESOURCES; } (Node->GaugeData).StartTick = LogEntry->StartTimeCount; EfiCopyMem (&(Node->GaugeData.GuidName), &LogEntry->Name, sizeof (EFI_GUID)); InsertTailList (&mPerfDataHead, &(Node->Link)); (Node->GaugeData).EndTick = LogEntry->StopTimeCount; } } while (!EFI_ERROR (Status)); return EFI_SUCCESS; }
EFI_STATUS EFIAPI GetPciRom ( IN CONST EFI_PCI_PLATFORM_PROTOCOL *This, IN EFI_HANDLE PciHandle, OUT VOID **RomImage, OUT UINTN *RomSize ) { EFI_STATUS Status; EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo; UINTN Segment; UINTN Bus; UINTN Device; UINTN Function; UINT16 VendorId; UINT16 DeviceId; UINT16 DeviceClass; UINTN TableIndex; UINT8 Data8; BOOLEAN MfgMode; EFI_PLATFORM_SETUP_ID *BootModeBuffer; EFI_PEI_HOB_POINTERS GuidHob; MfgMode = FALSE; // // Check if system is in manufacturing mode. // GuidHob.Raw = GetHobList (); if (GuidHob.Raw == NULL) { return EFI_NOT_FOUND; } if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformBootModeGuid, GuidHob.Raw)) != NULL) { BootModeBuffer = GET_GUID_HOB_DATA (GuidHob.Guid); if (!CompareMem (&BootModeBuffer->SetupName, MANUFACTURE_SETUP_NAME, StrSize (MANUFACTURE_SETUP_NAME))) { // // System is in manufacturing mode. // MfgMode = TRUE; } } Status = gBS->HandleProtocol ( PciHandle, &gEfiPciIoProtocolGuid, (void **)&PciIo ); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } Status = gBS->LocateProtocol ( &gEfiPciRootBridgeIoProtocolGuid, NULL, (void **)&PciRootBridgeIo ); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 0x0A, 1, &DeviceClass); PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function); PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 0, 1, &VendorId); PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 2, 1, &DeviceId); // // WA for PCIe SATA card (SYBA SY-PEX400-40) // if ((VendorId == 0x1B21) && (DeviceId == 0x0612)) { Data8 = 0x07; PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 4, 1, &Data8); } // // Do not run RAID or AHCI Option ROM if IDE // if ( (DeviceClass == ((PCI_CLASS_MASS_STORAGE << 8 ) | PCI_CLASS_MASS_STORAGE_IDE)) ) { return EFI_NOT_FOUND; } // // Run PXE ROM only if Boot network is enabled and not in MFG mode // if (DeviceClass == ((PCI_CLASS_NETWORK << 8 ) | PCI_CLASS_NETWORK_ETHERNET)) { if (((mSystemConfiguration.BootNetwork == 0) && (MfgMode == FALSE )) || (mSystemConfiguration.FastBoot == 1)) { return EFI_NOT_FOUND; } } // // Loop through table of Onboard option rom descriptions // for (TableIndex = 0; mPciOptionRomTable[TableIndex].VendorId != 0xffff; TableIndex++) { // // See if the PCI device specified by PciHandle matches at device in mPciOptionRomTable // if (VendorId != mPciOptionRomTable[TableIndex].VendorId || DeviceId != mPciOptionRomTable[TableIndex].DeviceId || ((DeviceClass == ((PCI_CLASS_NETWORK << 8 ) | PCI_CLASS_NETWORK_ETHERNET)) && (mPciOptionRomTable[TableIndex].Flag != mSystemConfiguration.BootNetwork)) ) { continue; } Status = GetRawImage( &mPciOptionRomTable[TableIndex].FileName, RomImage, RomSize ); if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_VLV_A0)) { *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_VLV_A0; } if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_II)) { *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_II; } if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_0BE4)) { *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_0BE4; } if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_QS)) { *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_QS; } if (EFI_ERROR (Status)) { continue; } return EFI_SUCCESS; } return EFI_NOT_FOUND; }
EFI_STATUS RebuildHeap ( IN OUT HEAP_MANAGER **HeapManagerPtr ) { EFI_STATUS Status; AGESA_STATUS AgesaStatus; UINTN AlignTo16ByteInDxeMem; UINTN TotalAlignTo16ByteInHob; EFI_PEI_HOB_POINTERS Hob; VOID *HobList; VOID *HeapBufferInHob; HEAP_MANAGER *HeapManagerInHob; BUFFER_NODE *HeapHeaderNodeInHob; BUFFER_NODE *HeapCurrentNodeInHob; BUFFER_NODE *HeapPreNodeInHob; HEAP_MANAGER *HeapManagerInDxeMem; BUFFER_NODE *HeapHeaderNodeInDxeMem; BUFFER_NODE *HeapCurrentNodeInDxeMem; BUFFER_NODE *HeapPreNodeInDxeMem; UINT32 OffsetOfHeapCurrentNodeInDxeMem; EFI_HOB_GUID_TYPE *GuidHob; AGESA_BUFFER_PARAMS AllocParams; Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &HobList); ASSERT_EFI_ERROR (Status); Hob.Raw = HobList; HeapBufferInHob = NULL; while (!END_OF_HOB_LIST (Hob)) { GuidHob = GetNextGuidHob (&gAmdHeapHobGuid, HobList); HeapBufferInHob = GET_GUID_HOB_DATA (GuidHob); if (HeapBufferInHob != NULL) { HeapManagerInHob = (HEAP_MANAGER *) HeapBufferInHob; HeapHeaderNodeInHob = (BUFFER_NODE *) ((UINT8 *) HeapManagerInHob + HeapManagerInHob->FirstActiveBufferOffset); HeapCurrentNodeInHob = HeapHeaderNodeInHob; // // 1. Analyse heap buffer from HOB data to calculate the final size for recreating the heap buffers // Reserve maximum pad size for each heap node. // 2. Allocate memory for heap buffers // 3. Copying heap manager data from HOB include extracing 1-byte alignment to 16-byte alignment // // // 1. Analyse heap buffer from HOB data to calculate the final size for recreating the heap buffers. // Reserve maximum pad size for each heap node. // TotalAlignTo16ByteInHob = 0; do { HeapPreNodeInHob = HeapCurrentNodeInHob; TotalAlignTo16ByteInHob += 0xF; HeapCurrentNodeInHob = (BUFFER_NODE *) ((UINT8 *) HeapBufferInHob + HeapCurrentNodeInHob->OffsetOfNextNode); } while (HeapPreNodeInHob->OffsetOfNextNode != AMD_HEAP_INVALID_HEAP_OFFSET); // // 2. Allocate memory for heap buffers // AllocParams.BufferLength = (UINT32) (HeapManagerInHob->UsedSize + TotalAlignTo16ByteInHob + 0x0F); AllocParams.BufferHandle = AMD_HEAP_IN_MAIN_MEMORY_HANDLE; if ((AgesaStatus = AgesaAllocateBuffer (0, &AllocParams)) != AGESA_SUCCESS) { if (AGESA_ERROR > AgesaStatus) { return EFI_OUT_OF_RESOURCES; } } ZeroMem (AllocParams.BufferPointer, AllocParams.BufferLength); *HeapManagerPtr = AllocParams.BufferPointer; // // 3. Copying heap manager data from HOB include extracing 1-byte alignment to 16-byte alignment // HeapManagerInDxeMem = *HeapManagerPtr; HeapManagerInDxeMem->FirstActiveBufferOffset = sizeof (HEAP_MANAGER); HeapManagerInDxeMem->UsedSize = sizeof (HEAP_MANAGER); HeapHeaderNodeInDxeMem = (BUFFER_NODE *) ((UINT8 *) HeapManagerInDxeMem + HeapManagerInDxeMem->FirstActiveBufferOffset); OffsetOfHeapCurrentNodeInDxeMem = HeapManagerInDxeMem->FirstActiveBufferOffset; HeapCurrentNodeInDxeMem = HeapHeaderNodeInDxeMem; HeapCurrentNodeInHob = HeapHeaderNodeInHob; HeapPreNodeInHob = NULL; do { // Create BUFFER_NODE with 16-byte alignment padding considered. // The beginning of data buffer is on 16-byte boundary address. // The structure of a heap buffer would be looked like below. // // +---------------------------------------------------------------------------------+ // | BUFFER_NODE | Pad | IDS SENTINEL ("Head") | Data buffer | IDS SENTINEL ("Tail") | // +---------------------------------------------------------------------------------+ // AlignTo16ByteInDxeMem = ((0x10 - (((UINTN) (VOID *) HeapCurrentNodeInDxeMem + sizeof (BUFFER_NODE) + SIZE_OF_SENTINEL) & 0xF)) & 0xF); HeapCurrentNodeInDxeMem->BufferHandle = HeapCurrentNodeInHob->BufferHandle; HeapCurrentNodeInDxeMem->BufferSize = (UINT32) (HeapCurrentNodeInHob->BufferSize + AlignTo16ByteInDxeMem); HeapCurrentNodeInDxeMem->Persist = HeapCurrentNodeInHob->Persist; HeapCurrentNodeInDxeMem->PadSize = (UINT8) AlignTo16ByteInDxeMem; HeapCurrentNodeInDxeMem->OffsetOfNextNode = OffsetOfHeapCurrentNodeInDxeMem + sizeof (BUFFER_NODE) + HeapCurrentNodeInDxeMem->BufferSize; // Copy buffer data gBS->CopyMem ( (UINT8 *) ((UINT8 *) HeapCurrentNodeInDxeMem + sizeof (BUFFER_NODE) + AlignTo16ByteInDxeMem), (UINT8 *) ((UINT8 *) HeapCurrentNodeInHob + sizeof (BUFFER_NODE)), HeapCurrentNodeInHob->BufferSize ); // Point to the next heap node HeapPreNodeInHob = HeapCurrentNodeInHob; HeapPreNodeInDxeMem = HeapCurrentNodeInDxeMem; HeapCurrentNodeInHob = (BUFFER_NODE *) ((UINT8 *) HeapBufferInHob + HeapCurrentNodeInHob->OffsetOfNextNode); HeapCurrentNodeInDxeMem = (BUFFER_NODE *) ((UINT8 *) HeapManagerInDxeMem + HeapCurrentNodeInDxeMem->OffsetOfNextNode); OffsetOfHeapCurrentNodeInDxeMem = (UINT32) ((UINTN) HeapCurrentNodeInDxeMem - (UINTN) HeapManagerInDxeMem); } while (HeapPreNodeInHob->OffsetOfNextNode != AMD_HEAP_INVALID_HEAP_OFFSET); // // Finalize the last heap node // HeapManagerInDxeMem->UsedSize = (UINT32) HeapPreNodeInDxeMem->OffsetOfNextNode; HeapPreNodeInDxeMem->OffsetOfNextNode = AMD_HEAP_INVALID_HEAP_OFFSET; // // Finalize Heap Manager pointer // No free buffer node is provide after heap recreation. // *HeapManagerPtr = HeapManagerInDxeMem; HeapManagerInDxeMem->FirstActiveBufferOffset = (UINT32) ((UINT8 *) HeapHeaderNodeInDxeMem - (UINT8 *) HeapManagerInDxeMem); HeapManagerInDxeMem->FirstFreeSpaceOffset = AMD_HEAP_INVALID_HEAP_OFFSET; HeapManagerInDxeMem->Signature = HeapManagerInHob->Signature; return EFI_SUCCESS; } } return EFI_NOT_FOUND; }
/** Main entry point to DXE Core. @param HobStart Pointer to the beginning of the HOB List from PEI. @return This function should never return. **/ VOID EFIAPI DxeMain ( IN VOID *HobStart ) { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS MemoryBaseAddress; UINT64 MemoryLength; PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; UINTN Index; EFI_HOB_GUID_TYPE *GuidHob; EFI_VECTOR_HANDOFF_INFO *VectorInfoList; EFI_VECTOR_HANDOFF_INFO *VectorInfo; VOID *EntryPoint; // // Setup the default exception handlers // VectorInfoList = NULL; GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart); if (GuidHob != NULL) { VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob)); } Status = InitializeCpuExceptionHandlers (VectorInfoList); ASSERT_EFI_ERROR (Status); // // Initialize Debug Agent to support source level debug in DXE phase // InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE, HobStart, NULL); // // Initialize Memory Services // CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength); MemoryProfileInit (HobStart); // // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table // gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate); ASSERT (gDxeCoreST != NULL); gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate); ASSERT (gDxeCoreRT != NULL); gDxeCoreST->RuntimeServices = gDxeCoreRT; // // Start the Image Services. // Status = CoreInitializeImageServices (HobStart); ASSERT_EFI_ERROR (Status); // // Initialize the Global Coherency Domain Services // Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength); ASSERT_EFI_ERROR (Status); // // Call constructor for all libraries // ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST); PERF_END (NULL,"PEI", NULL, 0) ; PERF_START (NULL,"DXE", NULL, 0) ; // // Report DXE Core image information to the PE/COFF Extra Action Library // ZeroMem (&ImageContext, sizeof (ImageContext)); ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase; ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*)(UINTN)ImageContext.ImageAddress); ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID*)(UINTN)ImageContext.ImageAddress); Status = PeCoffLoaderGetEntryPoint ((VOID*)(UINTN)ImageContext.ImageAddress, &EntryPoint); if (Status == EFI_SUCCESS) { ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint; } ImageContext.Handle = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase; ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; PeCoffLoaderRelocateImageExtraAction (&ImageContext); // // Install the DXE Services Table into the EFI System Tables's Configuration Table // Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS); ASSERT_EFI_ERROR (Status); // // Install the HOB List into the EFI System Tables's Configuration Table // Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart); ASSERT_EFI_ERROR (Status); // // Install Memory Type Information Table into the EFI System Tables's Configuration Table // Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation); ASSERT_EFI_ERROR (Status); // // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI // Code and Tseg base to load SMM driver. // if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) { Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable); ASSERT_EFI_ERROR (Status); } // // Report Status Code here for DXE_ENTRY_POINT once it is available // REPORT_STATUS_CODE ( EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT) ); // // Create the aligned system table pointer structure that is used by external // debuggers to locate the system table... Also, install debug image info // configuration table. // CoreInitializeDebugImageInfoTable (); CoreNewDebugImageInfoEntry ( EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, gDxeCoreLoadedImage, gDxeCoreImageHandle ); DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart)); DEBUG_CODE_BEGIN (); EFI_PEI_HOB_POINTERS Hob; for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) { if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) { DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \ Hob.MemoryAllocation->AllocDescriptor.MemoryType, \ Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \ Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1)); } } for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) { if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) { DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV2 Hob 0x%0lx - 0x%0lx\n", Hob.FirmwareVolume2->BaseAddress, Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1)); } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) { DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV Hob 0x%0lx - 0x%0lx\n", Hob.FirmwareVolume->BaseAddress, Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1)); } } DEBUG_CODE_END (); // // Initialize the Event Services // Status = CoreInitializeEventServices (); ASSERT_EFI_ERROR (Status); MemoryProfileInstallProtocol (); CoreInitializePropertiesTable (); CoreInitializeMemoryAttributesTable (); // // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated, // and install configuration table // GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart); if (GuidHob != NULL) { VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob)); VectorInfo = VectorInfoList; Index = 1; while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) { VectorInfo ++; Index ++; } VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *) VectorInfoList); ASSERT (VectorInfo != NULL); Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) VectorInfo); ASSERT_EFI_ERROR (Status); } // // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs // // These Protocols are not architectural. This implementation is sharing code between // PEI and DXE in order to save FLASH space. These Protocols could also be implemented // as part of the DXE Core. However, that would also require the DXE Core to be ported // each time a different CPU is used, a different Decompression algorithm is used, or a // different Image type is used. By placing these Protocols in PEI, the DXE Core remains // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform, // and from CPU to CPU. // // // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components // Status = CoreInstallMultipleProtocolInterfaces ( &mDecompressHandle, &gEfiDecompressProtocolGuid, &gEfiDecompress, NULL ); ASSERT_EFI_ERROR (Status); // // Register for the GUIDs of the Architectural Protocols, so the rest of the // EFI Boot Services and EFI Runtime Services tables can be filled in. // Also register for the GUIDs of optional protocols. // CoreNotifyOnProtocolInstallation (); // // Produce Firmware Volume Protocols, one for each FV in the HOB list. // Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST); ASSERT_EFI_ERROR (Status); Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST); ASSERT_EFI_ERROR (Status); // // Produce the Section Extraction Protocol // Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST); ASSERT_EFI_ERROR (Status); // // Initialize the DXE Dispatcher // PERF_START (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ; CoreInitializeDispatcher (); PERF_END (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ; // // Invoke the DXE Dispatcher // PERF_START (NULL, "CoreDispatcher", "DxeMain", 0); CoreDispatcher (); PERF_END (NULL, "CoreDispatcher", "DxeMain", 0); // // Display Architectural protocols that were not loaded if this is DEBUG build // DEBUG_CODE_BEGIN (); CoreDisplayMissingArchProtocols (); DEBUG_CODE_END (); // // Display any drivers that were not dispatched because dependency expression // evaluated to false if this is a debug build // DEBUG_CODE_BEGIN (); CoreDisplayDiscoveredNotDispatched (); DEBUG_CODE_END (); // // Assert if the Architectural Protocols are not present. // Status = CoreAllEfiServicesAvailable (); if (EFI_ERROR(Status)) { // // Report Status code that some Architectural Protocols are not present. // REPORT_STATUS_CODE ( EFI_ERROR_CODE | EFI_ERROR_MAJOR, (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH) ); } ASSERT_EFI_ERROR (Status); // // Report Status code before transfer control to BDS // REPORT_STATUS_CODE ( EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT) ); // // Transfer control to the BDS Architectural Protocol // gBds->Entry (gBds); // // BDS should never return // ASSERT (FALSE); CpuDeadLoop (); UNREACHABLE (); }
EFI_STATUS EFIAPI SaveMemoryConfigEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: This is the standard EFI driver point that detects whether there is a MemoryConfigurationData HOB and, if so, saves its data to nvRAM. Arguments: ImageHandle - Handle for the image of this driver SystemTable - Pointer to the EFI System Table Returns: EFI_SUCCESS - if the data is successfully saved or there was no data EFI_NOT_FOUND - if the HOB list could not be located. EFI_UNLOAD_IMAGE - It is not success --*/ { EFI_STATUS Status; VOID *HobList; EFI_HOB_GUID_TYPE *GuidHob; VOID *HobData; VOID *VariableData; UINTN DataSize; UINTN BufferSize; DataSize = 0; VariableData = NULL; GuidHob = NULL; HobList = NULL; HobData = NULL; Status = EFI_UNSUPPORTED; // // Get the HOB list. If it is not present, then ASSERT. // HobList = GetHobList (); ASSERT (HobList != NULL); // // Search for the Memory Configuration GUID HOB. If it is not present, then // there's nothing we can do. It may not exist on the update path. // GuidHob = GetNextGuidHob (&gEfiMemoryConfigDataGuid, HobList); if (GuidHob != NULL) { HobData = GET_GUID_HOB_DATA (GuidHob); DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob); // // Use the HOB to save Memory Configuration Data // BufferSize = DataSize; VariableData = AllocatePool (BufferSize); ASSERT (VariableData != NULL); Status = gRT->GetVariable ( EFI_MEMORY_CONFIG_DATA_NAME, &gEfiMemoryConfigDataGuid, NULL, &BufferSize, VariableData ); if (Status == EFI_BUFFER_TOO_SMALL) { (gBS->FreePool)(VariableData); VariableData = AllocatePool (BufferSize); ASSERT (VariableData != NULL); Status = gRT->GetVariable ( EFI_MEMORY_CONFIG_DATA_NAME, &gEfiMemoryConfigDataGuid, NULL, &BufferSize, VariableData ); } if ( (EFI_ERROR(Status)) || BufferSize != DataSize || 0 != CompareMem (HobData, VariableData, DataSize)) { if (Status != EFI_SUCCESS){ Status = gRT->SetVariable ( EFI_MEMORY_CONFIG_DATA_NAME, &gEfiMemoryConfigDataGuid, (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS), DataSize, HobData ); } ASSERT((Status == EFI_SUCCESS) || (Status == EFI_OUT_OF_RESOURCES)); DEBUG((EFI_D_INFO, "Restored Size is 0x%x\n", DataSize)); } (gBS->FreePool)(VariableData); } // // This driver does not produce any protocol services, so always unload it. // return Status; }
/** Convert PEI performance log to FPDT String boot record. @param IsStart TRUE if the performance log is start log. @param Handle Pointer to environment specific context used to identify the component being measured. @param Token Pointer to a Null-terminated ASCII string that identifies the component being measured. @param Module Pointer to a Null-terminated ASCII string that identifies the module being measured. @param Ticker 64-bit time stamp. @param Identifier 32-bit identifier. If the value is 0, the created record is same as the one created by StartGauge of PERFORMANCE_PROTOCOL. @retval EFI_SUCCESS Add FPDT boot record. @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement. @retval EFI_UNSUPPORTED No matched FPDT record. **/ EFI_STATUS InsertPeiFpdtMeasurement ( IN BOOLEAN IsStart, IN CONST VOID *Handle, OPTIONAL IN CONST CHAR8 *Token, OPTIONAL IN CONST CHAR8 *Module, OPTIONAL IN UINT64 Ticker, IN UINT32 Identifier ) { EFI_HOB_GUID_TYPE *GuidHob; UINTN PeiPerformanceSize; UINT8 *PeiFirmwarePerformance; FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader; FPDT_RECORD_PTR FpdtRecordPtr; FPDT_BASIC_RECORD_INFO RecordInfo; CONST VOID *ModuleGuid; UINTN DestMax; UINTN StrLength; CONST CHAR8 *StringPtr; EFI_STATUS Status; UINT16 PeiPerformanceLogEntries; UINT64 TimeStamp; StringPtr = NULL; FpdtRecordPtr.RecordHeader = NULL; PeiPerformanceLogHeader = NULL; // // Get record info (type, size, ProgressID and Module Guid). // Status = GetFpdtRecordInfo (IsStart, Handle, Token, Module, &RecordInfo); if (EFI_ERROR (Status)) { return Status; } // // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority. // !!! Note: If the Perf is not the known Token used in the core but have same // ID with the core Token, this case will not be supported. // And in currtnt usage mode, for the unkown ID, there is a general rule: // If it is start pref: the lower 4 bits of the ID should be 0. // If it is end pref: the lower 4 bits of the ID should not be 0. // If input ID doesn't follow the rule, we will adjust it. // if ((Identifier != 0) && (IsKnownID (Identifier)) && (!IsKnownTokens (Token))) { return EFI_UNSUPPORTED; } else if ((Identifier != 0) && (!IsKnownID (Identifier)) && (!IsKnownTokens (Token))) { if (IsStart && ((Identifier & 0x000F) != 0)) { Identifier &= 0xFFF0; } else if ((!IsStart) && ((Identifier & 0x000F) == 0)) { Identifier += 1; } RecordInfo.ProgressID = (UINT16)Identifier; } // // Get the number of PeiPerformanceLogEntries form PCD. // PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ? PcdGet16 (PcdMaxPeiPerformanceLogEntries16) : PcdGet8 (PcdMaxPeiPerformanceLogEntries)); // // Create GUID HOB Data. // GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid); PeiFirmwarePerformance = NULL; while (GuidHob != NULL) { // // PEI Performance HOB was found, then return the existing one. // PeiFirmwarePerformance = (UINT8*)GET_GUID_HOB_DATA (GuidHob); PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance; if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize > PeiPerformanceLogEntries * MAX_RECORD_SIZE) { PeiPerformanceLogHeader->HobIsFull = TRUE; } if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize <= PeiPerformanceLogEntries * MAX_RECORD_SIZE) { FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + PeiPerformanceLogHeader->SizeOfAllEntries); break; } // // Previous HOB is used, then find next one. // GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob)); } if (GuidHob == NULL) { // // PEI Performance HOB was not found, then build one. // PeiPerformanceSize = sizeof (FPDT_PEI_EXT_PERF_HEADER) + MAX_RECORD_SIZE * PeiPerformanceLogEntries; PeiFirmwarePerformance = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize); if (PeiFirmwarePerformance != NULL) { ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize); } PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance; FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER)); } if (PeiFirmwarePerformance == NULL) { // // there is no enough resource to store performance data // return EFI_OUT_OF_RESOURCES; } // // Get the TimeStamp. // if (Ticker == 0) { Ticker = GetPerformanceCounter (); TimeStamp = GetTimeInNanoSecond (Ticker); } else if (Ticker == 1) { TimeStamp = 0; } else { TimeStamp = GetTimeInNanoSecond (Ticker); } // // Get the ModuleGuid. // if (Handle != NULL) { ModuleGuid = Handle; } else { ModuleGuid = &gEfiCallerIdGuid; } switch (RecordInfo.Type) { case FPDT_GUID_EVENT_TYPE: FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE; FpdtRecordPtr.GuidEvent->Header.Length = RecordInfo.RecordSize;; FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1; FpdtRecordPtr.GuidEvent->ProgressID = RecordInfo.ProgressID; FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp; CopyMem (&FpdtRecordPtr.GuidEvent->Guid, ModuleGuid, sizeof (EFI_GUID)); PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize; break; case FPDT_GUID_QWORD_EVENT_TYPE: FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE; FpdtRecordPtr.GuidQwordEvent->Header.Length = RecordInfo.RecordSize;; FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1; FpdtRecordPtr.GuidQwordEvent->ProgressID = RecordInfo.ProgressID; FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp; PeiPerformanceLogHeader->LoadImageCount++; FpdtRecordPtr.GuidQwordEvent->Qword = PeiPerformanceLogHeader->LoadImageCount; CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID)); PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize; break; case FPDT_DYNAMIC_STRING_EVENT_TYPE: FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE; FpdtRecordPtr.DynamicStringEvent->Header.Length = RecordInfo.RecordSize; FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1; FpdtRecordPtr.DynamicStringEvent->ProgressID = RecordInfo.ProgressID; FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp; CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID)); PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize; if (Token != NULL) { StringPtr = Token; } else if (Module != NULL) { StringPtr = Module; } if (StringPtr != NULL && AsciiStrLen (StringPtr) != 0) { DestMax = (RecordInfo.RecordSize - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)) / sizeof (CHAR8); StrLength = AsciiStrLen (StringPtr); if (StrLength >= DestMax) { StrLength = DestMax -1; } AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StrLength); } else { AsciiStrCpyS (FpdtRecordPtr.DynamicStringEvent->String, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, "unknown name"); } break; default: // // Record is not supported in current PEI phase, return EFI_ABORTED // return EFI_UNSUPPORTED; } return EFI_SUCCESS; }
/** Routine Description: GC_TODO: Add function description. Arguments: Event - GC_TODO: add argument description Context - GC_TODO: add argument description Returns: GC_TODO: add return values **/ STATIC VOID EFIAPI OnReadyToBoot ( IN EFI_EVENT Event, IN VOID *Context ) { EFI_STATUS Status; EFI_ACPI_TABLE_VERSION TableVersion; EFI_ACPI_SUPPORT_PROTOCOL *AcpiSupport; EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save; SYSTEM_CONFIGURATION SetupVarBuffer; UINTN VariableSize; EFI_PLATFORM_CPU_INFO *PlatformCpuInfoPtr = NULL; EFI_PLATFORM_CPU_INFO PlatformCpuInfo; EFI_PEI_HOB_POINTERS GuidHob; if (mFirstNotify) { return; } mFirstNotify = TRUE; // // To avoid compiler warning of "C4701: potentially uninitialized local variable 'PlatformCpuInfo' used". // PlatformCpuInfo.CpuVersion.FullCpuId = 0; // // Get Platform CPU Info HOB. // PlatformCpuInfoPtr = NULL; ZeroMem (&PlatformCpuInfo, sizeof(EFI_PLATFORM_CPU_INFO)); VariableSize = sizeof(EFI_PLATFORM_CPU_INFO); Status = gRT->GetVariable( EfiPlatformCpuInfoVariable, &gEfiVlv2VariableGuid, NULL, &VariableSize, PlatformCpuInfoPtr ); if (EFI_ERROR(Status)) { GuidHob.Raw = GetHobList (); if (GuidHob.Raw != NULL) { if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformCpuInfoGuid, GuidHob.Raw)) != NULL) { PlatformCpuInfoPtr = GET_GUID_HOB_DATA (GuidHob.Guid); } } } if ((PlatformCpuInfoPtr != NULL)) { CopyMem(&PlatformCpuInfo, PlatformCpuInfoPtr, sizeof(EFI_PLATFORM_CPU_INFO)); } // // Update the ACPI parameter blocks finally. // VariableSize = sizeof (SYSTEM_CONFIGURATION); Status = gRT->GetVariable ( L"Setup", &mSystemConfigurationGuid, NULL, &VariableSize, &SetupVarBuffer ); ASSERT_EFI_ERROR (Status); // // Find the AcpiSupport protocol. // Status = LocateSupportProtocol (&gEfiAcpiSupportProtocolGuid, (VOID **) &AcpiSupport, 0); ASSERT_EFI_ERROR (Status); TableVersion = EFI_ACPI_TABLE_VERSION_2_0; // // Publish ACPI 1.0 or 2.0 Tables. // Status = AcpiSupport->PublishTables ( AcpiSupport, TableVersion ); ASSERT_EFI_ERROR (Status); // // S3 script save. // Status = gBS->LocateProtocol (&gEfiAcpiS3SaveProtocolGuid, NULL, (VOID **) &AcpiS3Save); if (!EFI_ERROR (Status)) { AcpiS3Save->S3Save (AcpiS3Save, NULL); } }
/** Entry point for Acpi platform driver. @param[in] ImageHandle A handle for the image that is initializing this driver. @param[in] SystemTable A pointer to the EFI system table. @retval EFI_SUCCESS Driver initialized successfully. @retval EFI_LOAD_ERROR Failed to Initialize or has been loaded. @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources. **/ EFI_STATUS EFIAPI AcpiPlatformEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_STATUS AcpiStatus; EFI_ACPI_SUPPORT_PROTOCOL *AcpiSupport; EFI_FIRMWARE_VOLUME_PROTOCOL *FwVol; INTN Instance; EFI_ACPI_COMMON_HEADER *CurrentTable; UINTN TableHandle; UINT32 FvStatus; UINT32 Size; EFI_EVENT Event; EFI_ACPI_TABLE_VERSION TableVersion; UINTN VarSize; UINTN SysCfgSize; EFI_HANDLE Handle; EFI_PS2_POLICY_PROTOCOL *Ps2Policy; EFI_PEI_HOB_POINTERS GuidHob; UINT8 PortData; EFI_MP_SERVICES_PROTOCOL *MpService; UINTN MaximumNumberOfCPUs; UINTN NumberOfEnabledCPUs; UINT32 Data32; PCH_STEPPING pchStepping; mFirstNotify = FALSE; TableVersion = EFI_ACPI_TABLE_VERSION_2_0; Instance = 0; CurrentTable = NULL; TableHandle = 0; Data32 = 0; // // Update HOB variable for PCI resource information. // Get the HOB list. If it is not present, then ASSERT. // GuidHob.Raw = GetHobList (); if (GuidHob.Raw != NULL) { if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) { mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid); } } // // Search for the Memory Configuration GUID HOB. If it is not present, then // there's nothing we can do. It may not exist on the update path. // VarSize = sizeof(SYSTEM_CONFIGURATION); Status = gRT->GetVariable( L"Setup", &mSystemConfigurationGuid, NULL, &VarSize, &mSystemConfiguration ); ASSERT_EFI_ERROR (Status); // // Find the AcpiSupport protocol. // Status = LocateSupportProtocol (&gEfiAcpiSupportProtocolGuid, (VOID **) &AcpiSupport, 0); ASSERT_EFI_ERROR (Status); // // Locate the firmware volume protocol. // Status = LocateSupportProtocol (&gEfiFirmwareVolumeProtocolGuid, (VOID **) &FwVol, 1); ASSERT_EFI_ERROR (Status); // // Read the current system configuration variable store. // SysCfgSize = sizeof(SYSTEM_CONFIGURATION); Status = gRT->GetVariable ( L"Setup", &gEfiNormalSetupGuid, NULL, &SysCfgSize, &mSystemConfig ); Status = EFI_SUCCESS; Instance = 0; // // TBD: Need re-design based on the ValleyTrail platform. // Status = gBS->LocateProtocol ( &gEfiMpServiceProtocolGuid, NULL, (VOID **) &MpService ); if (EFI_ERROR (Status)) { return Status; } // // Determine the number of processors. // MpService->GetNumberOfProcessors ( MpService, &MaximumNumberOfCPUs, &NumberOfEnabledCPUs ); // // Allocate and initialize the NVS area for SMM and ASL communication. // Status = gBS->AllocatePool ( EfiACPIMemoryNVS, sizeof (EFI_GLOBAL_NVS_AREA), (void **)&mGlobalNvsArea.Area ); ASSERT_EFI_ERROR (Status); gBS->SetMem ( mGlobalNvsArea.Area, sizeof (EFI_GLOBAL_NVS_AREA), 0 ); DEBUG((EFI_D_ERROR, "mGlobalNvsArea.Area is at 0x%X\n", mGlobalNvsArea.Area)); // // Update global NVS area for ASL and SMM init code to use. // mGlobalNvsArea.Area->ApicEnable = 1; mGlobalNvsArea.Area->EmaEnable = 0; mGlobalNvsArea.Area->NumberOfBatteries = 1; mGlobalNvsArea.Area->BatteryCapacity0 = 100; mGlobalNvsArea.Area->BatteryStatus0 = 84; mGlobalNvsArea.Area->OnboardCom = 1; mGlobalNvsArea.Area->IdeMode = 0; mGlobalNvsArea.Area->PowerState = 0; mGlobalNvsArea.Area->LogicalProcessorCount = (UINT8)NumberOfEnabledCPUs; mGlobalNvsArea.Area->PassiveThermalTripPoint = mSystemConfiguration.PassiveThermalTripPoint; mGlobalNvsArea.Area->PassiveTc1Value = mSystemConfiguration.PassiveTc1Value; mGlobalNvsArea.Area->PassiveTc2Value = mSystemConfiguration.PassiveTc2Value; mGlobalNvsArea.Area->PassiveTspValue = mSystemConfiguration.PassiveTspValue; mGlobalNvsArea.Area->CriticalThermalTripPoint = mSystemConfiguration.CriticalThermalTripPoint; mGlobalNvsArea.Area->IgdPanelType = mSystemConfiguration.IgdFlatPanel; mGlobalNvsArea.Area->IgdPanelScaling = mSystemConfiguration.PanelScaling; mGlobalNvsArea.Area->IgdSciSmiMode = 0; mGlobalNvsArea.Area->IgdTvFormat = 0; mGlobalNvsArea.Area->IgdTvMinor = 0; mGlobalNvsArea.Area->IgdSscConfig = 1; mGlobalNvsArea.Area->IgdBiaConfig = mSystemConfiguration.IgdLcdIBia; mGlobalNvsArea.Area->IgdBlcConfig = mSystemConfiguration.IgdLcdIGmchBlc; mGlobalNvsArea.Area->IgdDvmtMemSize = mSystemConfiguration.IgdDvmt50TotalAlloc; mGlobalNvsArea.Area->IgdPAVP = mSystemConfiguration.PavpMode; mGlobalNvsArea.Area->AlsEnable = mSystemConfiguration.AlsEnable; mGlobalNvsArea.Area->BacklightControlSupport = 2; mGlobalNvsArea.Area->BrightnessPercentage = 100; mGlobalNvsArea.Area->IgdState = 1; mGlobalNvsArea.Area->LidState = 1; mGlobalNvsArea.Area->DeviceId1 = 0x80000100 ; mGlobalNvsArea.Area->DeviceId2 = 0x80000400 ; mGlobalNvsArea.Area->DeviceId3 = 0x80000200 ; mGlobalNvsArea.Area->DeviceId4 = 0x04; mGlobalNvsArea.Area->DeviceId5 = 0x05; mGlobalNvsArea.Area->NumberOfValidDeviceId = 4 ; mGlobalNvsArea.Area->CurrentDeviceList = 0x0F ; mGlobalNvsArea.Area->PreviousDeviceList = 0x0F ; mGlobalNvsArea.Area->UartSelection = mSystemConfiguration.UartInterface; mGlobalNvsArea.Area->PcuUart1Enable = mSystemConfiguration.PcuUart1; mGlobalNvsArea.Area->NativePCIESupport = 1; // // Update BootMode: 0:ACPI mode; 1:PCI mode // mGlobalNvsArea.Area->LpssSccMode = mSystemConfiguration.LpssPciModeEnabled; if (mSystemConfiguration.LpssMipiHsi == 0) { mGlobalNvsArea.Area->MipiHsiAddr = 0; mGlobalNvsArea.Area->MipiHsiLen = 0; mGlobalNvsArea.Area->MipiHsi1Addr = 0; mGlobalNvsArea.Area->MipiHsi1Len = 0; } // // Platform Flavor // mGlobalNvsArea.Area->PlatformFlavor = mPlatformInfo->PlatformFlavor; // // Update the Platform id // mGlobalNvsArea.Area->BoardID = mPlatformInfo->BoardId; // // Update the Board Revision // mGlobalNvsArea.Area->FabID = mPlatformInfo->BoardRev; // // Update SOC Stepping // mGlobalNvsArea.Area->SocStepping = (UINT8)(PchStepping()); mGlobalNvsArea.Area->OtgMode = mSystemConfiguration.PchUsbOtg; pchStepping = PchStepping(); if (mSystemConfiguration.UsbAutoMode == 1) { // // Auto mode is enabled. // if (PchA0 == pchStepping) { // // For A0, EHCI is enabled as default. // mSystemConfiguration.PchUsb20 = 1; mSystemConfiguration.PchUsb30Mode = 0; mSystemConfiguration.UsbXhciSupport = 0; DEBUG ((EFI_D_INFO, "EHCI is enabled as default. SOC 0x%x\n", pchStepping)); } else { // // For A1 and later, XHCI is enabled as default. // mSystemConfiguration.PchUsb20 = 0; mSystemConfiguration.PchUsb30Mode = 1; mSystemConfiguration.UsbXhciSupport = 1; DEBUG ((EFI_D_INFO, "XHCI is enabled as default. SOC 0x%x\n", pchStepping)); } } mGlobalNvsArea.Area->XhciMode = mSystemConfiguration.PchUsb30Mode; mGlobalNvsArea.Area->Stepping = mPlatformInfo->IchRevision; // // Override invalid Pre-Boot Driver and XhciMode combination. // if ((mSystemConfiguration.UsbXhciSupport == 0) && (mSystemConfiguration.PchUsb30Mode == 3)) { mGlobalNvsArea.Area->XhciMode = 2; } if ((mSystemConfiguration.UsbXhciSupport == 1) && (mSystemConfiguration.PchUsb30Mode == 2)) { mGlobalNvsArea.Area->XhciMode = 3; } DEBUG ((EFI_D_ERROR, "ACPI NVS XHCI:0x%x\n", mGlobalNvsArea.Area->XhciMode)); mGlobalNvsArea.Area->PmicEnable = GLOBAL_NVS_DEVICE_DISABLE; mGlobalNvsArea.Area->BatteryChargingSolution = GLOBAL_NVS_DEVICE_DISABLE; mGlobalNvsArea.Area->ISPDevSel = mSystemConfiguration.ISPDevSel; mGlobalNvsArea.Area->LpeEnable = mSystemConfiguration.Lpe; if (mSystemConfiguration.ISPEn == 0) { mGlobalNvsArea.Area->ISPDevSel = GLOBAL_NVS_DEVICE_DISABLE; } mGlobalNvsArea.Area->WittEnable = mSystemConfiguration.WittEnable; mGlobalNvsArea.Area->UtsEnable = mSystemConfiguration.UtsEnable; mGlobalNvsArea.Area->SarEnable = mSystemConfiguration.SAR1; mGlobalNvsArea.Area->ReservedO = 1; SettingI2CTouchAddress(); mGlobalNvsArea.Area->IdleReserve= mSystemConfiguration.IdleReserve; // // Read BMBOUND and store it in GlobalNVS to pass into ASL. // // BUGBUG: code was moved into silicon reference code. // if (mSystemConfiguration.eMMCBootMode== 1) { // // Auto detect mode. // DEBUG ((EFI_D_ERROR, "Auto detect mode------------start\n")); // // Silicon Steppings. // switch (PchStepping()) { case PchA0: // A0/A1 case PchA1: DEBUG ((EFI_D_ERROR, "SOC A0/A1: eMMC 4.41 Configuration\n")); mSystemConfiguration.LpsseMMCEnabled = 1; mSystemConfiguration.LpsseMMC45Enabled = 0; break; case PchB0: // B0 and later. default: DEBUG ((EFI_D_ERROR, "SOC B0 and later: eMMC 4.5 Configuration\n")); mSystemConfiguration.LpsseMMCEnabled = 0; mSystemConfiguration.LpsseMMC45Enabled = 1; break; } } else if (mSystemConfiguration.eMMCBootMode == 2) { // // eMMC 4.41 // DEBUG ((EFI_D_ERROR, "Force to eMMC 4.41 Configuration\n")); mSystemConfiguration.LpsseMMCEnabled = 1; mSystemConfiguration.LpsseMMC45Enabled = 0; } else if (mSystemConfiguration.eMMCBootMode == 3) { // // eMMC 4.5 // DEBUG ((EFI_D_ERROR, "Force to eMMC 4.5 Configuration\n")); mSystemConfiguration.LpsseMMCEnabled = 0; mSystemConfiguration.LpsseMMC45Enabled = 1; } else { // // Disable eMMC controllers. // DEBUG ((EFI_D_ERROR, "Disable eMMC controllers\n")); mSystemConfiguration.LpsseMMCEnabled = 0; mSystemConfiguration.LpsseMMC45Enabled = 0; } mGlobalNvsArea.Area->emmcVersion = 0; if (mSystemConfiguration.LpsseMMCEnabled) { DEBUG ((EFI_D_ERROR, "mGlobalNvsArea.Area->emmcVersion = 0\n")); mGlobalNvsArea.Area->emmcVersion = 0; } if (mSystemConfiguration.LpsseMMC45Enabled) { DEBUG ((EFI_D_ERROR, "mGlobalNvsArea.Area->emmcVersion = 1\n")); mGlobalNvsArea.Area->emmcVersion = 1; } mGlobalNvsArea.Area->SdCardRemovable = mSystemConfiguration.SdCardRemovable; // // Microsoft IOT // if ((mSystemConfiguration.LpssHsuart0FlowControlEnabled == 1) && \ (mSystemConfiguration.LpssPwm0Enabled == 0) && \ (mSystemConfiguration.LpssPwm1Enabled == 0)) { mGlobalNvsArea.Area->MicrosoftIoT = GLOBAL_NVS_DEVICE_ENABLE; DEBUG ((EFI_D_ERROR, "JP1 is set to be MSFT IOT configuration.\n")); } else { mGlobalNvsArea.Area->MicrosoftIoT = GLOBAL_NVS_DEVICE_DISABLE; DEBUG ((EFI_D_ERROR, "JP1 is not set to be MSFT IOT configuration.\n")); } // // SIO related option. // Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (void **)&mCpuIo); ASSERT_EFI_ERROR (Status); mGlobalNvsArea.Area->WPCN381U = GLOBAL_NVS_DEVICE_DISABLE; mGlobalNvsArea.Area->DockedSioPresent = GLOBAL_NVS_DEVICE_DISABLE; if (mGlobalNvsArea.Area->DockedSioPresent != GLOBAL_NVS_DEVICE_ENABLE) { // // Check ID for SIO WPCN381U. // Status = mCpuIo->Io.Read ( mCpuIo, EfiCpuIoWidthUint8, WPCN381U_CONFIG_INDEX, 1, &PortData ); ASSERT_EFI_ERROR (Status); if (PortData != 0xFF) { PortData = 0x20; Status = mCpuIo->Io.Write ( mCpuIo, EfiCpuIoWidthUint8, WPCN381U_CONFIG_INDEX, 1, &PortData ); ASSERT_EFI_ERROR (Status); Status = mCpuIo->Io.Read ( mCpuIo, EfiCpuIoWidthUint8, WPCN381U_CONFIG_DATA, 1, &PortData ); ASSERT_EFI_ERROR (Status); if ((PortData == WPCN381U_CHIP_ID) || (PortData == WDCP376_CHIP_ID)) { mGlobalNvsArea.Area->WPCN381U = GLOBAL_NVS_DEVICE_ENABLE; mGlobalNvsArea.Area->OnboardCom = GLOBAL_NVS_DEVICE_ENABLE; mGlobalNvsArea.Area->OnboardComCir = GLOBAL_NVS_DEVICE_DISABLE; } } } // // Get Ps2 policy to set. Will be use if present. // Status = gBS->LocateProtocol ( &gEfiPs2PolicyProtocolGuid, NULL, (VOID **)&Ps2Policy ); if (!EFI_ERROR (Status)) { Status = Ps2Policy->Ps2InitHardware (ImageHandle); } mGlobalNvsArea.Area->SDIOMode = mSystemConfiguration.LpssSdioMode; Handle = NULL; Status = gBS->InstallMultipleProtocolInterfaces ( &Handle, &gEfiGlobalNvsAreaProtocolGuid, &mGlobalNvsArea, NULL ); // // Read tables from the storage file. // while (!EFI_ERROR (Status)) { CurrentTable = NULL; Status = FwVol->ReadSection ( FwVol, &gEfiAcpiTableStorageGuid, EFI_SECTION_RAW, Instance, (VOID **) &CurrentTable, (UINTN *) &Size, &FvStatus ); if (!EFI_ERROR (Status)) { // // Allow platform specific code to reject the table or update it. // AcpiStatus = AcpiPlatformHooksIsActiveTable (CurrentTable); if (!EFI_ERROR (AcpiStatus)) { // // Perform any table specific updates. // AcpiStatus = PlatformUpdateTables (CurrentTable); if (!EFI_ERROR (AcpiStatus)) { // // Add the table. // TableHandle = 0; AcpiStatus = AcpiSupport->SetAcpiTable ( AcpiSupport, CurrentTable, TRUE, TableVersion, &TableHandle ); ASSERT_EFI_ERROR (AcpiStatus); } } // // Increment the instance. // Instance++; } } Status = EfiCreateEventReadyToBootEx ( TPL_NOTIFY, OnReadyToBoot, NULL, &Event ); // // Finished. // return EFI_SUCCESS; }
/** Register the callback function for ReportStatusCode() notification. When this function is called the function pointer is added to an internal list and any future calls to ReportStatusCode() will be forwarded to the Callback function. @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is called when a call to ReportStatusCode() occurs. @retval EFI_SUCCESS Function was successfully registered. @retval EFI_INVALID_PARAMETER The callback function was NULL. @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be registered. @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again. **/ EFI_STATUS EFIAPI Register ( IN EFI_PEI_RSC_HANDLER_CALLBACK Callback ) { EFI_PEI_HOB_POINTERS Hob; EFI_PEI_RSC_HANDLER_CALLBACK *CallbackEntry; UINTN *NumberOfEntries; UINTN Index; UINTN FreeEntryIndex; UINTN *FreePacket; if (Callback == NULL) { return EFI_INVALID_PARAMETER; } Hob.Raw = GetFirstGuidHob (&gStatusCodeCallbackGuid); FreePacket = NULL; FreeEntryIndex = 0; while (Hob.Raw != NULL) { NumberOfEntries = GET_GUID_HOB_DATA (Hob); CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *) (NumberOfEntries + 1); if (FreePacket == NULL && *NumberOfEntries < 64) { // // If current total number of handlers does not exceed 64, put new handler // at the last of packet // FreePacket = NumberOfEntries; FreeEntryIndex = *NumberOfEntries; } for (Index = 0; Index < *NumberOfEntries; Index++) { if (CallbackEntry[Index] == Callback) { // // If the function was already registered. It can't be registered again. // return EFI_ALREADY_STARTED; } if (FreePacket == NULL && CallbackEntry[Index] == NULL) { // // If the total number of handlers in current packet is max value 64, // search an entry with NULL pointer and fill new handler into this entry. // FreePacket = NumberOfEntries; FreeEntryIndex = Index; } } Hob.Raw = GET_NEXT_HOB (Hob); Hob.Raw = GetNextGuidHob (&gStatusCodeCallbackGuid, Hob.Raw); } if (FreePacket == NULL) { FreePacket = CreateRscHandlerCallbackPacket(); } CallbackEntry = (EFI_PEI_RSC_HANDLER_CALLBACK *) (FreePacket + 1); CallbackEntry[FreeEntryIndex] = Callback; if (*FreePacket == FreeEntryIndex) { // // If new registered callback is added as a new entry in the packet, // increase the total number of handlers in the packet. // *FreePacket += 1; } return EFI_SUCCESS; }