public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
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 v2 4/4] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA
Date: Sun, 10 May 2020 12:42:59 +0200	[thread overview]
Message-ID: <20200510104259.23739-5-ard.biesheuvel@arm.com> (raw)
In-Reply-To: <20200510104259.23739-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
+
+[FixedPcd]
+  gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
+  gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
index 2176bb451e7d..4d40a7afd199 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.
 
@@ -596,16 +600,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;
@@ -690,8 +698,8 @@ GenetDmaFree (
     GenetDmaUnmapRxDescriptor (Genet, Idx);
 
     if (Genet->RxBuffer[Idx] != NULL) {
-      DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE),
-        Genet->RxBuffer[Idx]);
+      gBS->FreePages (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE),
+        (UINTN)Genet->RxBuffer[Idx]);
       Genet->RxBuffer[Idx] = NULL;
     }
   }
-- 
2.17.1


  parent reply	other threads:[~2020-05-10 10:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-10 10:42 [PATCH edk2-platforms v2 0/4] BCM genet fixes Ard Biesheuvel
2020-05-10 10:42 ` [PATCH edk2-platforms v2 1/4] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel
2020-05-10 10:42 ` [PATCH edk2-platforms v2 2/4] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel
2020-05-10 10:42 ` [PATCH edk2-platforms v2 3/4] Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling Ard Biesheuvel
2020-05-10 10:42 ` Ard Biesheuvel [this message]
2020-05-10 21:36 ` [PATCH edk2-platforms v2 0/4] 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=20200510104259.23739-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