Skip to contentSkip to conversation

serial: 8250_dma: sync regions for device before transfer

PATCH In review Andy Shevchenko 2 participants 2 messages Jun 12, 2014 – Jun 13, 2014 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: 8250_dma: sync regions for device before transfer

The documentation says that we have to sync DMA regions after CPU access and before any DMA transfer is going on. The actual DMA for buffer happens when we call dmaengine_submit() (*). The original code syncs data after this call which might lead to the corrupted data in actual stream.

(*) Accordingly to the Documentation/dmaengine.txt the dmaengine_submit call shouldn't do the transfer, but some DMA controller drivers abuse this rule. Thus, we would like to have this patch until all DMA controller drivers will be fixed. Even after that it will be harmless.

---
 drivers/tty/serial/8250/8250_dma.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/tty/serial/8250/8250_dma.c +4 -6
index 148ffe4..f70ee29 100644
@@ -76,6 +76,8 @@ int serial8250_tx_dma(struct uart_8250_port *p)
 
 	dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
 
+	dma_sync_single_for_device(dma->txchan->device->dev, dma->tx_addr,
+				   UART_XMIT_SIZE, DMA_TO_DEVICE);
 	desc = dmaengine_prep_slave_single(dma->txchan,
 					   dma->tx_addr + xmit->tail,
 					   dma->tx_size, DMA_MEM_TO_DEV,
@@ -90,9 +92,6 @@ int serial8250_tx_dma(struct uart_8250_port *p)
 
 	dma->tx_cookie = dmaengine_submit(desc);
 
-	dma_sync_single_for_device(dma->txchan->device->dev, dma->tx_addr,
-				   UART_XMIT_SIZE, DMA_TO_DEVICE);
-
 	dma_async_issue_pending(dma->txchan);
 
 	return 0;
@@ -129,6 +128,8 @@ int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
 	if (dma_status)
 		return 0;
 
+	dma_sync_single_for_device(dma->rxchan->device->dev, dma->rx_addr,
+				   dma->rx_size, DMA_FROM_DEVICE);
 	desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
 					   dma->rx_size, DMA_DEV_TO_MEM,
 					   DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
@@ -140,9 +141,6 @@ int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
 
 	dma->rx_cookie = dmaengine_submit(desc);
 
-	dma_sync_single_for_device(dma->rxchan->device->dev, dma->rx_addr,
-				   dma->rx_size, DMA_FROM_DEVICE);
-
 	dma_async_issue_pending(dma->rxchan);
 
 	return 0;
Signature · 1 line
2.0.0
#1 lore raw

Hi Andy,

Quoted 9 lines · Andy Shevchenko

The documentation says that we have to sync DMA regions after CPU access and before any DMA transfer is going on. The actual DMA for buffer happens when we call dmaengine_submit() (*). The original code syncs data after this call which might lead to the corrupted data in actual stream.

(*) Accordingly to the Documentation/dmaengine.txt the dmaengine_submit call shouldn't do the transfer, but some DMA controller drivers abuse this rule. Thus, we would like to have this patch until all DMA controller drivers will be fixed. Even after that it will be harmless.

It's probable better that we directly fix the DMA engine drivers instead of working around the issue here.

Thanks,

Signature · 1 line
heikki