From patchwork Tue Sep 26 05:20:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 144808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1811254vqu; Tue, 26 Sep 2023 03:33:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEc9WgVX2nktU+O0CkCO0BBraq+aCCOvtn3+B/8VxwCDKRNr4FSIQ0VVkGyCoMv0XnUVBEl X-Received: by 2002:a17:90a:6048:b0:263:f521:da3e with SMTP id h8-20020a17090a604800b00263f521da3emr3147563pjm.2.1695724402213; Tue, 26 Sep 2023 03:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695724402; cv=none; d=google.com; s=arc-20160816; b=VFvODZzpF6kl7H1dLtf+h2K1cwWYd1x2Ij9xYS2qYF6pb0CfnBwCXYIsWEdwFftneV FP1gC8NsJWbhFCnVEXjPUODwEiMpPLrMadnaDE2yyvDlw17gT6mwHPFnOxZP71lqP4Hi e6zZd2eyscv2FjzjE22R2jKqceRsptNeUSbIQkPfJRHRKuuWQcDrIKJkZ52GLRMNGXYa UC/oo4Sa31FZf3bsZon+4SUo2JQrIZvo1eO7//FGitrvoaoOPcR+DlQK5aL65ETglt4E ohTQcLZP//A3HsxecdMj34xkskZMOg/84HJbULlSTspqUwsEEps/znZO58+IkIf0eDSa /WUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=M60sRqt4xNv5ErJ+j1DQt+h8t34Lsw9KsA1hVQluwtU=; fh=vW1oNT0lvWbI8AMX2u/BZGKXD0nTZmrv2xM94BgUfog=; b=XTtQJVb7Mqm2C8ZSXHwHNEFABMsPMBfK9EuCk/2i1yh6rM5ehrxkNCM0K/XQ2Wk6Wt xs7651Ly/5W75DjuuQVOPXnEVculRbLJ3rG7eJIo0zYyBMHMQuZhVG23dTYnH+CUJmtB PwM9mYbbVb3YDmgwxwJS6PhSKQPCunIZ1L6Zap4paFLmirpo2z+cQsRmX8GsHpHcMDJV NQEhjphnzywTZjIF+/4YSF2JqEkDuufdqAYZzzRd5d+PKv0WXzeBz1V6txnSco1bP9iw STMn8U27VoV9PaJ1zLn82zG+FDDHBIduEjJP1QcPbx1LOdMrXy+6zKwtCdiGilH3qM1L jyLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="BCDAY/L/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i12-20020a17090acf8c00b00262e5a82047si547692pju.44.2023.09.26.03.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 03:33:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="BCDAY/L/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 229D0806117C; Mon, 25 Sep 2023 22:20:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232692AbjIZFUk (ORCPT + 26 others); Tue, 26 Sep 2023 01:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231549AbjIZFUb (ORCPT ); Tue, 26 Sep 2023 01:20:31 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16D4C10E; Mon, 25 Sep 2023 22:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695705625; x=1727241625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HobNRGqJUHXjsUELG2MflqrUmiEdsI1lLhoWfVAN/p8=; b=BCDAY/L/WYVWBl8pngiAdFcz/U1dMmcpzRk+hXQib+spNZq2mjhAFVmK VtP+Hy5vUYcBFV88c4byiVj8uA1F7XvwYtFXeICrcecnxM+JovEJNUrUs mW2qFfLZ5SStTyycXL6TqvEC4Nqgu1xLXWGHtdTU5Dq+dLDqS6qTJymUf vQmMnURUUVRxdzP3spGlVxilEIRt3Obd48z4egEgd81h72qgDGDeMbg4O SYBrWKuRj/LYLwMRa5BEIf5sWlosmW0Kl8DEZ2nbw7eDXorZy0+Wfvo29 N8mjY6cdprFeCAdAQpE52B83WPeISDZA+APCNb/YyK0PwYrLGww65HKwv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="360865684" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="360865684" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 22:20:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="748689667" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="748689667" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 25 Sep 2023 22:20:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id DE9E387; Tue, 26 Sep 2023 08:20:18 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Yury Norov , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Bartosz Golaszewski , Andy Shevchenko , Rasmus Villemoes , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v1 1/5] lib/test_bitmap: Excape space symbols when printing input string Date: Tue, 26 Sep 2023 08:20:03 +0300 Message-Id: <20230926052007.3917389-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> References: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 22:20:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778095910740649074 X-GMAIL-MSGID: 1778095910740649074 test_bitmap_printlist() prints the input string which contains a new line character. Instead of stripping it, escape that kind of characters, so developer will see the actual input string that has been used. Without this change the new line splits the string to two, and the first one is not guaranteed to be followed by the first part immediatelly. Signed-off-by: Andy Shevchenko --- lib/test_bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index f2ea9f30c7c5..1f2dc7fef17f 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -523,7 +523,7 @@ static void __init test_bitmap_printlist(void) goto out; } - pr_err("bitmap_print_to_pagebuf: input is '%s', Time: %llu\n", buf, time); + pr_err("bitmap_print_to_pagebuf: input is '%*pEs', Time: %llu\n", ret, buf, time); out: kfree(buf); kfree(bmap); From patchwork Tue Sep 26 05:20:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 144742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1714416vqu; Mon, 25 Sep 2023 23:45:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG06YscaurM7hxy3zCeINlcWYXjBVmzvV9fqtUjem9WaRSkmjzhY1rClYBZXIvHdfd43yPO X-Received: by 2002:a62:ee06:0:b0:68f:a92a:8509 with SMTP id e6-20020a62ee06000000b0068fa92a8509mr2263467pfi.7.1695710723747; Mon, 25 Sep 2023 23:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695710723; cv=none; d=google.com; s=arc-20160816; b=W6LM42CfgQ0JXXusO1aDZAPmg5Thsr825bg8JCAOJD3PZNH9nhIvbp0XMS3+8f5Ibc 93J79t2om8O1YHGf3L2d2S/AJRNKMvTgZxS+0/OTgEwCv0qVznlc2iodAbMA2uRXZ0c8 XBl4Dnt31jIo6dnTpnZjYfcbJeWjQU8vQibSaXKYWBIvJUYazs0uiMqDUpyQORXZnBw/ lBaIL26dPxRK0keo72+tPGhCdx5gQLyHGFAXbaZmQFwSPuSJdkd5dPq4hB7rU/wJjpH6 2aYlrLmYNurKoVmRb8Vj2+AkMi7qYnDUiiKRRydHgikFmv7bc2FkHyz6XM1zO082+hYf VOOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oD8M0nyHmQs82NGD9bg9sV1iaUbN/HZCHTX8l6FrvlM=; fh=vW1oNT0lvWbI8AMX2u/BZGKXD0nTZmrv2xM94BgUfog=; b=if5+9WdU7LYB0scLdyfbdbQxUPK9XhGpl+oMLDANTsB0u1iDJdaZKgxDOxJFjZkmGh IRneoLtPndcj4Dq2Rf08IGTq0GZoWzRlofUt+NNQftR5oVtGK7+PHDQEh1HrUb2SNOZ3 Yo1pP+S7Q4ElDnXolHpvF8i12GJuCVpXKbzebRA3YxweSZ1HYQWRn0RpLFROVQcGsVWG t+46EVynFYg7HqsFspPBbx/ebhwR+mQtL4LEHTx95M94norL69EsnR3h5E/wRYgaaESU 5/jSw7sJsM3PGQjZQPdxNDkvuxGv0Uk9RvAqJaXfnaDqYJFtP4X89/XaLF+DGvwvKeAL TvLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HYrP7gRN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id ch3-20020a056a00288300b00690d55d630dsi11874875pfb.274.2023.09.25.23.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:45:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HYrP7gRN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id EDA95825173F; Mon, 25 Sep 2023 22:20:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233132AbjIZFUx (ORCPT + 26 others); Tue, 26 Sep 2023 01:20:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjIZFUc (ORCPT ); Tue, 26 Sep 2023 01:20:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EFB9D7; Mon, 25 Sep 2023 22:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695705625; x=1727241625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JNhOP0h4Wmvb7AtoOm+qvjG9Eh0xhQGc8R2E+oO+zNM=; b=HYrP7gRNwuPuH2loLskcgJ1okqzq4Dp1u93tOPg0J6hexFP6+Ga9MK2r T8eXZuPGT4nnbXqyJRKs6cMWi5+kHkWGBTKIT+1s8xy0j7aZzfdB5i3So WG0KKdMGyWO0KYnKZv/VW027QVl5ABrOGAl1D3s/FvdrC8DvMwpry3Eff WmxUjMdN9xuM7IIJkf5w46c4axnDw2n9yd0bTNmA+Aa+RQ11Z5xigdCNA QqyHMp1z0pKoCZJ8R2+R3gWo4K5ekOXd0Ud36vKnf9zjzQ6E/SKxdjE3i BtnDKFPT+PffaGIY3PzHqWvz4l9gZ/j6/c04QQWgCBI8YdDVRsaTTvOEQ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="371820573" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="371820573" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 22:20:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="783824216" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="783824216" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 25 Sep 2023 22:20:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E7E8117D; Tue, 26 Sep 2023 08:20:18 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Yury Norov , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Bartosz Golaszewski , Andy Shevchenko , Rasmus Villemoes , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v1 2/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers Date: Tue, 26 Sep 2023 08:20:04 +0300 Message-Id: <20230926052007.3917389-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> References: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 22:20:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778081568092945673 X-GMAIL-MSGID: 1778081568092945673 These helpers are the optimized versions of the bitmap_remap() where one of the bitmaps (source or destination) is of sequential bits. See more in the kernel documentation of the helpers. Signed-off-by: Andy Shevchenko --- include/linux/bitmap.h | 9 ++++++ lib/bitmap.c | 70 ++++++++++++++++++++++++++++++++++++++++++ lib/test_bitmap.c | 23 ++++++++++++++ 3 files changed, 102 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 1516ff979315..87013b9a7dd8 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -60,6 +60,8 @@ struct device; * bitmap_shift_left(dst, src, n, nbits) *dst = *src << n * bitmap_cut(dst, src, first, n, nbits) Cut n bits from first, copy rest * bitmap_replace(dst, old, new, mask, nbits) *dst = (*old & ~(*mask)) | (*new & *mask) + * bitmap_scatter(dst, src, mask, nbits) *dst = map(dense, sparse)(src) + * bitmap_gather(dst, src, mask, nbits) *dst = map(sparse, dense)(src) * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap @@ -208,6 +210,12 @@ int bitmap_parselist(const char *buf, unsigned long *maskp, int nmaskbits); int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen, unsigned long *dst, int nbits); + +unsigned int bitmap_scatter(unsigned long *dst, const unsigned long *src, + const unsigned long *mask, unsigned int nbits); +unsigned int bitmap_gather(unsigned long *dst, const unsigned long *src, + const unsigned long *mask, unsigned int nbits); + void bitmap_remap(unsigned long *dst, const unsigned long *src, const unsigned long *old, const unsigned long *new, unsigned int nbits); int bitmap_bitremap(int oldbit, @@ -216,6 +224,7 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig, const unsigned long *relmap, unsigned int bits); void bitmap_fold(unsigned long *dst, const unsigned long *orig, unsigned int sz, unsigned int nbits); + int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order); void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order); int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); diff --git a/lib/bitmap.c b/lib/bitmap.c index 935e0f96e785..31cfc7846aae 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -942,6 +942,76 @@ int bitmap_parse(const char *start, unsigned int buflen, } EXPORT_SYMBOL(bitmap_parse); +/** + * bitmap_scatter - Scatter a bitmap according to the given mask + * @dst: scattered bitmap + * @src: gathered bitmap + * @mask: bits to assign to in the scattered bitmap + * @nbits: number of bits in each of these bitmaps + * + * Scatters bitmap with sequential bits according to the given @mask. + * + * Example: + * If @src bitmap = 0x005a, with @mask = 0x1313, @dst will be 0x0302. + * + * Or in binary form + * @src @mask @dst + * 0000000001011010 0001001100010011 0000001100000010 + * + * (Bits 0, 1, 2, 3, 4, 5 are copied to the bits 0, 1, 4, 8, 9, 12) + * + * Returns: the weight of the @mask. + */ +unsigned int bitmap_scatter(unsigned long *dst, const unsigned long *src, + const unsigned long *mask, unsigned int nbits) +{ + unsigned int bit; + int n = 0; + + bitmap_zero(dst, nbits); + + for_each_set_bit(bit, mask, nbits) + __assign_bit(bit, dst, test_bit(n++, src)); + + return n; +} +EXPORT_SYMBOL(bitmap_scatter); + +/** + * bitmap_gather - Gather a bitmap according to given mask + * @dst: gathered bitmap + * @src: scattered bitmap + * @mask: bits to extract from in the scattered bitmap + * @nbits: number of bits in each of these bitmaps + * + * Gathers bitmap with sparse bits according to the given @mask. + * + * Example: + * If @src bitmap = 0x0302, with @mask = 0x1313, @dst will be 0x001a. + * + * Or in binary form + * @src @mask @dst + * 0000001100000010 0001001100010011 0000000000011010 + * + * (Bits 0, 1, 4, 8, 9, 12 are copied to the bits 0, 1, 2, 3, 4, 5) + * + * Returns: the weight of the @mask. + */ +unsigned int bitmap_gather(unsigned long *dst, const unsigned long *src, + const unsigned long *mask, unsigned int nbits) +{ + unsigned int bit; + int n = 0; + + bitmap_zero(dst, nbits); + + for_each_set_bit(bit, mask, nbits) + __assign_bit(n++, dst, test_bit(bit, src)); + + return n; +} +EXPORT_SYMBOL(bitmap_gather); + /** * bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap * @buf: pointer to a bitmap diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 1f2dc7fef17f..f43a07679998 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -50,6 +50,9 @@ static const unsigned long exp2[] __initconst = { static const unsigned long exp2_to_exp3_mask[] __initconst = { BITMAP_FROM_U64(0x008000020020212eULL), }; +static const unsigned long exp2_to_exp3_maskg[] __initconst = { + BITMAP_FROM_U64(0x00000000000001ffULL), +}; /* exp3_0_1 = (exp2[0] & ~exp2_to_exp3_mask) | (exp2[1] & exp2_to_exp3_mask) */ static const unsigned long exp3_0_1[] __initconst = { BITMAP_FROM_U64(0x33b3333311313137ULL), @@ -357,6 +360,25 @@ static void __init test_replace(void) expect_eq_bitmap(bmap, exp3_1_0, nbits); } +static void __init test_bitmap_sg(void) +{ + unsigned int nbits = 64; + DECLARE_BITMAP(bmap, 1024); + unsigned int w; + + bitmap_zero(bmap, 1024); + w = bitmap_gather(bmap, exp2_to_exp3_mask, exp2_to_exp3_mask, nbits); + expect_eq_uint(bitmap_weight(exp2_to_exp3_mask, nbits), w); + expect_eq_uint(bitmap_weight(bmap, 1024), w); + expect_eq_bitmap(bmap, exp2_to_exp3_maskg, nbits); + + bitmap_zero(bmap, 1024); + w = bitmap_scatter(bmap, exp2_to_exp3_maskg, exp2_to_exp3_mask, nbits); + expect_eq_uint(bitmap_weight(exp2_to_exp3_maskg, nbits), w); + expect_eq_uint(bitmap_weight(bmap, 1024), w); + expect_eq_bitmap(bmap, exp2_to_exp3_mask, nbits); +} + #define PARSE_TIME 0x1 #define NO_LEN 0x2 @@ -1228,6 +1250,7 @@ static void __init selftest(void) test_fill_set(); test_copy(); test_replace(); + test_bitmap_sg(); test_bitmap_arr32(); test_bitmap_arr64(); test_bitmap_parse(); From patchwork Tue Sep 26 05:20:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 144792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1783708vqu; Tue, 26 Sep 2023 02:32:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8QNR2btbaTA1hmSIJRLs57GWHeodvvldHqJjKnob9PiU261cGv20yDLab9RsoEtf0+ybN X-Received: by 2002:a17:90a:e518:b0:276:ae0f:57c0 with SMTP id t24-20020a17090ae51800b00276ae0f57c0mr6914274pjy.19.1695720734586; Tue, 26 Sep 2023 02:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695720734; cv=none; d=google.com; s=arc-20160816; b=yFo9DiEM/KpbKSTsZXEj2PeAjfeI5NzHDWclpfdyz2ecdptP4cqPF2cV3XCYtn4E9R uuCVMMfUVx8Cxoa+T5qry8KQhtItUKfwcZYyGMNfwbAdG3HpftxawpgrvgUFiJYVwPzq L8j1RKnpnOJHUakuRJYh1W+zcD7fRILmF32cuG+OabUFgrod3Bd9bSHQm54vcOTWU8YN Ir+3PlvNELYrvJ4Bq5F4RkXqtEu5M2n+mpbXGxl+S0APnwquWwbd2dHvFCu5R5f66XcQ 63JLVXpobNb1rU3uJF2pNcLjP1FG1ocNMJTAoWzYCdQijetZ7smpjdB628/VzZjEGp7I Gepg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RWH+87FsoZ6xcpwCvWZtbGJ1xS3siXgq3RoFMNrZfo8=; fh=vW1oNT0lvWbI8AMX2u/BZGKXD0nTZmrv2xM94BgUfog=; b=nSc4nhQJD1gOn/fHKdy6b2yJIQ3NPi16+k+uw0iECCjq0spOZJ9MGlDPWJlszKHHb6 fpdZ1KChkFPyLuXdo3z3ugTZ6lie24k2EBSecQS23KAWL3euaf70uHERSZJMoFYJ0fB/ oHCbEDRAFsAo3zhjq/w1MDJVQvNvgIGqHTmqSUdoaWxcQaIlywqKGSt29ULQHTABPX2L cQ2CjiECTmjmH9GRHUgXQp0jC9daxYq94ZWHHItB8nzCplBHBwDmwEYy1rtZR+kfC+sJ jDU/qgPLcTEeRFiCFUHhM1M1KBuOZThLtOmc0YtzjiAgyhU2Nvi4EL6zMUVmNR19E11R Bc+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jBwODYqC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x1-20020a17090a970100b0027450695a78si7321695pjo.172.2023.09.26.02.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 02:32:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jBwODYqC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D8FFD81F9677; Mon, 25 Sep 2023 22:21:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233678AbjIZFUs (ORCPT + 26 others); Tue, 26 Sep 2023 01:20:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231683AbjIZFUc (ORCPT ); Tue, 26 Sep 2023 01:20:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E04B312A; Mon, 25 Sep 2023 22:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695705625; x=1727241625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/0/YnXJEcB9BbLqlQjSk46oBKNZtRMAfDcTDuka6q4c=; b=jBwODYqCk5oXJDf6s7w2mXj+RnNta6A7XAjkFwKDOSN+ust9W8v2ITS/ SBJFeLzFF9j/non28Nc5pjBhjrY9eg1CxzzDTJsDhD+FaxIr52bSLZgww UZSLgbkbrU6ABpD2friyG9PPfO7CyWnO7ip3i8vWkHWXxGp+OSl0D+sCV cHSx604LAF4SJ/g+0kD1l6x/zSCGbqmHlenbY/fu+eZSeUGOhaXTTdKMy HTHd5HWyHXOzCGb/e0iu5mHz7HF3tKUzyUyDq/02YPD5gsxnGBCrSOeci xFkCMtFLVpl0ImU4edxgUD+K91nyxrYAEmyZZEBPb8F3IthuW0HjNyqsb Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="360865691" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="360865691" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 22:20:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="748689668" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="748689668" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 25 Sep 2023 22:20:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id F04B91C7; Tue, 26 Sep 2023 08:20:18 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Yury Norov , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Bartosz Golaszewski , Andy Shevchenko , Rasmus Villemoes , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v1 3/5] gpio: xilinx: Switch to use new bitmap_scatter() helper Date: Tue, 26 Sep 2023 08:20:05 +0300 Message-Id: <20230926052007.3917389-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> References: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 25 Sep 2023 22:21:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778092064675503255 X-GMAIL-MSGID: 1778092064675503255 bitmaps_scatter() produces a sparse bitmap based on the dense one and a given mask. In this driver the given mask is hw_map, while sw_map is of sequential bits. We may use the bitmap_scatter() helper instead of bitmap_remap(), because it's optimized for our case. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpio-xilinx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index a16945e8319e..f103c30cc74f 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -208,8 +208,8 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long flags; struct xgpio_instance *chip = gpiochip_get_data(gc); - bitmap_remap(hw_mask, mask, chip->sw_map, chip->hw_map, 64); - bitmap_remap(hw_bits, bits, chip->sw_map, chip->hw_map, 64); + bitmap_scatter(hw_mask, mask, chip->hw_map, 64); + bitmap_scatter(hw_bits, bits, chip->hw_map, 64); spin_lock_irqsave(&chip->gpio_lock, flags); From patchwork Tue Sep 26 05:20:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 144724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1684921vqu; Mon, 25 Sep 2023 22:30:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYkw8x2YP3vBpX00sOcbqStsKLzPb6HndMqSEEwf02KKpRcdTQ7go/2HWRBHNVIApVYzWF X-Received: by 2002:a05:6a20:9151:b0:15e:b8a1:57b0 with SMTP id x17-20020a056a20915100b0015eb8a157b0mr4550904pzc.39.1695706204267; Mon, 25 Sep 2023 22:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695706204; cv=none; d=google.com; s=arc-20160816; b=EafoApdsgcJNwrUB1FoI01C0/dzeJO+8QA1PoKX+A0indUhD1vakb6rT9zdNGDWvps ZZp028PFMmoGqgzgXY5wqcbLrl0nZt2BMUIoQlh+sN88R8XA8EdTsFZ7UA7+LnnqVLl4 eKQDnX9d0NxLgwYK5m7FV4Yo3hMJ6ukt9y8Y5VLSSah6iWpuA7Q6dVqFXQZz7OgWdNrN QVRrOZ+sdYcZnHmO9RDH7bjhZI4FP6NwkpAAj8rxFi0ah9LkSZLDqfg16mmqRfLPoLdN wkSeUTZ1ZVOCbVKUPOHppxyJlZsuDneWtVwQDo5Q0tMV5wClhG6bOZezdSxmFXORJx8m ETmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pBJX8Sz54k15/RBkZi9RYeKLTRV90CVvnRpvGJ+6Ev8=; fh=vW1oNT0lvWbI8AMX2u/BZGKXD0nTZmrv2xM94BgUfog=; b=eRnkuiafTsGpCfecgVnsDU//rANfLX4phJdL+hm3g/nQYFhv5c/2t+R52GEMp1bL14 OFxYMDB46jA3j3FW4IOB06Iza1w9jvOljHcV1DV7U1YlYIbIw+t1iNf8L4UinTsJ7uZA D+QEfUDiUIMIsdo/GbaicwczmsY0WW0YrWZJ870OoX94VmR0Qtlnvmt2pH41raCZL98g SEODO3tONyFSIbnVRJ9bLIoWG15tVflWqNtHcUA2P+nR+OP2SKeT9q10o2pbsxLC7nbV AmI+61FBQPPyEJ6/uB2TZy44KZ98IKGxnidzLI0RZDdWPqtphK6za/YbkSZatX7c1YkQ od1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GfCkes34; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e8-20020a170902cf4800b001bde9e8a29fsi10639063plg.183.2023.09.25.22.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 22:30:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GfCkes34; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 18F7E80A1858; Mon, 25 Sep 2023 22:20:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233361AbjIZFUo (ORCPT + 26 others); Tue, 26 Sep 2023 01:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231628AbjIZFUc (ORCPT ); Tue, 26 Sep 2023 01:20:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79821120; Mon, 25 Sep 2023 22:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695705625; x=1727241625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nbE19XBFoeQsTwGAJN998UHeoS6jXenyajr7Dybr/A4=; b=GfCkes340mSo6zWeejPwvvdkXhS6tIoMiLioOMVARO0N/t8mrnrXjsMU FWjg7u22teNHMSQDsQJOw4OGilZbUc8IIZM1LtFwo/sAujghyjfPOoN5F NADAiiRjfC9cf+WLYBFQ3h1hEyQ3O0kkW9lI8gL4ZBLj8ShR3BN9H+L+d eJwlfy/a3Hi71+OOaHPAfEL7rGEeFADSAIWO9dY5NKiy97ZySk//BFRAm BtN0UcN2a1tTdi3YDflLBLyh9qDjTGFYwgrcqzsa6MV4cmveIG0/3vmwU GcnXs4rJoO0PhsJydM7J8xsSM8Yf66jAXVmjcGPMUmdG8I+f36BpR9f7f Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="371820585" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="371820585" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 22:20:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="783824217" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="783824217" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 25 Sep 2023 22:20:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 06CAD919; Tue, 26 Sep 2023 08:20:19 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Yury Norov , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Bartosz Golaszewski , Andy Shevchenko , Rasmus Villemoes , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v1 4/5] gpio: xilinx: Replace bitmap_bitremap() calls Date: Tue, 26 Sep 2023 08:20:06 +0300 Message-Id: <20230926052007.3917389-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> References: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 22:20:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778076829115310314 X-GMAIL-MSGID: 1778076829115310314 We have sparse and dence masks of the line mappings based on the view point (Linux numbering or hardware numbering). Since the Linux side uses sequential bits for the mask, we can simply convert a Linux number to the hardware one and vise versa by counting set bits in the respective mask. Hence replace bitmap_bitremap() calls by simpler equivalents. With this done the dence mask is not needed and thus dropped. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpio-xilinx.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index f103c30cc74f..14ca3097563a 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -46,7 +46,6 @@ * @gc: GPIO chip * @regs: register block * @hw_map: GPIO pin mapping on hardware side - * @sw_map: GPIO pin mapping on software side * @state: GPIO write state shadow register * @last_irq_read: GPIO read state register from last interrupt * @dir: GPIO direction shadow register @@ -62,7 +61,6 @@ struct xgpio_instance { struct gpio_chip gc; void __iomem *regs; DECLARE_BITMAP(hw_map, 64); - DECLARE_BITMAP(sw_map, 64); DECLARE_BITMAP(state, 64); DECLARE_BITMAP(last_irq_read, 64); DECLARE_BITMAP(dir, 64); @@ -76,12 +74,12 @@ struct xgpio_instance { static inline int xgpio_from_bit(struct xgpio_instance *chip, int bit) { - return bitmap_bitremap(bit, chip->hw_map, chip->sw_map, 64); + return bitmap_weight(chip->hw_map, bit + 1); } static inline int xgpio_to_bit(struct xgpio_instance *chip, int gpio) { - return bitmap_bitremap(gpio, chip->sw_map, chip->hw_map, 64); + return find_nth_bit(chip->hw_map, 64, gpio); } static inline u32 xgpio_get_value32(const unsigned long *map, int bit) @@ -619,9 +617,6 @@ static int xgpio_probe(struct platform_device *pdev) if (width[1] > 32) return -EINVAL; - /* Setup software pin mapping */ - bitmap_set(chip->sw_map, 0, width[0] + width[1]); - /* Setup hardware pin mapping */ bitmap_set(chip->hw_map, 0, width[0]); bitmap_set(chip->hw_map, 32, width[1]); From patchwork Tue Sep 26 05:20:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 144937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1996872vqu; Tue, 26 Sep 2023 08:22:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjd6tQGyIC4/T2h9zAmwugVpGVDZbFJpih7ezPPfHF/RoaXsMSR5loseWGJW2i37b8tRCR X-Received: by 2002:a17:90b:1287:b0:274:6d4e:e0d9 with SMTP id fw7-20020a17090b128700b002746d4ee0d9mr9264141pjb.45.1695741757119; Tue, 26 Sep 2023 08:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695741757; cv=none; d=google.com; s=arc-20160816; b=IdyScCcEeL61qw0NucsY8vK4WBlQzZHD7q6QMH1ErFarPlu1VbyggeVI2wfGgzIzwo buqD0oNKVOC6sq2gFR13PH8rXHACawIFrIdM4JsD5/ooK9a7KB5XnaczE7sKHvYlaK4Q 3IeawwPZp49gSryu0IE2la2psvPVOD5iguf1vXhEp2/4O6YZoHiWjq+0xBkHsb6z/0Sm DzMQ+8Wq1Tju1qk+84/g+uqRQH1bJcyBdap3mEFcCJsH/sH60FXpvK0HuOtTJryCiQPY VC0pjRVmQSy0Fpu84lkDf7Z6qOl9BNYcanKFWLDSJdEinVEVFpkkaZjuI2OvgXVew98c GtsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5A548O0tLyQT1QoOeHI3rcVy8RDU676utBgf7/p9rTA=; fh=vW1oNT0lvWbI8AMX2u/BZGKXD0nTZmrv2xM94BgUfog=; b=q/7hiY5HKnAkbxPPRnWWUVIT8GaQOpPka8C6xAdbHOAeHEY+voARkKWbCPRPFUFnCI oDEEBsuWo13Kz5CdGxRzt4aZVmrwTI5OsXGMtGcpXWZY644ZcbyfXGWXbcyxfEhglhGt 8wCuifE5XpZtiZjhgake6jQc433wrFk/XarmZOxG4x7Gku6nnzjZlJVAdlSbSDMU0wqV CnXv66i92SQtpK2ywzS4lizxD5TNMt04puUMPloDOO9vNOPOCYjJChtkqVkFlqEB+7FY xPONa1kj3n2XZ5R9PBForKK9oMiONjdE+H+NeiA0sfQP+MpbwVJ9RB2bF1dQyUjBTtLh 7P8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bqkT8gDq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id lx4-20020a17090b4b0400b002766354b7aesi16781491pjb.166.2023.09.26.08.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 08:22:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bqkT8gDq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id EB4A1826E325; Mon, 25 Sep 2023 22:21:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233695AbjIZFU6 (ORCPT + 26 others); Tue, 26 Sep 2023 01:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232239AbjIZFUg (ORCPT ); Tue, 26 Sep 2023 01:20:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 279EEF2; Mon, 25 Sep 2023 22:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695705629; x=1727241629; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2HOZ+oim+zNWe8lFVHeNEs80ZdHaUduFZXUMLCdW3No=; b=bqkT8gDq5l9vXOhCHEgLdaTSreExf3hLjWetfKuF5mDvlLkMjzhjBDvg AIMYx2wJJMbAk2JE/8R2pey70Yl3Fgtq90qDT8Su8ov8f/CaGJuSVgxPT 810FWwAgcTLuQnr6P0MBwIHQKfhqfO8EFKuHPSz5cEfKLDCub1TbrMsti eg6EknMbrt5BE4zHo745ZXI+t0du5YUZBREMECiDeNlOOssrCM28jd4xp +3b7F+2RRrXUiV4Kkr+7EucffQXyrewKB2POEPrOnn9gQvK9mg3Croqz6 hbom/b3fvi+0NgoR+Dh0grVl2zfLYNnRmikv5uw9gNB2kSRZygzYvMp0x g==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="360865705" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="360865705" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 22:20:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="748689685" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="748689685" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 25 Sep 2023 22:20:24 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 162DB133D; Tue, 26 Sep 2023 08:20:19 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Yury Norov , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Bartosz Golaszewski , Andy Shevchenko , Rasmus Villemoes , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v1 5/5] gpiolib: cdev: Utilize more bitmap APIs Date: Tue, 26 Sep 2023 08:20:07 +0300 Message-Id: <20230926052007.3917389-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> References: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 22:21:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778114108975291142 X-GMAIL-MSGID: 1778114108975291142 Currently we have a few bitmap calls that are open coded in the library module. Let's convert them to use generic bitmap APIs instead. Signed-off-by: Andy Shevchenko Tested-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 79 +++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index e39d344feb28..a5bbbd44531f 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -1263,35 +1263,32 @@ static long linereq_get_values(struct linereq *lr, void __user *ip) { struct gpio_v2_line_values lv; DECLARE_BITMAP(vals, GPIO_V2_LINES_MAX); + DECLARE_BITMAP(mask, GPIO_V2_LINES_MAX); + DECLARE_BITMAP(bits, GPIO_V2_LINES_MAX); struct gpio_desc **descs; unsigned int i, didx, num_get; - bool val; int ret; /* NOTE: It's ok to read values of output lines. */ if (copy_from_user(&lv, ip, sizeof(lv))) return -EFAULT; - for (num_get = 0, i = 0; i < lr->num_lines; i++) { - if (lv.mask & BIT_ULL(i)) { - num_get++; - descs = &lr->lines[i].desc; - } - } + bitmap_from_arr64(mask, &lv.mask, GPIO_V2_LINES_MAX); + num_get = bitmap_weight(mask, lr->num_lines); if (num_get == 0) return -EINVAL; - if (num_get != 1) { + if (num_get == 1) { + descs = &lr->lines[find_first_bit(mask, lr->num_lines)].desc; + } else { descs = kmalloc_array(num_get, sizeof(*descs), GFP_KERNEL); if (!descs) return -ENOMEM; - for (didx = 0, i = 0; i < lr->num_lines; i++) { - if (lv.mask & BIT_ULL(i)) { - descs[didx] = lr->lines[i].desc; - didx++; - } - } + + didx = 0; + for_each_set_bit(i, mask, lr->num_lines) + descs[didx++] = lr->lines[i].desc; } ret = gpiod_get_array_value_complex(false, true, num_get, descs, NULL, vals); @@ -1301,19 +1298,15 @@ static long linereq_get_values(struct linereq *lr, void __user *ip) if (ret) return ret; - lv.bits = 0; - for (didx = 0, i = 0; i < lr->num_lines; i++) { - if (lv.mask & BIT_ULL(i)) { - if (lr->lines[i].sw_debounced) - val = debounced_value(&lr->lines[i]); - else - val = test_bit(didx, vals); - if (val) - lv.bits |= BIT_ULL(i); - didx++; - } + bitmap_scatter(bits, vals, mask, lr->num_lines); + + for_each_set_bit(i, mask, lr->num_lines) { + if (lr->lines[i].sw_debounced) + __assign_bit(i, bits, debounced_value(&lr->lines[i])); } + bitmap_to_arr64(&lv.bits, bits, GPIO_V2_LINES_MAX); + if (copy_to_user(ip, &lv, sizeof(lv))) return -EFAULT; @@ -1324,35 +1317,35 @@ static long linereq_set_values_unlocked(struct linereq *lr, struct gpio_v2_line_values *lv) { DECLARE_BITMAP(vals, GPIO_V2_LINES_MAX); + DECLARE_BITMAP(mask, GPIO_V2_LINES_MAX); + DECLARE_BITMAP(bits, GPIO_V2_LINES_MAX); struct gpio_desc **descs; unsigned int i, didx, num_set; int ret; - bitmap_zero(vals, GPIO_V2_LINES_MAX); - for (num_set = 0, i = 0; i < lr->num_lines; i++) { - if (lv->mask & BIT_ULL(i)) { - if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags)) - return -EPERM; - if (lv->bits & BIT_ULL(i)) - __set_bit(num_set, vals); - num_set++; - descs = &lr->lines[i].desc; - } - } + bitmap_from_arr64(mask, &lv->mask, GPIO_V2_LINES_MAX); + bitmap_from_arr64(bits, &lv->bits, GPIO_V2_LINES_MAX); + + num_set = bitmap_gather(vals, bits, mask, lr->num_lines); if (num_set == 0) return -EINVAL; - if (num_set != 1) { + for_each_set_bit(i, mask, lr->num_lines) { + if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags)) + return -EPERM; + } + + if (num_set == 1) { + descs = &lr->lines[find_first_bit(mask, lr->num_lines)].desc; + } else { /* build compacted desc array and values */ descs = kmalloc_array(num_set, sizeof(*descs), GFP_KERNEL); if (!descs) return -ENOMEM; - for (didx = 0, i = 0; i < lr->num_lines; i++) { - if (lv->mask & BIT_ULL(i)) { - descs[didx] = lr->lines[i].desc; - didx++; - } - } + + didx = 0; + for_each_set_bit(i, mask, lr->num_lines) + descs[didx++] = lr->lines[i].desc; } ret = gpiod_set_array_value_complex(false, true, num_set, descs, NULL, vals);