All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_dma: sync regions for device before transfer
@ 2014-06-12 15:51 Andy Shevchenko
  2014-06-13 13:05 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2014-06-12 15:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Heikki Krogerus, linux-serial; +Cc: 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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/8250/8250_dma.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
index 148ffe4..f70ee29 100644
--- a/drivers/tty/serial/8250/8250_dma.c
+++ b/drivers/tty/serial/8250/8250_dma.c
@@ -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;
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] serial: 8250_dma: sync regions for device before transfer
  2014-06-12 15:51 [PATCH] serial: 8250_dma: sync regions for device before transfer Andy Shevchenko
@ 2014-06-13 13:05 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2014-06-13 13:05 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Greg Kroah-Hartman, linux-serial

Hi Andy,

On Thu, Jun 12, 2014 at 06:51:18PM +0300, Andy Shevchenko wrote:
> 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,

-- 
heikki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-13 13:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-12 15:51 [PATCH] serial: 8250_dma: sync regions for device before transfer Andy Shevchenko
2014-06-13 13:05 ` Heikki Krogerus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.