From d2a217ee6f815e569ea1ab8fd9f0070a80465f43 Mon Sep 17 00:00:00 2001 From: Guo Mang Date: Fri, 23 Dec 2016 13:29:25 +0800 Subject: BroxtonPlatformPkg: Add MinnowBoard3/BoardInitPreMem Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang --- .../Board/MinnowBoard3/BoardInitPreMem/BoardInit.c | 184 +++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 Platform/BroxtonPlatformPkg/Board/MinnowBoard3/BoardInitPreMem/BoardInit.c (limited to 'Platform/BroxtonPlatformPkg/Board/MinnowBoard3/BoardInitPreMem/BoardInit.c') diff --git a/Platform/BroxtonPlatformPkg/Board/MinnowBoard3/BoardInitPreMem/BoardInit.c b/Platform/BroxtonPlatformPkg/Board/MinnowBoard3/BoardInitPreMem/BoardInit.c new file mode 100644 index 0000000000..bb82d4e2dc --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Board/MinnowBoard3/BoardInitPreMem/BoardInit.c @@ -0,0 +1,184 @@ +/** @file + Board Init driver. + + Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include "BoardInit.h" +#include "PlatformId.h" +#include "BoardInitMiscs.h" + +EFI_STATUS +EFIAPI +MinnowBoard3PreMemInit ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN PEI_BOARD_PRE_MEM_INIT_PPI *This + ); + +static PEI_BOARD_PRE_MEM_INIT_PPI mPreMemInitPpiInstance = { + MinnowBoard3PreMemInit +}; + +static EFI_PEI_PPI_DESCRIPTOR mMinnowBoard3PreMemInitPpi = { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gBoardPreMemInitPpiGuid, + &mPreMemInitPpiInstance +}; + +static EFI_PEI_PPI_DESCRIPTOR mMinnowBoard3PreMemInitDonePpi = { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gBoardPreMemInitDoneGuid, + NULL +}; + +EFI_STATUS +EFIAPI +MinnowBoard3PreMemInit ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN PEI_BOARD_PRE_MEM_INIT_PPI *This + ) +{ + EFI_STATUS Status; + VOID *Instance; + UINT8 BoardId; + UINT8 FabId; + + BoardId = 0; + FabId = 0; + Status = PeiServicesLocatePpi ( + &gBoardPreMemInitDoneGuid, + 0, + NULL, + &Instance + ); + if (!EFI_ERROR (Status)) { + DEBUG ((EFI_D_INFO, "Minnow Board 3 Pre Mem Init: Skip\n")); + return EFI_SUCCESS; + } + + DEBUG ((EFI_D_INFO, "Minnow Board 3 Pre Mem Init\n")); + + // + // Pre Mem Board Init + // + Status = GetEmbeddedBoardIdFabId (PeiServices, &BoardId, &FabId); + + if (BoardId != (UINT8) BOARD_ID_MINNOW) { + DEBUG ((EFI_D_INFO, "Not a Minnow Board - skip\n")); + return EFI_SUCCESS; + } + + PcdSet8 (PcdBoardId, BoardId); + PcdSet8 (PcdFabId, FabId); + + // + // Set board specific function as dynamic PCD to be called by common platform code + // + PcdSet64 (PcdUpdateFspmUpdFunc, (UINT64) (UINTN) mMb3UpdateFspmUpdPtr); + PcdSet64 (PcdDramCreatePolicyDefaultsFunc, (UINT64) (UINTN) mMb3DramCreatePolicyDefaultsPtr); + + // + // Install a flag signalling a board is detected and pre-mem init is done + // + Status = PeiServicesInstallPpi (&mMinnowBoard3PreMemInitDonePpi); + + return EFI_SUCCESS; +} + + +/** + This function performs Board initialization in Pre-Memory. + + @retval EFI_SUCCESS The PPI is installed and initialized. + @retval EFI ERRORS The PPI is not successfully installed. + @retval EFI_OUT_OF_RESOURCES No enough resoruces (such as out of memory). + +**/ +EFI_STATUS +EFIAPI +MinnowBoard3InitConstructor ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + VOID *Ppi; + EFI_PEI_PPI_DESCRIPTOR *PeiPpiDescriptor; + UINTN Instance; + + DEBUG ((EFI_D_INFO, "MinnowBoard3 Pre Mem Init Constructor \n")); + + Status = PeiServicesLocatePpi ( + &gBoardPreMemInitDoneGuid, + 0, + &PeiPpiDescriptor, + &Ppi + ); + if (!EFI_ERROR (Status)) { + // + // Board detection previously done, so this is a re-invocation shadowed in memory. + // Reinstall PPIs to eliminate PPI descriptors in torn down temp RAM. + // + // + // Reinstall PreMemInit Done PPI + // + DEBUG ((EFI_D_INFO, "Reinstall Pre Mem Init Done PPI\n")); + Status = PeiServicesReInstallPpi ( + PeiPpiDescriptor, + &mMinnowBoard3PreMemInitDonePpi + ); + ASSERT_EFI_ERROR (Status); + + // + // Reinstall all instances of Pre Mem Init PPIs. + // These PPIs are no longer used so it doesn't matter which board's instance is finally installed. + // According to PeiServicesReInstallPpi behavior: + // The first run of this loop would replace all descrioptors with a singe in-RAM descriptor; + // Subsequent runs of this loop will only replace the first (already in-RAM) descriptor. + // As long as all descriptors are in ram, we are fine. + // + Instance = 0; + do { + Status = PeiServicesLocatePpi ( + &gBoardPreMemInitPpiGuid, + Instance, + &PeiPpiDescriptor, + &Ppi + ); + if (Status == EFI_NOT_FOUND) { + break; + } + ASSERT_EFI_ERROR (Status); + DEBUG ((EFI_D_INFO, "Reinstall Pre Mem Init PPI\n")); + Status = PeiServicesReInstallPpi ( + PeiPpiDescriptor, + &mMinnowBoard3PreMemInitPpi + ); + ASSERT_EFI_ERROR (Status); + + Instance++; + } while (TRUE); + return Status; + } + + DEBUG ((EFI_D_INFO, "Install Pre Mem Init PPI \n")); + Status = PeiServicesInstallPpi (&mMinnowBoard3PreMemInitPpi); + return Status; +} + -- cgit v1.2.3