X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPei%2FMemory%2FMemoryServices.c;h=d24897d7767b505022f074df42f25342b67881b3;hp=7e841c3c461a7ef35888a6a518ca4b943ba9476e;hb=14941e689f3d4b006ba263de494c5b9e386a546a;hpb=1bd90a4c479759542f86dbac953855552cbb31fa diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index 7e841c3c46..d24897d776 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -18,7 +18,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Initialize the memory services. - @param PrivateData Points to PeiCore's private instance data. + + @param PrivateData Add parameter description @param SecCoreData Points to a data structure containing information about the PEI core's operating environment, such as the size and location of temporary RAM, the stack location and the BFV location. @@ -75,13 +76,9 @@ InitializeMemoryServices ( /** - This function registers the found memory configuration with the PEI Foundation. + Install the permanent memory is now available. + Creates HOB (PHIT and Stack). - The usage model is that the PEIM that discovers the permanent memory shall invoke this service. - This routine will hold discoveried memory information into PeiCore's private data, - and set SwitchStackSignal flag. After PEIM who discovery memory is dispatched, - PeiDispatcher will migrate temporary memory to permenement memory. - @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. @param MemoryBegin Start of memory address. @param MemoryLength Length of memory. @@ -123,6 +120,7 @@ PeiInstallPeiMemory ( @param Memory Pointer of memory allocated. @retval EFI_SUCCESS The allocation was successful + @retval EFI_INVALID_PARAMETER Only AllocateAnyAddress is supported. @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available @retval EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement to allocate the number of pages. @@ -131,14 +129,15 @@ PeiInstallPeiMemory ( EFI_STATUS EFIAPI PeiAllocatePages ( - IN CONST EFI_PEI_SERVICES **PeiServices, - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN Pages, - OUT EFI_PHYSICAL_ADDRESS *Memory + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + OUT EFI_PHYSICAL_ADDRESS *Memory ) { PEI_CORE_INSTANCE *PrivateData; EFI_PEI_HOB_POINTERS Hob; + EFI_PHYSICAL_ADDRESS Offset; EFI_PHYSICAL_ADDRESS *FreeMemoryTop; EFI_PHYSICAL_ADDRESS *FreeMemoryBottom; @@ -151,7 +150,7 @@ PeiAllocatePages ( if (!PrivateData->PeiMemoryInstalled) { // // When PeiInstallMemory is called but CAR has *not* been moved to temporary memory, - // the AllocatePage will dependent on the field of PEI_CORE_INSTANCE structure. + // the AllocatePage will dependent the field of PEI_CORE_INSTANCE structure. // if (!PrivateData->SwitchStackSignal) { return EFI_NOT_AVAILABLE_YET; @@ -165,9 +164,16 @@ PeiAllocatePages ( } // - // Check to see if on 4k boundary, If not aligned, make the allocation aligned. + // Check to see if on 4k boundary // - *(FreeMemoryTop) -= *(FreeMemoryTop) & 0xFFF; + Offset = *(FreeMemoryTop) & 0xFFF; + + // + // If not aligned, make the allocation aligned. + // + if (Offset != 0) { + *(FreeMemoryTop) -= Offset; + } // // Verify that there is sufficient memory to satisfy the allocation @@ -204,14 +210,12 @@ PeiAllocatePages ( /** - Pool allocation service. Before permenent memory is discoveried, the pool will - be allocated the heap in the CAR. Genenrally, the size of heap in temporary - memory does not exceed to 64K, so the biggest pool size could be allocated is - 64K. + Memory allocation service on the CAR. + - @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. - @param Size Amount of memory required - @param Buffer Address of pointer to the buffer + @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. + @param Size Amount of memory required + @param Buffer Address of pointer to the buffer @retval EFI_SUCCESS The allocation was successful @retval EFI_OUT_OF_RESOURCES There is not enough heap to satisfy the requirement @@ -221,30 +225,26 @@ PeiAllocatePages ( EFI_STATUS EFIAPI PeiAllocatePool ( - IN CONST EFI_PEI_SERVICES **PeiServices, - IN UINTN Size, - OUT VOID **Buffer + IN CONST EFI_PEI_SERVICES **PeiServices, + IN UINTN Size, + OUT VOID **Buffer ) { EFI_STATUS Status; EFI_HOB_MEMORY_POOL *Hob; - // - // If some "post-memory" PEIM wishes to allocate larger pool, - // it should use AllocatePages service instead. - // - - // - // Generally, the size of heap in temporary memory does not exceed to 64K, - // so the maxmium size of pool is 0x10000 - sizeof (EFI_HOB_MEMORY_POOL) - // - ASSERT (Size < 0x10000 - sizeof (EFI_HOB_MEMORY_POOL)); - Status = PeiServicesCreateHob ( + // + // If some "post-memory" PEIM wishes to allocate larger pool, + // it should use AllocatePages service instead. + // + ASSERT (Size < 0x10000 - sizeof (EFI_HOB_MEMORY_POOL)); + Status = PeiServicesCreateHob ( EFI_HOB_TYPE_MEMORY_POOL, (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size), (VOID **)&Hob ); *Buffer = Hob+1; + return Status; }