linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frode Isaksen <fisaksen@baylibre.com>
To: nsekhar@ti.com, khilman@baylibre.com, ptitiano@baylibre.com,
	linux-arm-kernel@lists.infradead.org
Cc: Frode Isaksen <fisaksen@baylibre.com>,
	broonie@kernel.org, linux-spi@vger.kernel.org
Subject: [PATCH 4/8] spi: davinci: flush caches when performing DMA
Date: Fri, 10 Feb 2017 16:29:40 +0100	[thread overview]
Message-ID: <1486740584-17875-5-git-send-email-fisaksen@baylibre.com> (raw)
In-Reply-To: <1486740584-17875-1-git-send-email-fisaksen@baylibre.com>

This CPU has VIVT caches, so need to flush the
cache for vmalloc'ed buffers, since the address
may be aliased (same phyiscal address used by
multiple virtual addresses).
This fixes errors when mounting and reading/writing
UBIFS volumes with SPI flash.

Signed-off-by: Frode Isaksen <fisaksen@baylibre.com>
---
 drivers/spi/spi-davinci.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index f1b46f6..c735425 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -29,6 +29,7 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_bitbang.h>
 #include <linux/slab.h>
+#include <asm/cacheflush.h>
 
 #include <linux/platform_data/spi-davinci.h>
 
@@ -676,7 +677,9 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 			}
 			sg_dma_address(&sg_rx) = t->rx_dma;
 			sg_dma_len(&sg_rx) = t->len;
-		}
+		} else if (is_vmalloc_addr(t->rx_buf))
+			/* VIVT cache, flush since aliased address */
+			flush_kernel_vmap_range((void *)t->rx_buf, t->len);
 
 		sg_init_table(&sg_tx, 1);
 		if (!t->tx_buf) {
@@ -688,7 +691,9 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 			}
 			sg_dma_address(&sg_tx) = t->tx_dma;
 			sg_dma_len(&sg_tx) = t->len;
-		}
+		} else if (is_vmalloc_addr(t->tx_buf))
+			/* VIVT cache, flush since aliased address */
+			flush_kernel_vmap_range((void *)t->tx_buf, t->len);
 
 		rxdesc = dmaengine_prep_slave_sg(dspi->dma_rx,
 				t->rx_sg.sgl ?: &sg_rx, t->rx_sg.nents ?: 1,
@@ -741,6 +746,10 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 		if (!t->rx_buf)
 			dma_unmap_single(&spi->dev, t->rx_dma,
 					t->len, DMA_FROM_DEVICE);
+		else if (is_vmalloc_addr(t->rx_buf))
+			/* VIVT cache, invalidate since aliased address */
+			invalidate_kernel_vmap_range((void *)t->rx_buf, t->len);
+
 		if (!t->tx_buf)
 			dma_unmap_single(&spi->dev, t->tx_dma,
 					t->len, DMA_TO_DEVICE);
-- 
2.7.4

  parent reply	other threads:[~2017-02-10 15:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 15:29 Enable DMA for daVinci SPI controller Frode Isaksen
2017-02-10 15:29 ` [PATCH 1/8] spi: davinci: Use SPI framework to handle DMA mapping Frode Isaksen
     [not found]   ` <1486740584-17875-2-git-send-email-fisaksen-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2017-02-13 11:30     ` Mark Brown
     [not found] ` <1486740584-17875-1-git-send-email-fisaksen-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2017-02-10 15:29   ` [PATCH 2/8] spi: davinci: enable DMA when channels are defined in DT Frode Isaksen
     [not found]     ` <1486740584-17875-3-git-send-email-fisaksen-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2017-02-13 11:32       ` Mark Brown
2017-02-10 15:29 ` [PATCH 3/8] spi: davinci: limit the transfer size if DMA enabled Frode Isaksen
     [not found]   ` <1486740584-17875-4-git-send-email-fisaksen-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2017-02-10 19:07     ` Kevin Hilman
2017-02-13  5:59     ` Sekhar Nori
2017-02-14 11:27       ` Frode Isaksen
2017-02-14 15:29         ` Sekhar Nori
     [not found]           ` <c0d6c236-1302-e910-8c41-cd82e0fac39b-l0cyMroinI0@public.gmane.org>
2017-02-14 16:40             ` Frode Isaksen
2017-03-21 22:02       ` Peter Ujfalusi
     [not found]         ` <b4d8bd90-cd33-560f-5102-20c2375dac70-l0cyMroinI0@public.gmane.org>
2017-03-22 11:11           ` Frode Isaksen
2017-03-22 11:35             ` Sekhar Nori
     [not found]               ` <95c7bc96-2de9-043d-880e-4de9f0b2308a-l0cyMroinI0@public.gmane.org>
2017-03-22 12:20                 ` Peter Ujfalusi
     [not found]                   ` <c85c9e88-c40b-88b3-f47d-6d5f5cc1fa00-l0cyMroinI0@public.gmane.org>
2017-03-22 13:30                     ` Frode Isaksen
2017-02-10 15:29 ` Frode Isaksen [this message]
2017-02-10 15:29 ` [PATCH 5/8] spi: davinci: do not use DMA if transfer length is less than 16 Frode Isaksen
2017-02-10 15:29 ` [PATCH 6/8] spi: loopback-test: set HW loopback mode if loopback set Frode Isaksen
2017-02-10 15:29 ` [PATCH 7/8] spi: loopback-test: add option to use vmalloc'ed buffers Frode Isaksen
2017-02-10 15:29 ` [PATCH 8/8] spi: loopback-test: limit length to spi_max_transfer_size() Frode Isaksen

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=1486740584-17875-5-git-send-email-fisaksen@baylibre.com \
    --to=fisaksen@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=khilman@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=nsekhar@ti.com \
    --cc=ptitiano@baylibre.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).