From patchwork Mon Aug 6 22:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10558013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A2C141390 for ; Mon, 6 Aug 2018 22:32:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F55829871 for ; Mon, 6 Aug 2018 22:32:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8317729877; Mon, 6 Aug 2018 22:32:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D5AE29881 for ; Mon, 6 Aug 2018 22:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=oEbSvGKmB9pQ3YnApDcwcQDrb7c18yOwlG18Kra6nXY=; b=iiK0TkwsNHcKTVIb27XpmjDMrh sHcYQuh4iaL72sJUKYricTbBs0z4yjClDpOA1IhUYSawN7JVY9e5AkuX4+M8NFBqbcLxKasmmBNXj m78zCIwkFs2OxwIqpVbaptssoZfK/VdE7u6x3LbPWLWoE0q5DxV1HOMPwLMVp5Rf8/ifEoq6Pf0WD ti+hqQx+k2ZBwhiu83UCnfW0CQGJnCDmWOucofQI1UGcSZqWyVZLYoJUYepM5XRsMBOaSGbe496lA biG70ydgf6KWe/PSWlywFSqHOT59d52kPWb61HPL/LaO+EpO58tYE3ORw4cOzdnIQEevgG5QOHkWz hD1VqUzQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmo3F-0001tm-Rr; Mon, 06 Aug 2018 22:32:33 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fmo0a-0005Sc-Fp; Mon, 06 Aug 2018 22:30:01 +0000 Received: by mail-lf1-x141.google.com with SMTP id v22-v6so10200956lfe.8; 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=U465vM1lNenRCJOwynaiTOyySAmZ6bL/n8/1WheALMSCF4JUQygn61RnHPNJl+pAWp 614H4qG0b9zJpWBix4DS2I7lomWUGNNqAQ34HErplySfppJsVZpB+/NGUmgb66Vpu5q0 ttqg7Cs/zI4dOwX3uiD71Cs2N1qnwAZsja2U8bCuVflzBlSl0Th01jAbOl7pK4ehKW5O QOb5x7LAcMy6Fal/GYZ9veyRv7NpGmSV+uWxElkecDftnK48vyWz7htnILhSydcvI90C ilODzfYBtEhUd5ZtMfUsQc0vX/4Q3VlFduqxlXH0/ZEtkr1FDFcdyVEW9gZ/22moAuXZ 9V5Q== X-Gm-Message-State: AOUpUlGDAaBC1Jifri2h3/ijH+1xUggq04iysQtSuCWaDjclYsxsdIEx V5psAtSA52zKqhEF9BWXF9c= X-Google-Smtp-Source: AAOMgpe1kBSzm5J6s2TGZ6xuh9XrZ36DhEPwqaDLXIoZov77FCx7o+JryEyDTjswU9SaAdSCixn93A== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180806_152949_079748_02A3359D X-CRM114-Status: GOOD ( 16.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-omap@vger.kernel.org, Jonathan Corbet , Tony Lindgren , Richard Weinberger , linux-gpio@vger.kernel.org, Aaro Koskinen , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Marek Vasut , Janusz Krzysztofik , linux-mtd@lists.infradead.org, Miquel Raynal , Brian Norris , David Woodhouse , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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[]; };