From: Herve Codina <herve.codina@bootlin.com>
To: Vadim Fedorenko <vadim.fedorenko@linux.dev>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Herve Codina <herve.codina@bootlin.com>,
Yury Norov <yury.norov@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, Andrew Lunn <andrew@lunn.ch>,
Mark Brown <broonie@kernel.org>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [RESEND PATCH v3 4/6] bitmap: Introduce bitmap_off()
Date: Mon, 12 Feb 2024 08:56:39 +0100 [thread overview]
Message-ID: <20240212075646.19114-12-herve.codina@bootlin.com> (raw)
In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com>
The bitmap_onto() function translates one bitmap relative to another but
no function are present to perform the reverse translation.
Introduce bitmap_off() to fill this hole.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
include/linux/bitmap.h | 3 +++
lib/bitmap.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 99451431e4d6..5ecfcbbc91f4 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -65,6 +65,7 @@ struct device;
* 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
+ * bitmap_off(dst, orig, relmap, nbits) *dst = bitmap_onto() reverse operation
* bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz
* bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf
* bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf
@@ -208,6 +209,8 @@ int bitmap_bitremap(int oldbit,
const unsigned long *old, const unsigned long *new, int bits);
void bitmap_onto(unsigned long *dst, const unsigned long *orig,
const unsigned long *relmap, unsigned int bits);
+void bitmap_off(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);
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 2feccb5047dc..71343967335e 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -682,6 +682,48 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig,
}
EXPORT_SYMBOL(bitmap_onto);
+/**
+ * bitmap_off - revert operation done by bitmap_onto()
+ * @dst: resulting translated bitmap
+ * @orig: original untranslated bitmap
+ * @relmap: bitmap relative to which translated
+ * @bits: number of bits in each of these bitmaps
+ *
+ * Suppose onto computed using bitmap_onto(onto, src, relmap, n)
+ * The operation bitmap_off(result, onto, relmap, n) leads to a
+ * result equal or equivalent to src.
+ *
+ * The result can be 'equivalent' because bitmap_onto() and
+ * bitmap_off() are not bijective.
+ * The result and src values are equivalent in that sense that a
+ * call to bitmap_onto(onto, src, relmap, n) and a call to
+ * bitmap_onto(onto, result, relmap, n) will lead to the same onto
+ * value.
+ *
+ * If either of @orig or @relmap is empty (no set bits), then @dst
+ * will be returned empty.
+ *
+ * All bits in @dst not set by the above rule are cleared.
+ */
+void bitmap_off(unsigned long *dst, const unsigned long *orig,
+ const unsigned long *relmap, unsigned int bits)
+{
+ unsigned int n, m; /* same meaning as in above comment */
+
+ if (dst == orig) /* following doesn't handle inplace mappings */
+ return;
+ bitmap_zero(dst, bits);
+
+ m = 0;
+ for_each_set_bit(n, relmap, bits) {
+ /* m == bitmap_pos_to_ord(relmap, n, bits) */
+ if (test_bit(n, orig))
+ set_bit(m, dst);
+ m++;
+ }
+}
+EXPORT_SYMBOL(bitmap_off);
+
#ifdef CONFIG_NUMA
/**
* bitmap_fold - fold larger bitmap into smaller, modulo specified size
--
2.43.0
next prev parent reply other threads:[~2024-02-12 7:57 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 7:56 [PATCH v3 RESEND 0/6] Add support for QMC HDLC Herve Codina
2024-02-12 7:56 ` [PATCH v3 RESEND 1/6] net: wan: " Herve Codina
2024-02-12 12:22 ` Andy Shevchenko
2024-02-22 12:05 ` Herve Codina
2024-02-22 13:19 ` Andy Shevchenko
2024-02-22 13:21 ` Herve Codina
2024-02-12 7:56 ` [PATCH v3 RESEND 2/6] MAINTAINERS: Add the Freescale QMC HDLC driver entry Herve Codina
2024-02-12 7:56 ` [PATCH v3 RESEND 3/6] bitmap: Make bitmap_onto() available to users Herve Codina
2024-02-12 12:27 ` Andy Shevchenko
2024-02-12 13:37 ` Herve Codina
2024-02-12 14:01 ` Andy Shevchenko
2024-02-12 14:20 ` Herve Codina
2024-02-12 14:36 ` Andy Shevchenko
2024-02-12 19:13 ` Yury Norov
2024-02-15 17:46 ` Herve Codina
2024-02-15 19:17 ` Andy Shevchenko
2024-02-21 13:44 ` Herve Codina
2024-02-21 14:30 ` Andy Shevchenko
2024-02-12 7:56 ` [PATCH v3 RESEND 4/6] bitmap: Introduce bitmap_off() Herve Codina
2024-02-12 9:45 ` Rasmus Villemoes
2024-02-12 18:37 ` Yury Norov
2024-02-12 18:41 ` Yury Norov
2024-02-12 7:56 ` [PATCH v3 RESEND 5/6] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support Herve Codina
2024-02-12 7:56 ` [PATCH v3 RESEND 6/6] net: wan: fsl_qmc_hdlc: Add framer support Herve Codina
2024-02-12 7:56 ` [RESEND PATCH v3 0/6] Add support for QMC HDLC Herve Codina
2024-02-12 7:56 ` [RESEND PATCH v3 1/6] net: wan: " Herve Codina
2024-02-12 7:56 ` [RESEND PATCH v3 2/6] MAINTAINERS: Add the Freescale QMC HDLC driver entry Herve Codina
2024-02-12 7:56 ` [RESEND PATCH v3 3/6] bitmap: Make bitmap_onto() available to users Herve Codina
2024-02-12 7:56 ` Herve Codina [this message]
2024-02-12 7:56 ` [RESEND PATCH v3 5/6] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support Herve Codina
2024-02-12 7:56 ` [RESEND PATCH v3 6/6] net: wan: fsl_qmc_hdlc: Add framer support Herve Codina
2024-02-12 8:05 ` [PATCH v3 RESEND 0/6] Add support for QMC HDLC Herve Codina
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=20240212075646.19114-12-herve.codina@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=andrew@lunn.ch \
--cc=andriy.shevchenko@linux.intel.com \
--cc=broonie@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vadim.fedorenko@linux.dev \
--cc=yury.norov@gmail.com \
/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).