[PATCH] fixup! include: import Linux word-at-a-time.h

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Nov 23 00:16:34 PST 2023


word-at-a-time: include linux/bitops for fls definitions

In Linux, <linux/kernel.h> includes <linux/bitops.h>, which eventually
defines fls/fls64/__fls. In barebox this is not the case, so we need to
explicitly include <linux/bitops.h>.

Also PPC_CNTLZL isn't supported in barebox. Fix that too to avoid
compile errors on PowerPC.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/include/asm/word-at-a-time.h     | 1 +
 arch/powerpc/include/asm/bitops.h         | 1 +
 arch/powerpc/include/asm/word-at-a-time.h | 8 +++++++-
 arch/riscv/include/asm/word-at-a-time.h   | 1 +
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/word-at-a-time.h b/arch/arm/include/asm/word-at-a-time.h
index f22198a66be3..a2b20be13d07 100644
--- a/arch/arm/include/asm/word-at-a-time.h
+++ b/arch/arm/include/asm/word-at-a-time.h
@@ -8,6 +8,7 @@
 #if !defined(__AARCH64EB__) && !defined(__ARMEB__)
 
 #include <linux/kernel.h>
+#include <linux/bitops.h>
 
 struct word_at_a_time {
 	const unsigned long one_bits, high_bits;
diff --git a/arch/powerpc/include/asm/bitops.h b/arch/powerpc/include/asm/bitops.h
index 543612e6ede3..62b09c7da49c 100644
--- a/arch/powerpc/include/asm/bitops.h
+++ b/arch/powerpc/include/asm/bitops.h
@@ -184,6 +184,7 @@ static inline int ffs(int x)
 	return __ilog2(x & -x) + 1;
 }
 
+#include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
 #include <asm-generic/bitops/hweight.h>
 
diff --git a/arch/powerpc/include/asm/word-at-a-time.h b/arch/powerpc/include/asm/word-at-a-time.h
index 1de46fbd2e15..029740c6dedf 100644
--- a/arch/powerpc/include/asm/word-at-a-time.h
+++ b/arch/powerpc/include/asm/word-at-a-time.h
@@ -6,6 +6,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/bitops.h>
 
 #ifdef __BIG_ENDIAN__
 
@@ -28,7 +29,12 @@ static inline long find_zero(unsigned long mask)
 {
 	long leading_zero_bits;
 
-	asm (PPC_CNTLZL "%0,%1" : "=r" (leading_zero_bits) : "r" (mask));
+#ifdef __powerpc64__
+	asm ("cntlzd %0,%1" : "=r" (leading_zero_bits) : "r" (mask));
+#else
+	asm ("cntlzw %0,%1" : "=r" (leading_zero_bits) : "r" (mask));
+#endif
+
 	return leading_zero_bits >> 3;
 }
 
diff --git a/arch/riscv/include/asm/word-at-a-time.h b/arch/riscv/include/asm/word-at-a-time.h
index 7c086ac6ecd4..74f077d38fe0 100644
--- a/arch/riscv/include/asm/word-at-a-time.h
+++ b/arch/riscv/include/asm/word-at-a-time.h
@@ -10,6 +10,7 @@
 
 
 #include <linux/kernel.h>
+#include <linux/bitops.h>
 
 struct word_at_a_time {
 	const unsigned long one_bits, high_bits;
-- 
2.39.2




More information about the barebox mailing list