]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
ArmPkg/ArmDmaLib: use DMA buffer alignment from CPU arch protocol
[mirror_edk2.git] / ArmPkg / Library / ArmDmaLib / ArmDmaLib.c
index d48d6ff6dbbb82993d6232858e11739bc10a8fb9..e836feff1ef85db9af53341780fc95a76699571e 100644 (file)
@@ -22,7 +22,6 @@
 #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
@@ -36,8 +35,7 @@ typedef struct {
 \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
@@ -90,15 +88,13 @@ DmaMap (
     return  EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  *Mapping = Map;\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
     if (EFI_ERROR(Status)) {\r
-      return Status;\r
+      goto FreeMapInfo;\r
     }\r
 \r
     // If the mapped buffer is not an uncached buffer\r
@@ -112,7 +108,8 @@ DmaMap (
           "%a: Operation type 'MapOperationBusMasterCommonBuffer' is only supported\n"\r
           "on memory regions that were allocated using DmaAllocateBuffer ()\n",\r
           __FUNCTION__));\r
-        return EFI_UNSUPPORTED;\r
+        Status = EFI_UNSUPPORTED;\r
+        goto FreeMapInfo;\r
       }\r
 \r
       //\r
@@ -122,7 +119,7 @@ DmaMap (
       Map->DoubleBuffer  = TRUE;\r
       Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);\r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
+        goto FreeMapInfo;\r
       }\r
 \r
       if (Operation == MapOperationBusMasterRead) {\r
@@ -154,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
-    gCpu->FlushDataCache (gCpu, *DeviceAddress, *NumberOfBytes, EfiCpuFlushTypeWriteBackInvalidate);\r
+    mCpu->FlushDataCache (mCpu, *DeviceAddress, *NumberOfBytes,\r
+            EfiCpuFlushTypeWriteBackInvalidate);\r
   }\r
 \r
   Map->HostAddress   = (UINTN)HostAddress;\r
@@ -162,7 +160,14 @@ DmaMap (
   Map->NumberOfBytes = *NumberOfBytes;\r
   Map->Operation     = Operation;\r
 \r
+  *Mapping = Map;\r
+\r
   return EFI_SUCCESS;\r
+\r
+FreeMapInfo:\r
+  FreePool (Map);\r
+\r
+  return Status;\r
 }\r
 \r
 \r
@@ -211,7 +216,8 @@ DmaUnmap (
       //\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
@@ -311,11 +317,9 @@ ArmDmaLibConstructor (
   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
-  gCacheAlignment = ArmCacheWritebackGranule ();\r
-\r
   return Status;\r
 }\r
 \r