From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: linux-i2c@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
Wolfram Sang <wsa+renesas@sang-engineering.com>
Subject: [RFC PATCH 1/4] i2c: add helper to determine if DMA is favoured
Date: Tue, 6 Jun 2017 11:20:31 +0200 [thread overview]
Message-ID: <20170606092034.1516-2-wsa+renesas@sang-engineering.com> (raw)
In-Reply-To: <20170606092034.1516-1-wsa+renesas@sang-engineering.com>
We not only check if the buffer is DMA capable. We also require a
threshold value to see if it makes sense to setup DMA. Since most
I2C transactions are small, the cost for DMA might be too high.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
include/linux/i2c.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 72d0ece70ed30d..f0b835ba2ecd10 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -34,6 +34,8 @@
#include <linux/irqdomain.h> /* for Host Notify IRQ */
#include <linux/of.h> /* for struct device_node */
#include <linux/swab.h> /* for swab16 */
+#include <linux/mm.h>
+#include <linux/sched/task_stack.h>
#include <uapi/linux/i2c.h>
extern struct bus_type i2c_bus_type;
@@ -764,6 +766,33 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0);
}
+/**
+ * i2c_check_msg_for_dma() - check if a message is suitable for DMA
+ * @msg: the message to be checked
+ * @dma_threshold: the amount of byte from which using DMA makes sense
+ *
+ * Return: -ERANGE if message is smaller than threshold
+ * -EFAULT if message buffer is not DMA capable
+ * 0 if message is suitable for DMA
+ *
+ * Note: This function should only be called from process context! It uses
+ * helper functions which work on the 'current' task.
+ */
+static inline int i2c_check_msg_for_dma(struct i2c_msg *msg, unsigned int dma_threshold)
+{
+ if (msg->len < dma_threshold)
+ return -ERANGE;
+
+#if !defined(CONFIG_DMA_API_DEBUG)
+ if (!virt_addr_valid(msg->buf) || object_is_on_stack(msg->buf)) {
+ pr_debug("msg buffer to 0x%04x might not be DMA capable\n",
+ msg->addr);
+ return -EFAULT;
+ }
+#endif
+ return 0;
+}
+
int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
/**
* module_i2c_driver() - Helper macro for registering a modular I2C driver
--
2.11.0
next prev parent reply other threads:[~2017-06-06 9:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 9:20 [RFC PATCH 0/4] i2c: document DMA handling and add helper Wolfram Sang
2017-06-06 9:20 ` Wolfram Sang [this message]
2017-06-06 9:20 ` [RFC PATCH 2/4] i2c: add docs to clarify DMA handling Wolfram Sang
2017-06-06 10:03 ` Geert Uytterhoeven
2017-06-06 10:24 ` Wolfram Sang
2017-06-06 10:37 ` Geert Uytterhoeven
2017-06-06 10:54 ` Wolfram Sang
2017-06-06 11:12 ` Geert Uytterhoeven
2017-06-06 11:23 ` Wolfram Sang
2017-06-06 15:29 ` Geert Uytterhoeven
2017-06-06 9:20 ` [RFC PATCH 3/4] i2c: sh_mobile: use helper to decide if DMA is used Wolfram Sang
2017-06-06 9:20 ` [RFC PATCH 4/4] i2c: rcar: check for DMA-capable buffers Wolfram Sang
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=20170606092034.1516-2-wsa+renesas@sang-engineering.com \
--to=wsa+renesas@sang-engineering.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.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).