From: Boris Brezillon <boris.brezillon@bootlin.com>
To: David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>,
Boris Brezillon <boris.brezillon@bootlin.com>,
Marek Vasut <marek.vasut@gmail.com>,
Richard Weinberger <richard@nod.at>,
Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
linux-mtd@lists.infradead.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
Mark Brown <broonie@kernel.org>,
linux-spi@vger.kernel.org
Cc: "Yogesh Gaur" <yogeshnarayan.gaur@nxp.com>,
"Vignesh R" <vigneshr@ti.com>,
"Kamal Dasu" <kdasu.kdev@gmail.com>,
"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
"Peter Pan" <peterpansjtu@gmail.com>,
"Frieder Schrempf" <frieder.schrempf@exceet.de>,
"Rafał Miłecki" <rafal@milecki.pl>,
"Sourav Poddar" <sourav.poddar@ti.com>
Subject: [PATCH v2 02/10] spi: Expose spi_{map,unmap}_buf() for internal use
Date: Wed, 11 Apr 2018 00:44:31 +0200 [thread overview]
Message-ID: <20180410224439.9260-3-boris.brezillon@bootlin.com> (raw)
In-Reply-To: <20180410224439.9260-1-boris.brezillon@bootlin.com>
spi_{map,unmap}_buf() are needed by the spi-mem logic that is about to
be introduced to prepare data buffer for DMA operations.
Remove the static specifier on these functions and add their prototypes
to include/linux/spi/spi.h. We do not export the symbols here because
both SPI_MEM and SPI can't be enabled as modules and we'd like to
prevent controller/device drivers from using these functions.
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
I see 2 other options to not expose internal stuff to spi users or
controller drivers:
1/ we do not expose spi_map/unmap_buf() and instead implement
spi_controller_dma_map/unmap_mem_op_data() directly in spi.c
2/ we create a new header (drivers/spi/internals.h?) for all
definitions that are meant for internal use (shared between spi.c
and spi-mem.c)
I personally prefer #2 as it provides a better separation between spi
and spi-mem code.
---
drivers/spi/spi.c | 23 +++++------------------
include/linux/spi/spi.h | 26 ++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 24369e437c6b..308e4c2114d8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -740,9 +740,9 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
}
#ifdef CONFIG_HAS_DMA
-static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
- struct sg_table *sgt, void *buf, size_t len,
- enum dma_data_direction dir)
+int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
+ struct sg_table *sgt, void *buf, size_t len,
+ enum dma_data_direction dir)
{
const bool vmalloced_buf = is_vmalloc_addr(buf);
unsigned int max_seg_size = dma_get_max_seg_size(dev);
@@ -821,8 +821,8 @@ static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
return 0;
}
-static void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev,
- struct sg_table *sgt, enum dma_data_direction dir)
+void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev,
+ struct sg_table *sgt, enum dma_data_direction dir)
{
if (sgt->orig_nents) {
dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir);
@@ -907,19 +907,6 @@ static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg)
return 0;
}
#else /* !CONFIG_HAS_DMA */
-static inline int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
- struct sg_table *sgt, void *buf, size_t len,
- enum dma_data_direction dir)
-{
- return -EINVAL;
-}
-
-static inline void spi_unmap_buf(struct spi_controller *ctlr,
- struct device *dev, struct sg_table *sgt,
- enum dma_data_direction dir)
-{
-}
-
static inline int __spi_map_msg(struct spi_controller *ctlr,
struct spi_message *msg)
{
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index bc6bb325d1bf..de6fd95a61c5 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -16,6 +16,7 @@
#define __LINUX_SPI_H
#include <linux/device.h>
+#include <linux/dma-direction.h>
#include <linux/mod_devicetable.h>
#include <linux/slab.h>
#include <linux/kthread.h>
@@ -614,6 +615,31 @@ static inline bool spi_controller_is_slave(struct spi_controller *ctlr)
extern int spi_controller_suspend(struct spi_controller *ctlr);
extern int spi_controller_resume(struct spi_controller *ctlr);
+/*
+ * Helpers needed by the spi-mem logic. Should not be used outside of
+ * spi-mem.c
+ */
+#ifdef CONFIG_HAS_DMA
+int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
+ struct sg_table *sgt, void *buf, size_t len,
+ enum dma_data_direction dir);
+void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev,
+ struct sg_table *sgt, enum dma_data_direction dir);
+#else /* !CONFIG_HAS_DMA */
+static inline int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
+ struct sg_table *sgt, void *buf, size_t len,
+ enum dma_data_direction dir)
+{
+ return -EINVAL;
+}
+
+static inline void spi_unmap_buf(struct spi_controller *ctlr,
+ struct device *dev, struct sg_table *sgt,
+ enum dma_data_direction dir)
+{
+}
+#endif /* CONFIG_HAS_DMA */
+
/* Calls the driver make to interact with the message queue */
extern struct spi_message *spi_get_next_queued_message(struct spi_controller *ctlr);
extern void spi_finalize_current_message(struct spi_controller *ctlr);
--
2.14.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2018-04-10 22:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-10 22:44 [PATCH v2 00/10] spi: Extend the framework to generically support memory devices Boris Brezillon
2018-04-10 22:44 ` [PATCH v2 01/10] spi: Check presence the of ->transfer[_xxx]() before registering a controller Boris Brezillon
2018-04-16 12:13 ` Applied "spi: Check presence the of ->transfer[_xxx]() before registering a controller" to the spi tree Mark Brown
2018-04-26 12:14 ` Boris Brezillon
2018-04-26 12:37 ` Mark Brown
2018-04-26 12:54 ` Mark Brown
2018-04-10 22:44 ` Boris Brezillon [this message]
2018-04-16 12:11 ` [PATCH v2 02/10] spi: Expose spi_{map,unmap}_buf() for internal use Mark Brown
2018-04-18 14:20 ` Boris Brezillon
2018-04-10 22:44 ` [PATCH v2 03/10] spi: Add an helper to flush the message queue Boris Brezillon
2018-04-10 22:44 ` [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers Boris Brezillon
2018-04-12 14:38 ` Vignesh R
2018-04-12 15:10 ` Boris Brezillon
2018-04-12 19:59 ` Boris Brezillon
2018-04-17 4:12 ` Vignesh R
2018-04-18 14:17 ` Boris Brezillon
2018-04-16 10:33 ` Frieder Schrempf
2018-04-18 14:23 ` Boris Brezillon
2018-04-10 22:44 ` [PATCH v2 05/10] spi: Make support for regular transfers optional when ->mem_ops != NULL Boris Brezillon
2018-04-10 22:44 ` [PATCH v2 06/10] spi: bcm-qspi: Implement the spi_mem interface Boris Brezillon
2018-05-11 2:56 ` Applied "spi: bcm-qspi: Implement the spi_mem interface" to the spi tree Mark Brown
2018-04-10 22:44 ` [PATCH v2 07/10] spi: bcm53xx: Implement the spi_mem interface Boris Brezillon
2018-04-12 13:09 ` Boris Brezillon
2018-05-07 9:35 ` Rafał Miłecki
2018-04-10 22:44 ` [PATCH v2 08/10] spi: ti-qspi: " Boris Brezillon
2018-04-10 22:44 ` [PATCH v2 09/10] mtd: spi-nor: Use the spi_mem_xx() API Boris Brezillon
2018-05-11 2:55 ` Applied "mtd: spi-nor: Use the spi_mem_xx() API" to the spi tree Mark Brown
2018-04-10 22:44 ` [PATCH v2 10/10] spi: Get rid of the spi_flash_read() API Boris Brezillon
2018-04-17 10:57 ` [PATCH v2 00/10] spi: Extend the framework to generically support memory devices Mark Brown
2018-04-18 14:25 ` Boris Brezillon
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=20180410224439.9260-3-boris.brezillon@bootlin.com \
--to=boris.brezillon@bootlin.com \
--cc=broonie@kernel.org \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=frieder.schrempf@exceet.de \
--cc=kdasu.kdev@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=marek.vasut@gmail.com \
--cc=maxime.chevallier@bootlin.com \
--cc=miquel.raynal@bootlin.com \
--cc=peterpansjtu@gmail.com \
--cc=rafal@milecki.pl \
--cc=richard@nod.at \
--cc=sourav.poddar@ti.com \
--cc=vigneshr@ti.com \
--cc=yogeshnarayan.gaur@nxp.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).