linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <jmkrzyszt@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>,
	Peter Korsgaard <peter.korsgaard@barco.com>,
	Peter Rosin <peda@axentia.se>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Jiri Slaby <jslaby@suse.com>, Willy Tarreau <w@1wt.eu>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org,
	linux-mmc@vger.kernel.org, netdev@vger.kernel.org,
	linux-iio@vger.kernel.org, devel@driverdev.osuosl.org,
	linux-serial@vger.kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Janusz Krzysztofik <jmkrzyszt@gmail.com>
Subject: [PATCH v5 2/4] gpiolib: Identify arrays matching GPIO hardware
Date: Wed, 29 Aug 2018 22:48:58 +0200	[thread overview]
Message-ID: <20180829204900.19390-3-jmkrzyszt@gmail.com> (raw)
In-Reply-To: <20180829204900.19390-1-jmkrzyszt@gmail.com>

Certain GPIO array lookup results may map directly to GPIO pins of a
single GPIO chip in hardware order.  If that condition is recognized
and handled efficiently, significant performance gain of get/set array
functions may be possible.

While processing a request for an array of GPIO descriptors, identify
those which represent corresponding pins of a single GPIO chip.  Skip
over pins which require open source or open drain special processing.
Moreover, identify pins which require inversion.  Pass a pointer to
that information with the array to the caller so it can benefit from
enhanced performance as soon as get/set array functions can accept and
make efficient use of it.

Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
---
 Documentation/driver-api/gpio/consumer.rst |  4 +-
 drivers/gpio/gpiolib.c                     | 72 +++++++++++++++++++++++++++++-
 drivers/gpio/gpiolib.h                     |  9 ++++
 include/linux/gpio/consumer.h              |  9 ++++
 4 files changed, 92 insertions(+), 2 deletions(-)

diff --git a/Documentation/driver-api/gpio/consumer.rst b/Documentation/driver-api/gpio/consumer.rst
index ed68042ddccf..7e0298b9a7b9 100644
--- a/Documentation/driver-api/gpio/consumer.rst
+++ b/Documentation/driver-api/gpio/consumer.rst
@@ -109,9 +109,11 @@ For a function using multiple GPIOs all of those can be obtained with one call::
 					   enum gpiod_flags flags)
 
 This function returns a struct gpio_descs which contains an array of
-descriptors::
+descriptors.  It also contains a pointer to a gpiolib private structure which,
+if passed back to get/set array functions, may speed up I/O proocessing::
 
 	struct gpio_descs {
+		struct gpio_array *info;
 		unsigned int ndescs;
 		struct gpio_desc *desc[];
 	}
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f0e9ffa8cab6..c1ed1c759345 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4174,7 +4174,9 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
 {
 	struct gpio_desc *desc;
 	struct gpio_descs *descs;
-	int count;
+	struct gpio_array *array_info = NULL;
+	struct gpio_chip *chip;
+	int count, bitmap_size;
 
 	count = gpiod_count(dev, con_id);
 	if (count < 0)
@@ -4190,9 +4192,77 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
 			gpiod_put_array(descs);
 			return ERR_CAST(desc);
 		}
+
 		descs->desc[descs->ndescs] = desc;
+
+		chip = gpiod_to_chip(desc);
+		/*
+		 * Select a chip of first array member
+		 * whose index matches its pin hardware number
+		 * as a candidate for fast bitmap processing.
+		 */
+		if (!array_info && gpio_chip_hwgpio(desc) == descs->ndescs) {
+			struct gpio_descs *array;
+
+			bitmap_size = BITS_TO_LONGS(chip->ngpio > count ?
+						    chip->ngpio : count);
+
+			array = kzalloc(struct_size(descs, desc, count) +
+					struct_size(array_info, invert_mask,
+					3 * bitmap_size), GFP_KERNEL);
+			if (!array) {
+				gpiod_put_array(descs);
+				return ERR_PTR(-ENOMEM);
+			}
+
+			memcpy(array, descs,
+			       struct_size(descs, desc, descs->ndescs + 1));
+			kfree(descs);
+
+			descs = array;
+			array_info = (void *)(descs->desc + count);
+			array_info->get_mask = array_info->invert_mask +
+						  bitmap_size;
+			array_info->set_mask = array_info->get_mask +
+						  bitmap_size;
+
+			array_info->desc = descs->desc;
+			array_info->size = count;
+			array_info->chip = chip;
+			bitmap_set(array_info->get_mask, descs->ndescs,
+				   count - descs->ndescs);
+			bitmap_set(array_info->set_mask, descs->ndescs,
+				   count - descs->ndescs);
+			descs->info = array_info;
+		}
+		/*
+		 * Unmark members which don't qualify for fast bitmap
+		 * processing (different chip, not in hardware order)
+		 */
+		if (array_info && (chip != array_info->chip ||
+		    gpio_chip_hwgpio(desc) != descs->ndescs)) {
+			__clear_bit(descs->ndescs, array_info->get_mask);
+			__clear_bit(descs->ndescs, array_info->set_mask);
+		} else if (array_info) {
+			/* Exclude open drain or open source from fast output */
+			if (gpiochip_line_is_open_drain(chip, descs->ndescs) ||
+			    gpiochip_line_is_open_source(chip, descs->ndescs))
+				__clear_bit(descs->ndescs,
+					    array_info->set_mask);
+			/* Identify 'fast' pins which require invertion */
+			if (gpiod_is_active_low(desc))
+				__set_bit(descs->ndescs,
+					  array_info->invert_mask);
+		}
+
 		descs->ndescs++;
 	}
