From 756a514aa469c35e1a21c034a513630b7f02ecff Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Mon, 31 Oct 2016 15:43:49 +0000 Subject: [PATCH] ArmPkg/CpuDxe: set DmaBufferAlignment according to CWG The DmaBufferAlignment currently defaults to 4, which is dangerously small and may result in lost data on platforms that perform non-coherent DMA. So instead, take the CWG value from the cache info registers. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- ArmPkg/Drivers/CpuDxe/CpuDxe.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c b/ArmPkg/Drivers/CpuDxe/CpuDxe.c index d089cb2d11..7d328d096b 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c @@ -225,9 +225,18 @@ EFI_CPU_ARCH_PROTOCOL mCpu = { CpuGetTimerValue, CpuSetMemoryAttributes, 0, // NumberOfTimers - 4, // DmaBufferAlignment + 2048, // DmaBufferAlignment }; +STATIC +VOID +InitializeDma ( + IN OUT EFI_CPU_ARCH_PROTOCOL *CpuArchProtocol + ) +{ + CpuArchProtocol->DmaBufferAlignment = ArmCacheWritebackGranule (); +} + EFI_STATUS CpuDxeInitialize ( IN EFI_HANDLE ImageHandle, @@ -239,6 +248,8 @@ CpuDxeInitialize ( InitializeExceptions (&mCpu); + InitializeDma (&mCpu); + Status = gBS->InstallMultipleProtocolInterfaces ( &mCpuHandle, &gEfiCpuArchProtocolGuid, &mCpu, -- 2.39.2