All of lore.kernel.org
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@arm.linux.org.uk>
To: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
	linux-mmc@vger.kernel.org
Cc: Tony Lindgren <tony@atomide.com>
Subject: [PATCH 1/8] ARM: OMAP: fix DMA vs memory ordering
Date: Wed, 18 Apr 2012 11:10:35 +0100	[thread overview]
Message-ID: <E1SKRqN-0004b4-Me@rmk-PC.arm.linux.org.uk> (raw)
In-Reply-To: <20120418100954.GK25053@n2100.arm.linux.org.uk>

Using coherent DMA memory with the OMAP DMA engine results in
unpredictable behaviour due to memory ordering issues; as things stand,
there is no guarantee that data written to coherent DMA memory will be
visible to the DMA hardware.

This is because the OMAP dma_write() accessor contains no barriers,
necessary on ARMv6 and above.  The effect of this can be seen in comments
in the OMAP serial driver, which incorrectly talks about cache flushing
for the coherent DMA stuff.

Rather than adding barriers to the accessors, add it in the DMA support
code just before we enable DMA, and just after we disable DMA.  This
avoids having barriers for every DMA register access.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
 arch/arm/plat-omap/dma.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index ecdb3da..c58d896 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -916,6 +916,13 @@ void omap_start_dma(int lch)
 			l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
 	l |= OMAP_DMA_CCR_EN;
 
+	/*
+	 * As dma_write() uses IO accessors which are weakly ordered, there
+	 * is no guarantee that data in coherent DMA memory will be visible
+	 * to the DMA device.  Add a memory barrier here to ensure that any
+	 * such data is visible prior to enabling DMA.
+	 */
+	mb();
 	p->dma_write(l, CCR, lch);
 
 	dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
@@ -965,6 +972,13 @@ void omap_stop_dma(int lch)
 		p->dma_write(l, CCR, lch);
 	}
 
+	/*
+	 * Ensure that data transferred by DMA is visible to any access
+	 * after DMA has been disabled.  This is important for coherent
+	 * DMA regions.
+	 */
+	mb();
+
 	if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
 		int next_lch, cur_lch = lch;
 		char dma_chan_link_map[dma_lch_count];
-- 
1.7.4.4


WARNING: multiple messages have this Message-ID (diff)
From: rmk+kernel@arm.linux.org.uk (Russell King)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/8] ARM: OMAP: fix DMA vs memory ordering
Date: Wed, 18 Apr 2012 11:10:35 +0100	[thread overview]
Message-ID: <E1SKRqN-0004b4-Me@rmk-PC.arm.linux.org.uk> (raw)
In-Reply-To: <20120418100954.GK25053@n2100.arm.linux.org.uk>

Using coherent DMA memory with the OMAP DMA engine results in
unpredictable behaviour due to memory ordering issues; as things stand,
there is no guarantee that data written to coherent DMA memory will be
visible to the DMA hardware.

This is because the OMAP dma_write() accessor contains no barriers,
necessary on ARMv6 and above.  The effect of this can be seen in comments
in the OMAP serial driver, which incorrectly talks about cache flushing
for the coherent DMA stuff.

Rather than adding barriers to the accessors, add it in the DMA support
code just before we enable DMA, and just after we disable DMA.  This
avoids having barriers for every DMA register access.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
 arch/arm/plat-omap/dma.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index ecdb3da..c58d896 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -916,6 +916,13 @@ void omap_start_dma(int lch)
 			l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
 	l |= OMAP_DMA_CCR_EN;
 
+	/*
+	 * As dma_write() uses IO accessors which are weakly ordered, there
+	 * is no guarantee that data in coherent DMA memory will be visible
+	 * to the DMA device.  Add a memory barrier here to ensure that any
+	 * such data is visible prior to enabling DMA.
+	 */
+	mb();
 	p->dma_write(l, CCR, lch);
 
 	dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
@@ -965,6 +972,13 @@ void omap_stop_dma(int lch)
 		p->dma_write(l, CCR, lch);
 	}
 
