MdeModulePkg/XhciPei: Fix Aligned Page Allocation

Add support for allocating aligned pages at an alignment higher
than 4K. The new function allocated memory taking into account
the padding required and then frees up unused pages before mapping
it.

Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
This commit is contained in:
Ashish Singhal
2019-10-16 01:20:47 +08:00
committed by Matt DeVillier
parent 6bd9d60b41
commit 4ba839c5c8
3 changed files with 160 additions and 21 deletions

View File

@@ -569,11 +569,7 @@ UsbHcAllocateAlignedPages (
{
EFI_STATUS Status;
VOID *Memory;
UINTN AlignedMemory;
UINTN AlignmentMask;
EFI_PHYSICAL_ADDRESS DeviceMemory;
UINTN AlignedDeviceMemory;
UINTN RealPages;
//
// Alignment must be a power of two or zero.
@@ -589,18 +585,9 @@ UsbHcAllocateAlignedPages (
}
if (Alignment > EFI_PAGE_SIZE) {
//
// Calculate the total number of pages since alignment is larger than page size.
//
AlignmentMask = Alignment - 1;
RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
//
// Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
//
ASSERT (RealPages > Pages);
Status = IoMmuAllocateBuffer (
Status = IoMmuAllocateAlignedBuffer (
Pages,
Alignment,
&Memory,
&DeviceMemory,
Mapping
@@ -608,8 +595,6 @@ UsbHcAllocateAlignedPages (
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;
AlignedDeviceMemory = ((UINTN) DeviceMemory + AlignmentMask) & ~AlignmentMask;
} else {
//
// Do not over-allocate pages in this case.
@@ -623,12 +608,10 @@ UsbHcAllocateAlignedPages (
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
AlignedMemory = (UINTN) Memory;
AlignedDeviceMemory = (UINTN) DeviceMemory;
}
*HostAddress = (VOID *) AlignedMemory;
*DeviceAddress = (EFI_PHYSICAL_ADDRESS) AlignedDeviceMemory;
*HostAddress = Memory;
*DeviceAddress = DeviceMemory;
return EFI_SUCCESS;
}