summaryrefslogtreecommitdiffstats
path: root/ArmPkg
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2016-04-20 10:29:21 +0200
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2016-05-10 14:44:40 +0200
commitb64e44cc098ffd03ccbf1a635ae405ae98971419 (patch)
tree05e6cdcf1e1df702725e6b6fd3476d7c59c7cbec /ArmPkg
parent32e5fb76e5692911d5176ac4dc9cedafbe7fa5c9 (diff)
downloadedk2-b64e44cc098ffd03ccbf1a635ae405ae98971419.tar.gz
edk2-b64e44cc098ffd03ccbf1a635ae405ae98971419.tar.bz2
edk2-b64e44cc098ffd03ccbf1a635ae405ae98971419.zip
ArmPkg/ArmDmaLib: assert that consistent mappings are uncached
DmaMap () only allows uncached mappings to be used for creating consistent mappings with operation type MapOperationBusMasterCommonBuffer. However, if the buffer passed to DmaMap () happens to be aligned to the CWG, there is no need for a bounce buffer, and we perform the cache maintenance directly without ever checking if the memory attributes of the buffer adhere to the API. So add some debug code that asserts that the operation type and the memory attributes are consistent. 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>
Diffstat (limited to 'ArmPkg')
-rw-r--r--ArmPkg/Library/ArmDmaLib/ArmDmaLib.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
index f5788b3756..d48d6ff6db 100644
--- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
+++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
@@ -136,6 +136,23 @@ DmaMap (
} else {
Map->DoubleBuffer = FALSE;
+ DEBUG_CODE_BEGIN ();
+
+ //
+ // The operation type check above only executes if the buffer happens to be
+ // misaligned with respect to CWG, but even if it is aligned, we should not
+ // allow arbitrary buffers to be used for creating consistent mappings.
+ // So duplicate the check here when running in DEBUG mode, just to assert
+ // that we are not trying to create a consistent mapping for cached memory.
+ //
+ Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);
+ ASSERT_EFI_ERROR(Status);
+
+ ASSERT (Operation != MapOperationBusMasterCommonBuffer ||
+ (GcdDescriptor.Attributes & (EFI_MEMORY_WB | EFI_MEMORY_WT)) == 0);
+
+ DEBUG_CODE_END ();
+
// Flush the Data Cache (should not have any effect if the memory region is uncached)
gCpu->FlushDataCache (gCpu, *DeviceAddress, *NumberOfBytes, EfiCpuFlushTypeWriteBackInvalidate);
}