+	/*
+	 * Ensure that data transferred by DMA is visible to any access
+	 * after DMA has been disabled.  This is important for coherent
+	 * DMA regions.
+	 */
+	mb();
+
 	if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
 		int next_lch, cur_lch = lch;
 		char dma_chan_link_map[dma_lch_count];
-- 
1.7.4.4

  reply	other threads:[~2012-04-18 10:10 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-18 10:09 [RFC 0/8] DMA engine conversion for omap_hsmmc Russell King - ARM Linux
2012-04-18 10:09 ` Russell King - ARM Linux
2012-04-18 10:10 ` Russell King [this message]
2012-04-18 10:10   ` [PATCH 1/8] ARM: OMAP: fix DMA vs memory ordering Russell King
2012-04-18 10:15   ` Felipe Balbi
2012-04-18 10:15     ` Felipe Balbi
2012-04-18 10:17     ` Russell King - ARM Linux
2012-04-18 10:17       ` Russell King - ARM Linux
2012-04-18 10:18       ` Felipe Balbi
2012-04-18 10:18         ` Felipe Balbi
2012-04-18 10:26         ` Russell King - ARM Linux
2012-04-18 10:26           ` Russell King - ARM Linux
2012-04-20 22:22   ` Tony Lindgren
2012-04-20 22:22     ` Tony Lindgren
2012-04-23 14:19     ` Russell King - ARM Linux
2012-04-23 14:19       ` Russell King - ARM Linux
2012-04-23 14:27       ` Tony Lindgren
2012-04-23 14:27         ` Tony Lindgren
2012-04-23 14:35         ` Shilimkar, Santosh
2012-04-23 14:35           ` Shilimkar, Santosh
2012-04-18 10:10 ` [PATCH 2/8] dmaengine: amba-pl08x: ensure physical channels are properly held Russell King
2012-04-18 10:10   ` Russell King
2012-04-18 10:19   ` Russell King - ARM Linux
2012-04-18 10:19     ` Russell King - ARM Linux
2012-04-27 20:38     ` Linus Walleij
2012-04-27 20:38       ` Linus Walleij
2012-04-27 21:41       ` Russell King - ARM Linux
2012-04-27 21:41         ` Russell King - ARM Linux
2012-04-18 10:11 ` [PATCH 3/8] dmaengine: split out virtual channel DMA support from sa11x0 driver Russell King
2012-04-18 10:11   ` Russell King
2012-04-24 10:35   ` Laxman Dewangan
2012-04-24 10:35     ` Laxman Dewangan
2012-04-24 10:50     ` Russell King - ARM Linux
2012-04-24 10:50       ` Russell King - ARM Linux
2012-04-24 10:57       ` Laxman Dewangan
2012-04-24 10:57         ` Laxman Dewangan
2012-04-18 10:11 ` [PATCH 4/8] dmaengine: add OMAP DMA engine driver Russell King
2012-04-18 10:11   ` Russell King
2012-04-18 10:11 ` [PATCH 5/8] mmc: omap_hsmmc: release correct resource Russell King
2012-04-18 10:11   ` Russell King
2012-04-20 22:23   ` Tony Lindgren
2012-04-20 22:23     ` Tony Lindgren
2012-04-20 22:59     ` Chris Ball
2012-04-20 22:59       ` Chris Ball
2012-04-21  2:35       ` Chris Ball
2012-04-21  2:35         ` Chris Ball
2012-04-21  9:48         ` Russell King - ARM Linux
2012-04-21  9:48           ` Russell King - ARM Linux
2012-04-22 15:20           ` Chris Ball
2012-04-22 15:20             ` Chris Ball
2012-04-18 10:12 ` [PATCH 6/8] mmc: omap_hsmmc: add DMA engine support Russell King
2012-04-18 10:12   ` Russell King
2012-04-18 18:11   ` Tony Lindgren
2012-04-18 18:11     ` Tony Lindgren
2012-04-18 19:09     ` Russell King - ARM Linux
2012-04-18 19:09       ` Russell King - ARM Linux
2012-04-18 19:53       ` Tony Lindgren
2012-04-18 19:53         ` Tony Lindgren
2012-04-18 10:12 ` [PATCH 7/8] mmc: omap_hsmmc: remove private DMA API implementation Russell King
2012-04-18 10:12   ` Russell King
2012-04-18 10:12 ` [PATCH 8/8] ARM: omap_hsmmc: remove platform data dma_mask and initialization Russell King
2012-04-18 10:12   ` Russell King
2012-04-18 15:23   ` T Krishnamoorthy, Balaji
2012-04-18 15:23     ` T Krishnamoorthy, Balaji
2012-04-18 15:29     ` Russell King - ARM Linux
2012-04-18 15:29       ` Russell King - ARM Linux
2012-04-18 15:35       ` T Krishnamoorthy, Balaji
2012-04-18 15:35         ` T Krishnamoorthy, Balaji
2012-04-18 18:19         ` Tony Lindgren
2012-04-18 18:19           ` Tony Lindgren
2012-04-18 19:10           ` Russell King - ARM Linux
2012-04-18 19:10             ` Russell King - ARM Linux
2012-04-18 19:55             ` Tony Lindgren
2012-04-18 19:55               ` Tony Lindgren
2012-04-18 19:42         ` Russell King - ARM Linux
2012-04-18 19:42           ` Russell King - ARM Linux
2012-04-18 20:02           ` Tony Lindgren
2012-04-18 20:02             ` Tony Lindgren
2012-04-18 20:24             ` Russell King - ARM Linux
2012-04-18 20:24               ` Russell King - ARM Linux
2012-04-18 21:01               ` Tony Lindgren
2012-04-18 21:01                 ` Tony Lindgren
2012-04-18 21:16                 ` Russell King - ARM Linux
2012-04-18 21:16                   ` Russell King - ARM Linux
2012-04-18 21:34                   ` Tony Lindgren
2012-04-18 21:34                     ` Tony Lindgren
2012-04-18 21:36                   ` Russell King - ARM Linux
2012-04-18 21:36                     ` Russell King - ARM Linux
2012-04-19  1:39                     ` Tony Lindgren
2012-04-19  1:39                       ` Tony Lindgren
2012-04-19 17:43                       ` Russell King - ARM Linux
2012-04-19 17:43                         ` Russell King - ARM Linux
2012-04-19 18:07                         ` Tony Lindgren
2012-04-19 18:07                           ` Tony Lindgren
2012-04-20 15:10                           ` Russell King - ARM Linux
2012-04-20 15:10                             ` Russell King - ARM Linux
2012-04-20 15:26                             ` Tony Lindgren
2012-04-20 15:26                               ` Tony Lindgren
2012-04-20 15:37                               ` Russell King - ARM Linux
2012-04-20 15:37                                 ` Russell King - ARM Linux
2012-04-20 16:43                                 ` Tony Lindgren
2012-04-20 16:43                                   ` Tony Lindgren
2012-04-20 22:09                                   ` Russell King - ARM Linux
2012-04-20 22:09                                     ` Russell King - ARM Linux
2012-04-20 22:21                                     ` Tony Lindgren
2012-04-20 22:21                                       ` Tony Lindgren
2012-04-20 16:50                                 ` Tony Lindgren
2012-04-20 16:50                                   ` Tony Lindgren
2012-04-23 14:14                                   ` Russell King - ARM Linux
2012-04-23 14:14                                     ` Russell King - ARM Linux
2012-04-23 14:30                                     ` Tony Lindgren
2012-04-23 14:30                                       ` Tony Lindgren
2012-04-23 14:34                                       ` Russell King - ARM Linux
2012-04-23 14:34                                         ` Russell King - ARM Linux
2012-04-23 11:46 ` [RFC 0/8] DMA engine conversion Russell King - ARM Linux
2012-04-23 11:46   ` Russell King - ARM Linux
2012-04-23 12:32   ` Shilimkar, Santosh
2012-04-23 12:32     ` Shilimkar, Santosh
2012-04-23 15:27     ` Shubhrajyoti
2012-04-23 15:27       ` Shubhrajyoti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1SKRqN-0004b4-Me@rmk-PC.arm.linux.org.uk \
    --to=rmk+kernel@arm.linux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.