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.web12.13641.1589208950760765025 for ; Mon, 11 May 2020 07:55:50 -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 71119106F; Mon, 11 May 2020 07:55:50 -0700 (PDT) Received: from e123331-lin.nice.arm.com (unknown [10.37.8.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E64C63F68F; Mon, 11 May 2020 07:55:48 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Pete Batard , Jared McNeill , Andrei Warkentin , Samer El-Haj-Mahmoud , Jeremy Linton Subject: [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer Date: Mon, 11 May 2020 16:55:24 +0200 Message-Id: <20200511145527.23453-7-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511145527.23453-1-ard.biesheuvel@arm.com> References: <20200511145527.23453-1-ard.biesheuvel@arm.com> The DMA api requires that DMA mappings are kept in place during the time the device may access the memory. This may not matter for the way GENET is used on the RPi4, but it could break bounce buffering on platforms that impose DMA memory limits, since the bounce buffer may have been reused by the time the device gets to look at the data. So defer the DmaUnmap() of TX buffers to the point where they are recycled and returned to the caller. Signed-off-by: Ard Biesheuvel --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 5 +---- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index c43bdbe1d6da..16890f723cb2 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -213,6 +213,7 @@ typedef struct { GENERIC_PHY_PRIVATE_DATA Phy; UINT8 *TxBuffer[GENET_DMA_DESC_COUNT]; + VOID *TxBufferMap[GENET_DMA_DESC_COUNT]; UINT8 TxQueued; UINT16 TxNext; UINT16 TxConsIndex; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 94b578a10aa1..35a3c7abdf1e 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -760,6 +760,7 @@ GenetTxIntr ( Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; if (Genet->TxQueued > 0 && Total > 0) { + DmaUnmap (Genet->TxBufferMap[Genet->TxNext]); *TxBuf = Genet->TxBuffer[Genet->TxNext]; Genet->TxQueued--; Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c index 9746f210d1f2..b2cae687b3d4 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c @@ -559,7 +559,6 @@ GenetSimpleNetworkTransmit ( UINT8 Desc; PHYSICAL_ADDRESS DmaDeviceAddress; UINTN DmaNumberOfBytes; - VOID *DmaMapping; if (This == NULL || Buffer == NULL) { DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n", @@ -631,7 +630,7 @@ GenetSimpleNetworkTransmit ( (VOID *)(UINTN)Frame, &DmaNumberOfBytes, &DmaDeviceAddress, - &DmaMapping); + &Genet->TxBufferMap[Desc]); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: DmaMap failed: %r\n", __FUNCTION__, Status)); EfiReleaseLock (&Genet->Lock); @@ -643,8 +642,6 @@ GenetSimpleNetworkTransmit ( Genet->TxProdIndex = (Genet->TxProdIndex + 1) % 0xFFFF; Genet->TxQueued++; - DmaUnmap (DmaMapping); - EfiReleaseLock (&Genet->Lock); return EFI_SUCCESS; -- 2.17.1