]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmDmaLib: use DMA buffer alignment from CPU arch protocol
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sat, 12 Nov 2016 13:02:25 +0000 (14:02 +0100)
committerLeif Lindholm <leif.lindholm@linaro.org>
Wed, 30 Nov 2016 16:41:55 +0000 (16:41 +0000)
Instead of depending on ArmLib to retrieve the CWG directly, use
the DMA buffer alignment exposed by the CPU arch protocol. This
removes our dependency on ArmLib, which makes the library a bit
more architecture independent.

While we're in there, rename gCpu to mCpu to better reflect its
local scope, and reflow some lines that we're modifying anyway.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf

index 4476e8b461e39b1e7d051e3b89489c9c0fb25c9b..e836feff1ef85db9af53341780fc95a76699571e 100644 (file)
@@ -22,7 +22,6 @@
 #include <Library/UncachedMemoryAllocationLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UncachedMemoryAllocationLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
-#include <Library/ArmLib.h>\r
 \r
 #include <Protocol/Cpu.h>\r
 \r
 \r
 #include <Protocol/Cpu.h>\r
 \r
@@ -36,8 +35,7 @@ typedef struct {
 \r
 \r
 \r
 \r
 \r
 \r
-EFI_CPU_ARCH_PROTOCOL      *gCpu;\r
-UINTN                      gCacheAlignment = 0;\r
+STATIC EFI_CPU_ARCH_PROTOCOL      *mCpu;\r
 \r
 /**\r
   Provides the DMA controller-specific addresses needed to access system memory.\r
 \r
 /**\r
   Provides the DMA controller-specific addresses needed to access system memory.\r
@@ -90,8 +88,8 @@ DmaMap (
     return  EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
     return  EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||\r
-      ((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {\r
+  if ((((UINTN)HostAddress & (mCpu->DmaBufferAlignment - 1)) != 0) ||\r
+      ((*NumberOfBytes & (mCpu->DmaBufferAlignment - 1)) != 0)) {\r
 \r
     // Get the cacheability of the region\r
     Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);\r
 \r
     // Get the cacheability of the region\r
     Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);\r
@@ -153,7 +151,8 @@ DmaMap (
     DEBUG_CODE_END ();\r
 \r
     // Flush the Data Cache (should not have any effect if the memory region is uncached)\r
     DEBUG_CODE_END ();\r
 \r
     // Flush the Data Cache (should not have any effect if the memory region is uncached)\r
-    gCpu->FlushDataCache (gCpu, *DeviceAddress, *NumberOfBytes, EfiCpuFlushTypeWriteBackInvalidate);\r
+    mCpu->FlushDataCache (mCpu, *DeviceAddress, *NumberOfBytes,\r
+            EfiCpuFlushTypeWriteBackInvalidate);\r
   }\r
 \r
   Map->HostAddress   = (UINTN)HostAddress;\r
   }\r
 \r
   Map->HostAddress   = (UINTN)HostAddress;\r
@@ -217,7 +216,8 @@ DmaUnmap (
       //\r
       // Make sure we read buffer from uncached memory and not the cache\r
       //\r
       //\r
       // Make sure we read buffer from uncached memory and not the cache\r
       //\r
-      gCpu->FlushDataCache (gCpu, Map->HostAddress, Map->NumberOfBytes, EfiCpuFlushTypeInvalidate);\r
+      mCpu->FlushDataCache (mCpu, Map->HostAddress, Map->NumberOfBytes,\r
+              EfiCpuFlushTypeInvalidate);\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
@@ -317,11 +317,9 @@ ArmDmaLibConstructor (
   EFI_STATUS              Status;\r
 \r
   // Get the Cpu protocol for later use\r
   EFI_STATUS              Status;\r
 \r
   // Get the Cpu protocol for later use\r
-  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&gCpu);\r
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu);\r
   ASSERT_EFI_ERROR(Status);\r
 \r
   ASSERT_EFI_ERROR(Status);\r
 \r
-  gCacheAlignment = ArmCacheWritebackGranule ();\r
-\r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
index 95c13006eaac05f7e2cfbb2fbe4e8684d531eb47..31de3cfd828c69316e52ae66a83ca8a3ca4b5fe8 100644 (file)
@@ -37,8 +37,6 @@
   UncachedMemoryAllocationLib\r
   IoLib\r
   BaseMemoryLib\r
   UncachedMemoryAllocationLib\r
   IoLib\r
   BaseMemoryLib\r
-  ArmLib\r
-\r
 \r
 [Protocols]\r
   gEfiCpuArchProtocolGuid\r
 \r
 [Protocols]\r
   gEfiCpuArchProtocolGuid\r