+	if (array_info)
+		dev_dbg(dev,
+			"GPIO array info: chip=%s, size=%d, get_mask=%lx, set_mask=%lx, invert_mask=%lx\n",
+			array_info->chip->label, array_info->size,
+			*array_info->get_mask, *array_info->set_mask,
+			*array_info->invert_mask);
 	return descs;
 }
 EXPORT_SYMBOL_GPL(gpiod_get_array);
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 11e83d2eef89..b60905d558b1 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -183,6 +183,15 @@ static inline bool acpi_can_fallback_to_crs(struct acpi_device *adev,
 }
 #endif
 
+struct gpio_array {
+	struct gpio_desc	**desc;
+	unsigned int		size;
+	struct gpio_chip	*chip;
+	unsigned long		*get_mask;
+	unsigned long		*set_mask;
+	unsigned long		invert_mask[];
+};
+
 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);
 int gpiod_get_array_value_complex(bool raw, bool can_sleep,
 				  unsigned int array_size,
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 1b21dc7b0fad..8dede3e886af 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -17,11 +17,20 @@ struct device;
  */
 struct gpio_desc;
 
+/**
+ * Opaque descriptor for a structure of GPIO array attributes.  This structure
+ * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be
+ * passed back to get/set array functions in order to activate fast processing
+ * path if applicable.
+ */
+struct gpio_array;
+
 /**
  * Struct containing an array of descriptors that can be obtained using
  * gpiod_get_array().
  */
 struct gpio_descs {
+	struct gpio_array *info;
 	unsigned int ndescs;
 	struct gpio_desc *desc[];
 };
-- 
2.16.4


  parent reply	other threads:[~2018-08-29 20:50 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180813223448.21316-1-jmkrzyszt@gmail.com>
2018-08-20 23:43 ` [RFC RFT PATCH 0/4] gpiolib: speed up GPIO array processing Janusz Krzysztofik
2018-08-20 23:43   ` [RFC RFT PATCH v4 1/4] gpiolib: Pass bitmaps, not integer arrays, to get/set array Janusz Krzysztofik
2018-08-21  6:49     ` Peter Rosin
2018-08-21  6:52       ` Peter Rosin
2018-08-29 12:03     ` Miguel Ojeda
2018-08-29 18:01       ` Janusz Krzysztofik
2018-08-20 23:43   ` [RFC RFT PATCH v4 2/4] gpiolib: Identify arrays matching GPIO hardware Janusz Krzysztofik
2018-08-20 23:43   ` [RFC RFT PATCH v4 3/4] gpiolib: Pass array info to get/set array functions Janusz Krzysztofik
2018-08-20 23:43   ` [RFC RFT PATCH v4 4/4] gpiolib: Implement fast processing path in get/set array Janusz Krzysztofik
2018-08-29  9:06   ` [RFC RFT PATCH 0/4] gpiolib: speed up GPIO array processing Linus Walleij
2018-08-29 18:16     ` Janusz Krzysztofik
2018-08-29 10:19   ` Ulf Hansson
2018-08-29 20:48   ` [PATH v5 " Janusz Krzysztofik
2018-08-29 20:48     ` [PATCH v5 1/4] gpiolib: Pass bitmaps, not integer arrays, to get/set array Janusz Krzysztofik
2018-08-30  4:30       ` Peter Rosin
2018-08-30  7:40       ` Geert Uytterhoeven
2018-08-30 11:10       ` Miguel Ojeda
2018-08-30 15:35         ` David Laight
2018-09-02 10:19         ` Janusz Krzysztofik
2018-08-31  9:14       ` Linus Walleij
2018-08-29 20:48     ` Janusz Krzysztofik [this message]
2018-08-29 20:48     ` [PATCH v5 3/4] gpiolib: Pass array info to get/set array functions Janusz Krzysztofik
2018-08-29 20:49     ` [PATCH v5 4/4] gpiolib: Implement fast processing path in get/set array Janusz Krzysztofik
2018-08-31 22:56     ` [PATH v6 0/4] gpiolib: speed up GPIO array processing Janusz Krzysztofik
2018-08-31 22:56       ` [PATCH v6 1/4] gpiolib: Pass bitmaps, not integer arrays, to get/set array Janusz Krzysztofik
2018-09-01  0:23         ` Peter Rosin
2018-09-04 15:28         ` kbuild test robot
2018-09-04 15:28         ` kbuild test robot
2018-08-31 22:56       ` [PATCH v6 2/4] gpiolib: Identify arrays matching GPIO hardware Janusz Krzysztofik
2018-08-31 22:56       ` [PATCH v6 3/4] gpiolib: Pass array info to get/set array functions Janusz Krzysztofik
2018-09-04 15:27         ` kbuild test robot
2018-08-31 22:56       ` [PATCH v6 4/4] gpiolib: Implement fast processing path in get/set array Janusz Krzysztofik
2018-09-02 12:01       ` [PATCH v7 0/4] gpiolib: speed up GPIO array processing Janusz Krzysztofik
2018-09-02 12:01         ` [PATCH v7 1/4] gpiolib: Pass bitmaps, not integer arrays, to get/set array Janusz Krzysztofik
2018-09-02 13:21           ` Lukas Wunner
2018-09-03  4:31           ` Matthew Wilcox
2018-09-03 14:24             ` Geert Uytterhoeven
2018-09-03 15:07           ` Geert Uytterhoeven
2018-09-04 15:29           ` kbuild test robot
2018-09-05  6:46           ` kbuild test robot
2018-09-02 12:01         ` [PATCH v7 2/4] gpiolib: Identify arrays matching GPIO hardware Janusz Krzysztofik
2018-09-02 12:01         ` [PATCH v7 3/4] gpiolib: Pass array info to get/set array functions Janusz Krzysztofik
2018-09-03 14:21           ` Geert Uytterhoeven
2018-09-04 15:23           ` kbuild test robot
2018-09-05  7:11           ` kbuild test robot
2018-09-02 12:01         ` [PATCH v7 4/4] gpiolib: Implement fast processing path in get/set array Janusz Krzysztofik
     [not found]           ` <CGME20180920101151eucas1p221f5a1715b8556bb9d99bf08fe09ce6f@eucas1p2.samsung.com>
2018-09-20 10:11             ` Marek Szyprowski
2018-09-20 15:48               ` Janusz Krzysztofik
2018-09-20 16:21                 ` Janusz Krzysztofik
2018-09-21  8:18                   ` Marek Szyprowski
2018-09-21 10:51                     ` Janusz Krzysztofik
2018-09-21 11:26                       ` Janusz Krzysztofik
2018-09-21 14:14                       ` Marek Szyprowski
2018-09-23 10:43                         ` Janusz Krzysztofik
2018-09-23 23:53                           ` [PATCH 0/2] gpiolib: Fix issues introduced by fast bitmap processing path Janusz Krzysztofik
2018-09-23 23:53                             ` [PATCH 1/2] gpiolib: Fix missing updates of bitmap index Janusz Krzysztofik
2018-09-24  8:11                               ` Linus Walleij
2018-09-23 23:53                             ` [PATCH 2/2] gpiolib: Fix array members of same chip processed separately Janusz Krzysztofik
2018-09-24  8:13                               ` Linus Walleij
2018-09-24  9:43                             ` [PATCH 0/2] gpiolib: Fix issues introduced by fast bitmap processing path Marek Szyprowski
2018-09-24 11:08                               ` Janusz Krzysztofik
2018-09-24 11:38                                 ` Marek Szyprowski
2018-09-24 14:18                                   ` Janusz Krzysztofik
2018-09-20 18:05                 ` [PATCH v7 4/4] gpiolib: Implement fast processing path in get/set array Dan Carpenter
2018-09-20 15:49               ` Linus Walleij
2018-09-05 21:50         ` [PATCH v8 0/4] gpiolib: speed up GPIO array processing Janusz Krzysztofik
2018-09-05 21:50           ` [PATCH v8 1/4] gpiolib: Pass bitmaps, not integer arrays, to get/set array Janusz Krzysztofik
2018-09-05 21:50           ` [PATCH v8 2/4] gpiolib: Identify arrays matching GPIO hardware Janusz Krzysztofik
2018-09-05 21:50           ` [PATCH v8 3/4] gpiolib: Pass array info to get/set array functions Janusz Krzysztofik
2018-09-05 21:50           ` [PATCH v8 4/4] gpiolib: Implement fast processing path in get/set array Janusz Krzysztofik
2018-09-13  9:22           ` [PATCH v8 0/4] gpiolib: speed up GPIO array processing Linus Walleij
2018-09-19 18:08             ` Linus Walleij

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=20180829204900.19390-3-jmkrzyszt@gmail.com \
    --to=jmkrzyszt@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andrew@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devel@driverdev.osuosl.org \
    --cc=f.fainelli@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=jslaby@suse.com \
    --cc=kishon@ti.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=peda@axentia.se \
    --cc=peter.korsgaard@barco.com \
    --cc=pmeerw@pmeerw.net \
    --cc=ulf.hansson@linaro.org \
    --cc=w@1wt.eu \
    /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).