From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org, leif.lindholm@linaro.org
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v2 1/4] ArmPkg/ArmDmaLib: use DMA buffer alignment from CPU arch protocol
Date: Sat, 12 Nov 2016 14:02:25 +0100 [thread overview]
Message-ID: <1478955748-14819-2-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1478955748-14819-1-git-send-email-ard.biesheuvel@linaro.org>
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>
---
ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 18 ++++++++----------
ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf | 2 --
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
index d48d6ff6dbbb..03fd9f3278e6 100644
--- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
+++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
@@ -22,7 +22,6 @@
#include <Library/UncachedMemoryAllocationLib.h>
#include <Library/IoLib.h>
#include <Library/BaseMemoryLib.h>
-#include <Library/ArmLib.h>
#include <Protocol/Cpu.h>
@@ -36,8 +35,7 @@ typedef struct {
-EFI_CPU_ARCH_PROTOCOL *gCpu;
-UINTN gCacheAlignment = 0;
+STATIC EFI_CPU_ARCH_PROTOCOL *mCpu;
/**
Provides the DMA controller-specific addresses needed to access system memory.
@@ -92,8 +90,8 @@ DmaMap (
*Mapping = Map;
- if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||
- ((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {
+ if ((((UINTN)HostAddress & (mCpu->DmaBufferAlignment - 1)) != 0) ||
+ ((*NumberOfBytes & (mCpu->DmaBufferAlignment - 1)) != 0)) {
// Get the cacheability of the region
Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);
@@ -154,7 +152,8 @@ DmaMap (
DEBUG_CODE_END ();
// 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;
@@ -211,7 +210,8 @@ DmaUnmap (
//
// 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);
}
}
@@ -311,11 +311,9 @@ ArmDmaLibConstructor (
EFI_STATUS Status;
// 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);
- gCacheAlignment = ArmCacheWritebackGranule ();
-
return Status;
}
diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
index 95c13006eaac..31de3cfd828c 100644
--- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
+++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
@@ -37,8 +37,6 @@ [LibraryClasses]
UncachedMemoryAllocationLib
IoLib
BaseMemoryLib
- ArmLib
-
[Protocols]
gEfiCpuArchProtocolGuid
--
2.7.4
next prev parent reply other threads:[~2016-11-12 13:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-12 13:02 [PATCH v2 0/4] ArmPkg: more ArmDmaLib fixes Ard Biesheuvel
2016-11-12 13:02 ` Ard Biesheuvel [this message]
2016-11-14 15:18 ` [PATCH v2 1/4] ArmPkg/ArmDmaLib: use DMA buffer alignment from CPU arch protocol Leif Lindholm
2016-11-12 13:02 ` [PATCH v2 2/4] ArmPkg/ArmDmaLib: fix incorrect device address of double buffer Ard Biesheuvel
2016-11-14 15:13 ` Leif Lindholm
2016-11-12 13:02 ` [PATCH v2 3/4] ArmPkg/ArmDmaLib: clean up abuse of device address Ard Biesheuvel
2016-11-14 15:16 ` Leif Lindholm
2016-11-15 9:19 ` Ard Biesheuvel
2016-11-15 11:34 ` Ryan Harkin
2016-11-15 13:07 ` Ard Biesheuvel
2016-11-15 18:01 ` Leif Lindholm
2016-11-30 16:45 ` Leif Lindholm
2016-11-12 13:02 ` [PATCH v2 4/4] ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset Ard Biesheuvel
2016-11-14 15:17 ` Leif Lindholm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478955748-14819-2-git-send-email-ard.biesheuvel@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox