[PATCH 1/5] sandbox: add generic find_next_zero_bit implementation
lukas.funke-oss at weidmueller.com
lukas.funke-oss at weidmueller.com
Mon Dec 11 13:20:47 CET 2023
From: Lukas Funke <lukas.funke at weidmueller.com>
Add generic 'find_next_zero_bit' implementation in order to enable the
use of the 'for_each_set_bitrange' macro. The implementation is currently
missing for the sandbox-arch and using the function results in a linker
error.
There are more efficient implementations in the architecture specific
implementations. However, for the sandbox the implementation should be
simple and portable.
Signed-off-by: Lukas Funke <lukas.funke at weidmueller.com>
---
arch/sandbox/include/asm/bitops.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/arch/sandbox/include/asm/bitops.h b/arch/sandbox/include/asm/bitops.h
index f27d5e98c5..453ff005d2 100644
--- a/arch/sandbox/include/asm/bitops.h
+++ b/arch/sandbox/include/asm/bitops.h
@@ -104,8 +104,20 @@ static inline int __test_and_change_bit(int nr, void *addr)
return (old & mask) != 0;
}
-extern int find_first_zero_bit(void *addr, unsigned size);
-extern int find_next_zero_bit(void *addr, int size, int offset);
+#define find_first_zero_bit(addr, size) \
+ find_next_zero_bit((addr), (size), 0)
+
+static inline int find_next_zero_bit(const unsigned long *addr, int size,
+ int offset) {
+ unsigned long *p = ((unsigned long *)addr) + (offset >> 5);
+
+ while ((~(*p) & 0x1 << offset) == 0x0ll && (offset < size)) {
+ offset++;
+ p = ((unsigned long *)addr) + (offset >> 5);
+ }
+
+ return offset;
+}
/*
* This routine doesn't need to be atomic.
--
2.30.2
More information about the U-Boot
mailing list