diff mbox

[edk2,3/5] ArmPkg/ArmDmaLib: interpret GCD attributes as a bit field

Message ID 1461077734-4327-3-git-send-email-ard.biesheuvel@linaro.org
State Accepted
Commit 885d57ef091fd58916163e79ee694ddaf8fcc25e
Headers show

Commit Message

Ard Biesheuvel April 19, 2016, 2:55 p.m. UTC
Comparing a GCD attribute field directly against EFI_MEMORY_UC and
EFI_MEMORY_WT is incorrect, since it may have other bits set as well
which are not related to the cacheability of the region. So instead,
test explicitly against the flags EFI_MEMORY_WB and EFI_MEMORY_WT,
which must be set if the region may be mapped with cacheable attributes.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

-- 
2.5.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Leif Lindholm May 9, 2016, 4:24 p.m. UTC | #1
On Tue, Apr 19, 2016 at 04:55:32PM +0200, Ard Biesheuvel wrote:
> Comparing a GCD attribute field directly against EFI_MEMORY_UC and

> EFI_MEMORY_WT is incorrect, since it may have other bits set as well

> which are not related to the cacheability of the region. So instead,

> test explicitly against the flags EFI_MEMORY_WB and EFI_MEMORY_WT,

> which must be set if the region may be mapped with cacheable attributes.

> 

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Whoops.
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>


> ---

>  ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 4 +---

>  1 file changed, 1 insertion(+), 3 deletions(-)

> 

> diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c

> index 834afdba10ef..7f6598318a91 100644

> --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c

> +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c

> @@ -101,9 +101,7 @@ DmaMap (

>      }

>  

>      // If the mapped buffer is not an uncached buffer

> -    if ( (GcdDescriptor.Attributes != EFI_MEMORY_WC) &&

> -         (GcdDescriptor.Attributes != EFI_MEMORY_UC) )

> -    {

> +    if ((GcdDescriptor.Attributes & (EFI_MEMORY_WB | EFI_MEMORY_WT)) != 0) {

>        //

>        // If the buffer does not fill entire cache lines we must double buffer into

>        // uncached memory. Device (PCI) address becomes uncached page.

> -- 

> 2.5.0

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
index 834afdba10ef..7f6598318a91 100644
--- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
+++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
@@ -101,9 +101,7 @@  DmaMap (
     }
 
     // If the mapped buffer is not an uncached buffer
-    if ( (GcdDescriptor.Attributes != EFI_MEMORY_WC) &&
-         (GcdDescriptor.Attributes != EFI_MEMORY_UC) )
-    {
+    if ((GcdDescriptor.Attributes & (EFI_MEMORY_WB | EFI_MEMORY_WT)) != 0) {
       //
       // If the buffer does not fill entire cache lines we must double buffer into
       // uncached memory. Device (PCI) address becomes uncached page.