From nobody Mon Feb 9 23:38:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+59054+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+59054+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1589180832; cv=none; d=zohomail.com; s=zohoarc; b=g84nUGVf+58q0OgK9fHVlt+r8hJoV3lXbdxb0uL3zoINbtyIX37M8F2bJX5C5vR7MSFPEUHECB8mssFCJ4gvhcCmiC7MoZKOoqUSjOj93wQJwuPIVGEooZnUONwNeqQXMtrxOGgg+j+h6h65tvDGrpkBKpF8jTV1Q16gGhr5UuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589180832; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=GBDruQExOb/BfvvaytIdNr2MGYXGNrt05SXuUgyRuJA=; b=koszoqscpJ7llJlQcJod8t8r4W6NY+NMZyudv+EdYwI8TF48GXvGXurXpDhbwbZ+TW+GyimzngsRq9BPJaju5GTwTU2qfpp4XMFAmqt/l1nloLIm0GW4Y4eXSp2ozOzQTmM76cE/ES4R4uWlZX/L4gctLI7B9pucvZ8/Bbjx/1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+59054+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1589180832714299.9453710369419; Mon, 11 May 2020 00:07:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jtgnYY1788612xG7hQwRrgGK; Mon, 11 May 2020 00:07:12 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.7680.1589180831668011398 for ; Mon, 11 May 2020 00:07:11 -0700 X-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 5A1EAD6E; Mon, 11 May 2020 00:07:11 -0700 (PDT) X-Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B7B763F68F; Mon, 11 May 2020 00:07:09 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Pete Batard , Jared McNeill , Andrei Warkentin , Samer El-Haj-Mahmoud Subject: [edk2-devel] [PATCH edk2-platforms v3 4/5] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA Date: Mon, 11 May 2020 09:06:55 +0200 Message-Id: <20200511070656.32141-5-ard.biesheuvel@arm.com> In-Reply-To: <20200511070656.32141-1-ard.biesheuvel@arm.com> References: <20200511070656.32141-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: hX167oRgQFAqt60vvwOliwMJx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589180832; bh=NYLP5EUcGT4p1JSac84byjuoekw/bdVmQpUB/JU06MQ=; h=Cc:Date:From:Reply-To:Subject:To; b=vR+EJpRlFZfhanz6gkmd2zxMXuaYuzfexYvts6ht6rxyqfGES5Ve2jv2yvgKINKKLLI BGKMX3hjs2PpShiv84ZUxjP0xBphXb856jruYoVYvWIty4qkoMKgSRXs5dwW5GX2ogCmj NGrn3YbwaTHejwXhXmMpSdgP+p9XDrsfAr4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/Sil= icon/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 @@ =20 #define GENET_PHY_RETRY 1000 =20 +STATIC CONST +EFI_PHYSICAL_ADDRESS mDmaAddressLimit =3D FixedPcdGet64 (PcdDmaDeviceLim= it) - + FixedPcdGet64 (PcdDmaDeviceOffse= t); + /** Read a memory-mapped device CSR. =20 @@ -605,16 +609,20 @@ GenetDmaAlloc ( IN GENET_PRIVATE_DATA *Genet ) { - EFI_STATUS Status; - UINTN Idx; + EFI_PHYSICAL_ADDRESS Address; + EFI_STATUS Status; + UINTN Idx; =20 for (Idx =3D 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { - Status =3D DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (= GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]); + Address =3D mDmaAddressLimit; + Status =3D 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] =3D (UINT8 *)(UINTN)Address; } =20 return EFI_SUCCESS; @@ -699,8 +707,8 @@ GenetDmaFree ( GenetDmaUnmapRxDescriptor (Genet, Idx); =20 if (Genet->RxBuffer[Idx] !=3D 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] =3D NULL; } } --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#59054): https://edk2.groups.io/g/devel/message/59054 Mute This Topic: https://groups.io/mt/74130978/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-