<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Consolas, Courier, monospace; font-size: 12pt; color: rgb(0, 0, 0);">
Yeah if this code ever runs on a system with some kind of SMMU, definitely want the fix. (could we mention SMMU as a reason for why mappings must be valid during hw access?)</div>
<div style="font-family: Consolas, Courier, monospace; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="margin: 0px; font-size: 12pt; font-family: Consolas, Courier, monospace">
<br>
</div>
<div style="margin: 0px; font-size: 12pt; font-family: Consolas, Courier, monospace">
Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com></div>
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Ard Biesheuvel <ard.biesheuvel@arm.com><br>
<b>Sent:</b> Monday, May 11, 2020 9:55 AM<br>
<b>To:</b> devel@edk2.groups.io <devel@edk2.groups.io><br>
<b>Cc:</b> 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>; Jeremy Linton <jeremy.linton@arm.com><br>
<b>Subject:</b> [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">The DMA api requires that DMA mappings are kept in place during the<br>
time the device may access the memory. This may not matter for the<br>
way GENET is used on the RPi4, but it could break bounce buffering on<br>
platforms that impose DMA memory limits, since the bounce buffer may<br>
have been reused by the time the device gets to look at the data.<br>
<br>
So defer the DmaUnmap() of TX buffers to the point where they are<br>
recycled and returned to the caller.<br>
<br>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com><br>
---<br>
 Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h     | 1 +<br>
 Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c     | 1 +<br>
 Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 5 +----<br>
 3 files changed, 3 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h<br>
index c43bdbe1d6da..16890f723cb2 100644<br>
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h<br>
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h<br>
@@ -213,6 +213,7 @@ typedef struct {<br>
   GENERIC_PHY_PRIVATE_DATA            Phy;<br>
 <br>
   UINT8                               *TxBuffer[GENET_DMA_DESC_COUNT];<br>
+  VOID                                *TxBufferMap[GENET_DMA_DESC_COUNT];<br>
   UINT8                               TxQueued;<br>
   UINT16                              TxNext;<br>
   UINT16                              TxConsIndex;<br>
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c<br>
index 94b578a10aa1..35a3c7abdf1e 100644<br>
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c<br>
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c<br>
@@ -760,6 +760,7 @@ GenetTxIntr (<br>
 <br>
   Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF;<br>
   if (Genet->TxQueued > 0 && Total > 0) {<br>
+    DmaUnmap (Genet->TxBufferMap[Genet->TxNext]);<br>
     *TxBuf = Genet->TxBuffer[Genet->TxNext];<br>
     Genet->TxQueued--;<br>
     Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT;<br>
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c<br>
index 9746f210d1f2..b2cae687b3d4 100644<br>
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c<br>
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c<br>
@@ -559,7 +559,6 @@ GenetSimpleNetworkTransmit (<br>
   UINT8               Desc;<br>
   PHYSICAL_ADDRESS    DmaDeviceAddress;<br>
   UINTN               DmaNumberOfBytes;<br>
-  VOID                *DmaMapping;<br>
 <br>
   if (This == NULL || Buffer == NULL) {<br>
     DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n",<br>
@@ -631,7 +630,7 @@ GenetSimpleNetworkTransmit (<br>
                    (VOID *)(UINTN)Frame,<br>
                    &DmaNumberOfBytes,<br>
                    &DmaDeviceAddress,<br>
-                   &DmaMapping);<br>
+                   &Genet->TxBufferMap[Desc]);<br>
   if (EFI_ERROR (Status)) {<br>
     DEBUG ((DEBUG_ERROR, "%a: DmaMap failed: %r\n", __FUNCTION__, Status));<br>
     EfiReleaseLock (&Genet->Lock);<br>
@@ -643,8 +642,6 @@ GenetSimpleNetworkTransmit (<br>
   Genet->TxProdIndex = (Genet->TxProdIndex + 1) % 0xFFFF;<br>
   Genet->TxQueued++;<br>
 <br>
-  DmaUnmap (DmaMapping);<br>
-<br>
   EfiReleaseLock (&Genet->Lock);<br>
 <br>
   return EFI_SUCCESS;<br>
-- <br>
2.17.1<br>
<br>
</div>
</span></font></div>
</body>
</html>

<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>
Groups.io Links:<p>


You receive all messages sent to this group.



<p>

<a target="_blank" href="https://edk2.groups.io/g/devel/message/59133">View/Reply Online (#59133)</a> |


  


|


  
    <a target="_blank" href="https://groups.io/mt/74137454/1813853">Mute This Topic</a>
  

| <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>



<br>

<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>