X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPei%2FMemory%2FMemoryServices.c;h=719372e0612801176d6bd47d68c0c12b791b69f0;hb=e1e7e0fb3759d520517249ef696c4b67f614b47a;hp=1213702c680580e9968dedaee49821bb4db9bca2;hpb=5e574a01ca816e1e1dc0863c61b92d7638a6d5fd;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index 1213702c68..719372e061 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -1,7 +1,7 @@ /** @file EFI PEI Core memory services -Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2015, 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 @@ -96,7 +96,7 @@ PeiInstallPeiMemory ( // if (PrivateData->PeiMemoryInstalled) { DEBUG ((EFI_D_ERROR, "ERROR: PeiInstallPeiMemory is called more than once!\n")); - ASSERT (PrivateData->PeiMemoryInstalled); + ASSERT (FALSE); return EFI_SUCCESS; } @@ -123,7 +123,7 @@ PeiInstallPeiMemory ( @retval EFI_OUT_OF_RESOURCES The pages could not be allocated. @retval EFI_INVALID_PARAMETER Type is not equal to EfiLoaderCode, EfiLoaderData, EfiRuntimeServicesCode, EfiRuntimeServicesData, EfiBootServicesCode, EfiBootServicesData, - EfiACPIReclaimMemory, or EfiACPIMemoryNVS. + EfiACPIReclaimMemory, EfiReservedMemoryType, or EfiACPIMemoryNVS. **/ EFI_STATUS @@ -140,6 +140,8 @@ PeiAllocatePages ( EFI_PHYSICAL_ADDRESS *FreeMemoryTop; EFI_PHYSICAL_ADDRESS *FreeMemoryBottom; UINTN RemainingPages; + UINTN Granularity; + UINTN Padding; if ((MemoryType != EfiLoaderCode) && (MemoryType != EfiLoaderData) && @@ -148,10 +150,25 @@ PeiAllocatePages ( (MemoryType != EfiBootServicesCode) && (MemoryType != EfiBootServicesData) && (MemoryType != EfiACPIReclaimMemory) && + (MemoryType != EfiReservedMemoryType) && (MemoryType != EfiACPIMemoryNVS)) { return EFI_INVALID_PARAMETER; } + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY && + (MemoryType == EfiACPIReclaimMemory || + MemoryType == EfiACPIMemoryNVS || + MemoryType == EfiRuntimeServicesCode || + MemoryType == EfiRuntimeServicesData)) { + + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + + DEBUG ((DEBUG_INFO, "AllocatePages: aligning allocation to %d KB\n", + Granularity / SIZE_1KB)); + } + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); Hob.Raw = PrivateData->HobList.Raw; @@ -175,9 +192,27 @@ PeiAllocatePages ( } // - // Check to see if on 4k boundary, If not aligned, make the allocation aligned. + // Check to see if on correct boundary for the memory type. + // If not aligned, make the allocation aligned. // - *(FreeMemoryTop) -= *(FreeMemoryTop) & 0xFFF; + Padding = *(FreeMemoryTop) & (Granularity - 1); + if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < Padding) { + DEBUG ((DEBUG_ERROR, "AllocatePages failed: Out of space after padding.\n")); + return EFI_OUT_OF_RESOURCES; + } + + *(FreeMemoryTop) -= Padding; + if (Padding >= EFI_PAGE_SIZE) { + // + // Create a memory allocation HOB to cover + // the pages that we will lose to rounding + // + BuildMemoryAllocationHob ( + *(FreeMemoryTop), + Padding & ~(UINTN)EFI_PAGE_MASK, + EfiConventionalMemory + ); + } // // Verify that there is sufficient memory to satisfy the allocation. @@ -191,6 +226,7 @@ PeiAllocatePages ( // // The number of remaining pages needs to be greater than or equal to that of the request pages. // + Pages = ALIGN_VALUE (Pages, EFI_SIZE_TO_PAGES (Granularity)); if (RemainingPages < Pages) { DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages)); DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages)); @@ -221,7 +257,7 @@ PeiAllocatePages ( /** - Pool allocation service. Before permenent memory is discoveried, the pool will + Pool allocation service. Before permanent memory is discoveried, the pool will be allocated the heap in the temporary memory. Genenrally, the size of heap in temporary memory does not exceed to 64K, so the biggest pool size could be allocated is 64K.