summaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_bitmap.c
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-03-04 09:59:15 +0300
committerAnup Patel <anup@brainfault.org>2020-03-11 12:59:45 +0300
commit3226bd93ce41ed0c815a9021f5e489cfe3e83fa3 (patch)
treeb518dafa8e44c3d03f66a1eb9456afae38782e1b /lib/sbi/sbi_bitmap.c
parent078686d75c929af72971bb51115438e3a2826896 (diff)
downloadopensbi-3226bd93ce41ed0c815a9021f5e489cfe3e83fa3.tar.xz
lib: Simple bitmap library
We add simple bitmap library which will help us create and maintain bitmaps. It will also help us create a simple HART mask library. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'lib/sbi/sbi_bitmap.c')
-rw-r--r--lib/sbi/sbi_bitmap.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/sbi/sbi_bitmap.c b/lib/sbi/sbi_bitmap.c
new file mode 100644
index 0000000..e74b6bb
--- /dev/null
+++ b/lib/sbi/sbi_bitmap.c
@@ -0,0 +1,40 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ * Anup Patel <anup.patel@wdc.com>
+ */
+
+#include <sbi/sbi_bitmap.h>
+
+void __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2, int bits)
+{
+ int k;
+ int nr = BITS_TO_LONGS(bits);
+
+ for (k = 0; k < nr; k++)
+ dst[k] = bitmap1[k] & bitmap2[k];
+}
+
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2, int bits)
+{
+ int k;
+ int nr = BITS_TO_LONGS(bits);
+
+ for (k = 0; k < nr; k++)
+ dst[k] = bitmap1[k] | bitmap2[k];
+}
+
+void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2, int bits)
+{
+ int k;
+ int nr = BITS_TO_LONGS(bits);
+
+ for (k = 0; k < nr; k++)
+ dst[k] = bitmap1[k] ^ bitmap2[k];
+}