From: "Ard Biesheuvel" <ard.biesheuvel@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>,
Pete Batard <pete@akeo.ie>, Jared McNeill <jmcneill@invisible.ca>,
Andrei Warkentin <awarkentin@vmware.com>,
Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Subject: [PATCH edk2-platforms v3 4/5] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA
Date: Mon, 11 May 2020 09:06:55 +0200 [thread overview]
Message-ID: <20200511070656.32141-5-ard.biesheuvel@arm.com> (raw)
In-Reply-To: <20200511070656.32141-1-ard.biesheuvel@arm.com>
The non-coherent version of DmaAllocateBuffer () returns uncached
memory, to ensure that the CPU and the device see the same data,
even we they are accessing the buffer at the same time.
This is not really necessary for our RX ring: the CPU never accesses
the buffer while it is mapped for writing by the device, and so we
can simply use the streaming DMA model, which uses ordinary cached
buffers, but issues a cache invalidate at DMA unmap time.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
---
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 ++++
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 18 +++++++++++++-----
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
index e74fa02ad209..3cabc5936562 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
@@ -49,3 +49,7 @@ [Protocols]
gBcmGenetPlatformDeviceProtocolGuid ## TO_START
gEfiDevicePathProtocolGuid ## BY_START
gEfiSimpleNetworkProtocolGuid ## BY_START
+
+[Pcd]
+ gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
+ gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
index 746fbfe51b1d..23bd1c1d2baa 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
@@ -19,6 +19,10 @@
#define GENET_PHY_RETRY 1000
+STATIC CONST
+EFI_PHYSICAL_ADDRESS mDmaAddressLimit = FixedPcdGet64 (PcdDmaDeviceLimit) -
+ FixedPcdGet64 (PcdDmaDeviceOffset);
+
/**
Read a memory-mapped device CSR.
@@ -605,16 +609,20 @@ GenetDmaAlloc (
IN GENET_PRIVATE_DATA *Genet
)
{
- EFI_STATUS Status;
- UINTN Idx;
+ EFI_PHYSICAL_ADDRESS Address;
+ EFI_STATUS Status;
+ UINTN Idx;
for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) {
- Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]);
+ Address = mDmaAddressLimit;
+ Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), &Address);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "GenetDmaAlloc: Failed to allocate RX buffer: %r\n", Status));
GenetDmaFree (Genet);
return Status;
}
+ Genet->RxBuffer[Idx] = (UINT8 *)(UINTN)Address;
}
return EFI_SUCCESS;
@@ -699,8 +707,8 @@ GenetDmaFree (
GenetDmaUnmapRxDescriptor (Genet, Idx);
if (Genet->RxBuffer[Idx] != NULL) {
- DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE),
- Genet->RxBuffer[Idx]);
+ gBS->FreePages ((UINTN)Genet->RxBuffer[Idx],
+ EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE));
Genet->RxBuffer[Idx] = NULL;
}
}
--
2.17.1
next prev parent reply other threads:[~2020-05-11 7:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-11 7:06 [PATCH edk2-platforms v3 0/5] BCM genet fixes Ard Biesheuvel
2020-05-11 7:06 ` [PATCH edk2-platforms v3 1/5] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel
2020-05-11 7:06 ` [PATCH edk2-platforms v3 2/5] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel
2020-05-11 7:06 ` [PATCH edk2-platforms v3 3/5] Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling Ard Biesheuvel
2020-05-11 7:06 ` Ard Biesheuvel [this message]
2020-05-11 7:06 ` [PATCH edk2-platforms v3 5/5] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() Ard Biesheuvel
2020-05-11 9:02 ` [PATCH edk2-platforms v3 0/5] BCM genet fixes Ard Biesheuvel
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=20200511070656.32141-5-ard.biesheuvel@arm.com \
--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