X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ArmPlatformPkg%2FMemoryInitPei%2FMemoryInitPeim.c;h=25baac170c6c087406cb0955bd7208f6d341ec92;hp=d745357164eb5fb4a3f4521e2700259f153933d3;hb=984ec7588d569cc35dcbdd3c45a86088c4366eeb;hpb=bf72cf3381c20703042c5a574ec4ba689abd4430 diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c index d745357164..25baac170c 100755 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c @@ -1,14 +1,14 @@ /** @file * * Copyright (c) 2011, ARM Limited. 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. +* 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. * **/ @@ -63,7 +63,7 @@ BuildMemoryTypeInformationHob ( Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode); Info[8].Type = EfiLoaderData; Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData); - + // Terminator for the list Info[9].Type = EfiMaxMemoryType; Info[9].NumberOfPages = 0; @@ -75,13 +75,13 @@ BuildMemoryTypeInformationHob ( Routine Description: - + Arguments: FileHandle - Handle of the file being invoked. PeiServices - Describes the list of possible PEI Services. - + Returns: Status - EFI_SUCCESS if the boot mode could be set @@ -95,39 +95,58 @@ InitializeMemory ( ) { EFI_STATUS Status; - EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; - ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR* EfiMemoryMap; - UINTN Index; - UINTN SystemMemoryTop; + UINTN SystemMemoryBase; + UINT64 SystemMemoryTop; + UINTN FdBase; + UINTN FdTop; UINTN UefiMemoryBase; - UINTN UefiMemorySize; - DEBUG ((EFI_D_ERROR, "Memory Init PEIM Loaded\n")); - - // Ensure PcdSystemMemorySize has been set - ASSERT (FixedPcdGet32 (PcdSystemMemorySize) != 0); - - SystemMemoryTop = (UINTN)FixedPcdGet32 (PcdSystemMemoryBase) + (UINTN)FixedPcdGet32 (PcdSystemMemorySize); + DEBUG ((EFI_D_LOAD | EFI_D_INFO, "Memory Init PEIM Loaded\n")); // // Initialize the System Memory (DRAM) // - if (PcdGet32 (PcdStandalone)) { - // In case of a standalone version, the DRAM is already initialized - ArmPlatformInitializeSystemMemory(); + if (!FeaturePcdGet (PcdSystemMemoryInitializeInSec)) { + // In case the DRAM has not been initialized by the secure firmware + ArmPlatformInitializeSystemMemory (); + } + + // Ensure PcdSystemMemorySize has been set + ASSERT (PcdGet64 (PcdSystemMemorySize) != 0); + + SystemMemoryBase = (UINTN)PcdGet64 (PcdSystemMemoryBase); + SystemMemoryTop = SystemMemoryBase + PcdGet64 (PcdSystemMemorySize); + if (SystemMemoryTop - 1 > MAX_ADDRESS) { + SystemMemoryTop = (UINT64)MAX_ADDRESS + 1; } + FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress); + FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize); // // Declare the UEFI memory to PEI // - if (PcdGet32 (PcdStandalone)) { - // In case of standalone UEFI, we set the UEFI memory region at the top of the DRAM - UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + + // In case the firmware has been shadowed in the System Memory + if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) { + // Check if there is enough space between the top of the system memory and the top of the + // firmware to place the UEFI memory (for PEI & DXE phases) + if (SystemMemoryTop - FdTop >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) { + UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + } else { + // Check there is enough space for the UEFI memory + ASSERT (SystemMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) <= FdBase); + + UefiMemoryBase = FdBase - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + } } else { - // In case of a non standalone UEFI, we set the UEFI memory below the Firmware Volume - UefiMemoryBase = FixedPcdGet32 (PcdNormalFdBaseAddress) - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); + // Check the Firmware does not overlapped with the system memory + ASSERT ((FdBase < SystemMemoryBase) || (FdBase >= SystemMemoryTop)); + ASSERT ((FdTop <= SystemMemoryBase) || (FdTop > SystemMemoryTop)); + + UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); } - Status = PeiServicesInstallPeiMemory (UefiMemoryBase,FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); + + Status = PeiServicesInstallPeiMemory (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); ASSERT_EFI_ERROR (Status); // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)