]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
SourceLevelDebugPkg/DebugCommLibUsb3Pei: Make sure alloc physical mem
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugCommunicationLibUsb3 / DebugCommunicationLibUsb3Pei.c
index be3174e75fd643274e594bddcd075cc0bbc8d71e..902a3b626accf8a740b89b917fd0afb6168678ec 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Port Library implementation based on usb3 debug port.\r
 \r
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -14,6 +14,7 @@
 \r
 #include <PiPei.h>\r
 #include <Library/PeiServicesLib.h>\r
+#include <Ppi/MemoryDiscovered.h>\r
 #include "DebugCommunicationLibUsb3Internal.h"\r
 \r
 /**\r
@@ -32,13 +33,24 @@ AllocateAlignBuffer (
   VOID                     *Buf;\r
   EFI_PHYSICAL_ADDRESS     Address;\r
   EFI_STATUS               Status;\r
-  \r
-  Buf = NULL;  \r
-  Status = PeiServicesAllocatePages (EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (BufferSize), &Address);\r
-  if (EFI_ERROR (Status)) {\r
-    Buf = NULL;\r
-  } else {\r
-    Buf = (VOID *)(UINTN) Address;\r
+  VOID                     *MemoryDiscoveredPpi;\r
+\r
+  Buf = NULL;\r
+\r
+  //\r
+  // Make sure the allocated memory is physical memory.\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+             &gEfiPeiMemoryDiscoveredPpiGuid,\r
+             0,\r
+             NULL,\r
+             (VOID **) &MemoryDiscoveredPpi\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = PeiServicesAllocatePages (EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (BufferSize), &Address);\r
+    if (!EFI_ERROR (Status)) {\r
+      Buf = (VOID *)(UINTN) Address;\r
+    }\r
   }\r
   return Buf;\r
 }\r