SourceLevelDebugPkg/DebugCommLibUsb3Pei: Make sure alloc physical mem

PI 1.6 has supported pre permanent memory page allocation,
to make sure the allocated memory is physical memory for DMA,
the patch is to check memory discovered PPI installed or not first
before calling AllocatePages.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
This commit is contained in:
Star Zeng 2017-08-31 16:53:16 +08:00
parent c00ad62378
commit 364f63c065
2 changed files with 24 additions and 9 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
Debug Port Library implementation based on usb3 debug port. Debug Port Library implementation based on usb3 debug port.
Copyright (c) 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
@ -14,6 +14,7 @@
#include <PiPei.h> #include <PiPei.h>
#include <Library/PeiServicesLib.h> #include <Library/PeiServicesLib.h>
#include <Ppi/MemoryDiscovered.h>
#include "DebugCommunicationLibUsb3Internal.h" #include "DebugCommunicationLibUsb3Internal.h"
/** /**
@ -32,14 +33,25 @@ AllocateAlignBuffer (
VOID *Buf; VOID *Buf;
EFI_PHYSICAL_ADDRESS Address; EFI_PHYSICAL_ADDRESS Address;
EFI_STATUS Status; EFI_STATUS Status;
VOID *MemoryDiscoveredPpi;
Buf = NULL; Buf = NULL;
//
// Make sure the allocated memory is physical memory.
//
Status = PeiServicesLocatePpi (
&gEfiPeiMemoryDiscoveredPpiGuid,
0,
NULL,
(VOID **) &MemoryDiscoveredPpi
);
if (!EFI_ERROR (Status)) {
Status = PeiServicesAllocatePages (EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (BufferSize), &Address); Status = PeiServicesAllocatePages (EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (BufferSize), &Address);
if (EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Buf = NULL;
} else {
Buf = (VOID *)(UINTN) Address; Buf = (VOID *)(UINTN) Address;
} }
}
return Buf; return Buf;
} }

View File

@ -1,7 +1,7 @@
## @file ## @file
# Debug Communication Library instance based on usb3 debug port. # Debug Communication Library instance based on usb3 debug port.
# #
# Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
# #
# This program and the accompanying materials # This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License # are licensed and made available under the terms and conditions of the BSD License
@ -40,6 +40,9 @@
IntelFrameworkPkg/IntelFrameworkPkg.dec IntelFrameworkPkg/IntelFrameworkPkg.dec
SourceLevelDebugPkg/SourceLevelDebugPkg.dec SourceLevelDebugPkg/SourceLevelDebugPkg.dec
[Ppis]
gEfiPeiMemoryDiscoveredPpiGuid ## CONSUMES
[Pcd] [Pcd]
# The memory BAR of ehci host controller, in which usb debug feature is enabled. # The memory BAR of ehci host controller, in which usb debug feature is enabled.
# Note that the memory BAR address is only used before Pci bus resource allocation. # Note that the memory BAR address is only used before Pci bus resource allocation.