public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] SourceLevelDebugPkg/DebugCommLibUsb3Pei: Make sure alloc physical mem
@ 2017-08-31  9:11 Star Zeng
  2017-09-01  6:24 ` Wu, Hao A
  0 siblings, 1 reply; 3+ messages in thread
From: Star Zeng @ 2017-08-31  9:11 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Ruiyu Ni, Hao Wu

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>
---
 .../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 be3174e75fd6..902a3b626acc 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.<BR>
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
   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 <PiPei.h>
 #include <Library/PeiServicesLib.h>
+#include <Ppi/MemoryDiscovered.h>
 #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 74dcdd124b47..6cd5e1068333 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.<BR>
+#  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -40,6 +40,9 @@ [Packages]
   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.
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] SourceLevelDebugPkg/DebugCommLibUsb3Pei: Make sure alloc physical mem
  2017-08-31  9:11 [PATCH] SourceLevelDebugPkg/DebugCommLibUsb3Pei: Make sure alloc physical mem Star Zeng
@ 2017-09-01  6:24 ` Wu, Hao A
  2017-09-01  6:34   ` Ni, Ruiyu
  0 siblings, 1 reply; 3+ messages in thread
From: Wu, Hao A @ 2017-09-01  6:24 UTC (permalink / raw)
  To: Zeng, Star, edk2-devel@lists.01.org; +Cc: Ni, Ruiyu, Zeng, Star

Reviewed-by: Hao Wu <hao.a.wu@intel.com>


Best Regards,
Hao Wu


> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Star
> Zeng
> Sent: Thursday, August 31, 2017 5:11 PM
> To: edk2-devel@lists.01.org
> Cc: Ni, Ruiyu; Wu, Hao A; Zeng, Star
> Subject: [edk2] [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 <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>
> ---
>  .../DebugCommunicationLibUsb3Pei.c                 | 28 +++++++++++++++-------
>  .../DebugCommunicationLibUsb3Pei.inf               |  5 +++-
>  2 files changed, 24 insertions(+), 9 deletions(-)
> 
> diff --git
> a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommun
> icationLibUsb3Pei.c
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommun
> icationLibUsb3Pei.c
> index be3174e75fd6..902a3b626acc 100644
> ---
> a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommun
> icationLibUsb3Pei.c
> +++
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommun
> icationLibUsb3Pei.c
> @@ -1,7 +1,7 @@
>  /** @file
>    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
>    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 <PiPei.h>
>  #include <Library/PeiServicesLib.h>
> +#include <Ppi/MemoryDiscovered.h>
>  #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/DebugCommun
> icationLibUsb3Pei.inf
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommun
> icationLibUsb3Pei.inf
> index 74dcdd124b47..6cd5e1068333 100644
> ---
> a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommun
> icationLibUsb3Pei.inf
> +++
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommun
> icationLibUsb3Pei.inf
> @@ -1,7 +1,7 @@
>  ## @file
>  #  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
>  #  are licensed and made available under the terms and conditions of the BSD
> License
> @@ -40,6 +40,9 @@ [Packages]
>    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.
> --
> 2.7.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] SourceLevelDebugPkg/DebugCommLibUsb3Pei: Make sure alloc physical mem
  2017-09-01  6:24 ` Wu, Hao A
@ 2017-09-01  6:34   ` Ni, Ruiyu
  0 siblings, 0 replies; 3+ messages in thread
From: Ni, Ruiyu @ 2017-09-01  6:34 UTC (permalink / raw)
  To: Wu, Hao A, Zeng, Star, edk2-devel@lists.01.org; +Cc: Zeng, Star

Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: Wu, Hao A
> Sent: Friday, September 1, 2017 2:24 PM
> To: Zeng, Star <star.zeng@intel.com>; edk2-devel@lists.01.org
> Cc: Ni, Ruiyu <ruiyu.ni@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: RE: [edk2] [PATCH] SourceLevelDebugPkg/DebugCommLibUsb3Pei:
> Make sure alloc physical mem
> 
> Reviewed-by: Hao Wu <hao.a.wu@intel.com>
> 
> 
> Best Regards,
> Hao Wu
> 
> 
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> > Star Zeng
> > Sent: Thursday, August 31, 2017 5:11 PM
> > To: edk2-devel@lists.01.org
> > Cc: Ni, Ruiyu; Wu, Hao A; Zeng, Star
> > Subject: [edk2] [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 <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>
> > ---
> >  .../DebugCommunicationLibUsb3Pei.c                 | 28 +++++++++++++++-----
> --
> >  .../DebugCommunicationLibUsb3Pei.inf               |  5 +++-
> >  2 files changed, 24 insertions(+), 9 deletions(-)
> >
> > diff --git
> >
> a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom
> mun
> > icationLibUsb3Pei.c
> >
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom
> mun
> > icationLibUsb3Pei.c
> > index be3174e75fd6..902a3b626acc 100644
> > ---
> >
> a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom
> mun
> > icationLibUsb3Pei.c
> > +++
> >
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom
> mun
> > icationLibUsb3Pei.c
> > @@ -1,7 +1,7 @@
> >  /** @file
> >    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
> >    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 <PiPei.h>
> >  #include <Library/PeiServicesLib.h>
> > +#include <Ppi/MemoryDiscovered.h>
> >  #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/DebugCom
> mun
> > icationLibUsb3Pei.inf
> >
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom
> mun
> > icationLibUsb3Pei.inf
> > index 74dcdd124b47..6cd5e1068333 100644
> > ---
> >
> a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom
> mun
> > icationLibUsb3Pei.inf
> > +++
> >
> b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom
> mun
> > icationLibUsb3Pei.inf
> > @@ -1,7 +1,7 @@
> >  ## @file
> >  #  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  #  are licensed and
> > made available under the terms and conditions of the BSD License @@
> > -40,6 +40,9 @@ [Packages]
> >    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.
> > --
> > 2.7.0.windows.1
> >
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-01  6:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-31  9:11 [PATCH] SourceLevelDebugPkg/DebugCommLibUsb3Pei: Make sure alloc physical mem Star Zeng
2017-09-01  6:24 ` Wu, Hao A
2017-09-01  6:34   ` Ni, Ruiyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox