From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.12629.1589107408600691544 for ; Sun, 10 May 2020 03:43:28 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4ABE6101E; Sun, 10 May 2020 03:43:28 -0700 (PDT) Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D07F33F68F; Sun, 10 May 2020 03:43:26 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Pete Batard , Jared McNeill , Andrei Warkentin , Samer El-Haj-Mahmoud 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 Message-Id: <20200510104259.23739-5-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200510104259.23739-1-ard.biesheuvel@arm.com> References: <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 --- 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