From 364f63c06533a4de83e6f35ee698700bb24f735f Mon Sep 17 00:00:00 2001 From: Star Zeng Date: Thu, 31 Aug 2017 16:53:16 +0800 Subject: [PATCH] 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 Cc: Hao Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Ruiyu Ni Reviewed-by: Hao Wu --- .../DebugCommunicationLibUsb3Pei.c | 28 +++++++++++++------ .../DebugCommunicationLibUsb3Pei.inf | 5 +++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c index be3174e75f..902a3b626a 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c @@ -1,7 +1,7 @@ /** @file Debug Port Library implementation based on usb3 debug port. - Copyright (c) 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2017, 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 @@ -14,6 +14,7 @@ #include #include +#include #include "DebugCommunicationLibUsb3Internal.h" /** @@ -32,13 +33,24 @@ AllocateAlignBuffer ( VOID *Buf; EFI_PHYSICAL_ADDRESS Address; EFI_STATUS Status; - - Buf = NULL; - Status = PeiServicesAllocatePages (EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (BufferSize), &Address); - if (EFI_ERROR (Status)) { - Buf = NULL; - } else { - Buf = (VOID *)(UINTN) Address; + VOID *MemoryDiscoveredPpi; + + 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); + if (!EFI_ERROR (Status)) { + Buf = (VOID *)(UINTN) Address; + } } return Buf; } diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf index 74dcdd124b..6cd5e10683 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf @@ -1,7 +1,7 @@ ## @file # Debug Communication Library instance based on usb3 debug port. # -# Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2014 - 2017, 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 @@ -40,6 +40,9 @@ IntelFrameworkPkg/IntelFrameworkPkg.dec SourceLevelDebugPkg/SourceLevelDebugPkg.dec +[Ppis] + gEfiPeiMemoryDiscoveredPpiGuid ## CONSUMES + [Pcd] # 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.