ArmPkg/ArmDmaLib: use DMA buffer alignment from CPU arch protocol

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>
This commit is contained in:
Ard Biesheuvel 2016-11-12 14:02:25 +01:00 committed by Leif Lindholm
parent 35718840ef
commit de2ec785e2
2 changed files with 8 additions and 12 deletions

View File

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

View File

@ -37,8 +37,6 @@
UncachedMemoryAllocationLib UncachedMemoryAllocationLib
IoLib IoLib
BaseMemoryLib BaseMemoryLib
ArmLib
[Protocols] [Protocols]
gEfiCpuArchProtocolGuid gEfiCpuArchProtocolGuid