From: Radu Pirea <radu.pirea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
To: <linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
<broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
<nicolas.ferre-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>,
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Radu Pirea <radu.pirea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
Subject: [RFC PATCH 2/2] spi: atmel: Fix DMA transfers data corruption
Date: Wed, 15 Nov 2017 18:35:32 +0200 [thread overview]
Message-ID: <1510763732-10151-3-git-send-email-radu.pirea@microchip.com> (raw)
In-Reply-To: <1510763732-10151-1-git-send-email-radu.pirea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
If the cache model is VIVT, DMA data transfers may not be valid and to
ensure the validity of the data cache must be flushed and invalidated.
Signed-off-by: Radu Pirea <radu.pirea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
---
drivers/spi/spi-atmel.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 4e5e51f..cda6d0f 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -21,6 +21,8 @@
#include <linux/slab.h>
#include <linux/platform_data/dma-atmel.h>
#include <linux/of.h>
+#include <asm/cacheflush.h>
+#include <asm/cachetype.h>
#include <linux/io.h>
#include <linux/gpio.h>
@@ -742,6 +744,18 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
xfer->bits_per_word))
goto err_exit;
+#ifdef CONFIG_SOC_SAM_V4_V5
+ /*
+ * On Atmel SoCs based on ARM9 cores, the data cache follows the VIVT
+ * model, hence the cache aliases issue can occur when buffers are
+ * allocated from DMA-unsafe areas, by vmalloc() for instance, where
+ * cache coherency is not taken into account or at least not handled
+ * completely (cache lines of aliases are not flushed and invalidated).
+ * This is not a theorical issue: it was reproduced when trying to mount
+ * a UBI file-system on a at91sam9g35ek board.
+ */
+ flush_kernel_vmap_range((void *)xfer->rx_buf, xfer->len);
+#endif
/* Send both scatterlists */
rxdesc = dmaengine_prep_slave_sg(rxchan,
xfer->rx_sg.sgl, xfer->rx_sg.nents,
@@ -750,6 +764,9 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
if (!rxdesc)
goto err_dma;
+#ifdef CONFIG_SOC_SAM_V4_V5
+ flush_kernel_vmap_range((void *)xfer->tx_buf, xfer->len);
+#endif
txdesc = dmaengine_prep_slave_sg(txchan,
xfer->tx_sg.sgl, xfer->tx_sg.nents,
DMA_TO_DEVICE,
@@ -779,6 +796,9 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
rxchan->device->device_issue_pending(rxchan);
txchan->device->device_issue_pending(txchan);
+#ifdef CONFIG_SOC_SAM_V4_V5
+ invalidate_kernel_vmap_range((void *)xfer->rx_buf, xfer->len);
+#endif
/* take back lock */
atmel_spi_lock(as);
return 0;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-11-15 16:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 16:35 [RFC PATCH 0/2] Enable DMA transfers for SAM9 and fix cache aliasing Radu Pirea
[not found] ` <1510763732-10151-1-git-send-email-radu.pirea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
2017-11-15 16:35 ` [RFC PATCH 1/2] Revert "spi: atmel: fix corrupted data issue on SAM9 family SoCs" Radu Pirea
2017-11-16 10:36 ` Mark Brown
2017-11-15 16:35 ` Radu Pirea [this message]
[not found] ` <1510763732-10151-3-git-send-email-radu.pirea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
2017-11-15 19:01 ` [RFC PATCH 2/2] spi: atmel: Fix DMA transfers data corruption Trent Piepho
2017-11-16 10:26 ` Radu Nicolae Pirea
2017-11-16 10:45 ` Mark Brown
2017-12-08 13:26 ` Radu Nicolae Pirea
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=1510763732-10151-3-git-send-email-radu.pirea@microchip.com \
--to=radu.pirea-uwl1gki3jzl3ogb3hspcza@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=nicolas.ferre-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org \
/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).