Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4036443imm; Mon, 6 Aug 2018 15:32:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe5iQgl7u5CwtEDncAi3HMtKofa9STCVprGiMGlNRzvfw8Wb6+jxUvLVZF13VxizO6MIOuc X-Received: by 2002:a62:d544:: with SMTP id d65-v6mr18760685pfg.107.1533594769919; Mon, 06 Aug 2018 15:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533594769; cv=none; d=google.com; s=arc-20160816; b=haE4MgxqC0iZ3wZH+PKPj7Iu8h/gF+AW/7ImUHDRhZSo4QzU5wARcSxs+P/mjcq/0f CJTmkJgc38D/0EQ4+DyfrJpNgjDwFOJIByxdRCfqAFAIzwGSJLiW7jRmgQ1lXpvPYxm4 4w2ghItZ1Q95tYajryH455g9JnrCMUD3c4nznZAjAeXcDR89QhpbXff7OEbRvYHesM35 m6oHA3V8IZYaJAQG61T/Gj++0W4SGb7nYhTTsonvIQvUIaQ+lE4/ZqYcMfs0OdcsDpQm yxSOTAzbjG3DEz5kEpb4+kjdHEcaKIsbwkOVXlGEhXIFAlxns1uGfQcn8D7kEFJnIaEv EWWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ddxbjKWbH/qs2/dbAkPSUgMcTxkDVe7XOShiS2ShNhg=; b=FoYN1qWhYJFDVFYGoEMP1akuAkpnVuOKMJ3r+tGenhv6rcOxPtfF7iuGIH64F5643v hnzUqRm94F1e5bwWuqAfnKO9/N6d/i9Ugqsj7Z9L5F3xsaJD0chPtxYyKeDKrODhiGnj /uThr7Skii3bizr5LxwIUR/RBH8KEcjB4/x1PRIp5nReodhsepnh/tkL6Qb2q9UlRXVX 0J8W4pQeyjdEqXv/9TsMGdVAcl5HDk3hQvGwzRyz1heReIwR0dro2YkESUdc7wbU6Rmc ZujZ6YfzHTeYDcBQyjw20UiAzFRampQY8WYfTrpOf9H/WY/IKeRp13WLYtnDPBAR2Mj9 EUfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O4rnAwwU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1-v6si15304894pfm.7.2018.08.06.15.32.35; Mon, 06 Aug 2018 15:32:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O4rnAwwU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387851AbeHGAky (ORCPT + 99 others); Mon, 6 Aug 2018 20:40:54 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:45366 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387629AbeHGAkx (ORCPT ); Mon, 6 Aug 2018 20:40:53 -0400 Received: by mail-lf1-f68.google.com with SMTP id j143-v6so10187951lfj.12; Mon, 06 Aug 2018 15:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ddxbjKWbH/qs2/dbAkPSUgMcTxkDVe7XOShiS2ShNhg=; b=O4rnAwwU+E19y/dHgqfV5/LNr5ueAwgq1W7nBCLWP9ADhnJm3CbxcOA0zniiu5qIaB uMdeXG1Q0fL84RvXKIoJI12MkL7KR5sbIs/gEK2NUFnDr2nNHfKYnZharQuaiiuKFqC8 8RgIEEsCaErRxPzNN4yUOpduIm/yGT/ExpYhfRrzE/E9DEVPDnqyg7SxAAGs4+nYSoeY LVnc1S7SZeQOeDGnalM3AWlivmjquUd0keZr4mfAr6GXPsj+JMkcFaHaSIeveco+BJUJ MogHKF5Y2TLZGnBsmEwjw2scpufQ0GLAqf+kps9CmBrEz8DYUiN0iQEQDdZjIlILRTwa GNug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ddxbjKWbH/qs2/dbAkPSUgMcTxkDVe7XOShiS2ShNhg=; b=Rnly4VRhTPnPL5I12RaGRy/scuz89r7Ha1GeUm82VH0oTR0xHcTfpDimzHUjj/vKRK WOe8mxCihCpss5/SHqjia1y4M9uXzOJJXyGkfutVeJ0MbiF8h5u0shvEtfAqQBojZntL 3Onqst5VLAVuaXpmD4G5PBnuTGgcw+ixB0OjuWPlpLZsZV+1Z8zAO4JV61kfezlJ4EO+ UQRvmwX4TSKFpA0IVPPgtkZc0We21v42iO+WESuqC6XlzAIJ0NYODet0/vz8ADmROrVI H/W2FaRo79YtJcDQhQ1o/YsNb7ANphWZjWuZL6mGP5Icg9U5oedzMTSP5Bs9ACkD4jJ8 0aqw== X-Gm-Message-State: AOUpUlEPH09861mEXivW+jnBeJYf1cOuaBQgLVCIO0tETDzy8zEq/vLW 5ap+r4iyojKIh5PthoYxCU8= X-Received: by 2002:a19:14dc:: with SMTP id 89-v6mr11947557lfu.45.1533594580408; Mon, 06 Aug 2018 15:29:40 -0700 (PDT) Received: from z50.lan (93-181-165-181.internetia.net.pl. [93.181.165.181]) by smtp.gmail.com with ESMTPSA id o4-v6sm2438561ljc.67.2018.08.06.15.29.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 15:29:39 -0700 (PDT) From: Janusz Krzysztofik To: Boris Brezillon , Linus Walleij Cc: Jonathan Corbet , Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Tony Lindgren , Aaro Koskinen , linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-mtd@lists.infradead.org, linux-doc@vger.kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [RFC PATCH v2 09/12] gpiolib: Identify GPIO descriptor arrays with direct mapping Date: Tue, 7 Aug 2018 00:29:15 +0200 Message-Id: <20180806222918.12644-10-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180806222918.12644-1-jmkrzyszt@gmail.com> References: <20180718235710.18242-1-jmkrzyszt@gmail.com> <20180806222918.12644-1-jmkrzyszt@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, verify if the descriptors just collected represent consecutive pins of a single GPIO chip. Pass that information with the array to the caller so it can benefit from enhanced performance as soon as bitmap based get/set array functions which can make efficient use of that are available. Signed-off-by: Janusz Krzysztofik --- Documentation/driver-api/gpio/consumer.rst | 4 +++- drivers/gpio/gpiolib.c | 14 ++++++++++++++ include/linux/gpio/consumer.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/driver-api/gpio/consumer.rst b/Documentation/driver-api/gpio/consumer.rst index aa03f389d41d..38a990b5f3b6 100644 --- a/Documentation/driver-api/gpio/consumer.rst +++ b/Documentation/driver-api/gpio/consumer.rst @@ -109,11 +109,13 @@ 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 may also contain a valid descriptor of a single GPIO chip in +case the array strictly matches pin hardware layout of the chip:: struct gpio_descs { unsigned int ndescs; struct gpio_desc *desc[]; + struct gpio_chip *chip; } The following function returns NULL instead of -ENOENT if no GPIOs have been diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index bdbfc95793e7..c50bcec6e2d7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4161,6 +4161,7 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, { struct gpio_desc *desc; struct gpio_descs *descs; + struct gpio_chip *chip; int count; count = gpiod_count(dev, con_id); @@ -4177,6 +4178,19 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev, gpiod_put_array(descs); return ERR_CAST(desc); } + + /* + * Verify if the array qualifies for fast bitmap operations + * (single chip, pins in hardware order starting from 0) + * and mark the array with the chip descriptor if true. + */ + chip = gpiod_to_chip(desc); + if (descs->chip == NULL) + descs->chip = chip; + if (!IS_ERR(descs->chip) && (chip != descs->chip || + gpio_chip_hwgpio(desc) != descs->ndescs)) + descs->chip = ERR_PTR(-EINVAL); + descs->desc[descs->ndescs] = desc; descs->ndescs++; } diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 21ddbe440030..862ee027a02f 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -22,6 +22,7 @@ struct gpio_desc; * gpiod_get_array(). */ struct gpio_descs { + struct gpio_chip *chip; unsigned int ndescs; struct gpio_desc *desc[]; }; -- 2.16.4