From patchwork Tue Jan 20 23:43:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1714 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768952681; bh=zLxp9ZLzqqLD39gIcF6LQ0VYCJF5zlXP5372OmNrPZc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ZzvchWXOl+JQVQmLTNV+s/DhqlpFOgGhZYmmsrwGYCgqsfjny1kJULs0jGdR9UIxm 8YO9044oSN87lLNiPwvlOrlo8qujAkR4IM17eUs+t/4oEBY+Znx1YvDC2wWAhHWfMT 7nbDvAk1OfMw4c+2I0kBKPlAUTBUWM/avVZKmO1yA4wfJW6Up6O6Cu3yzqNYKkqU1t rlU5FnVH3xX0vp05pLJndPoo0CUh/l17hUVRpL7KVxSB1yqYWSjFeaM5NMe1/kaPwo RaAGybqUzfIC+peF7Qds8NTJNexFLfOuFG6I+aQoLjn/MaDR6riHJT+wzOea9g3lWu Ju8+iayCCOPnA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F39E8695AE for ; Tue, 20 Jan 2026 16:44:41 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cWdy4BvDCaj7 for ; Tue, 20 Jan 2026 16:44:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768952681; bh=zLxp9ZLzqqLD39gIcF6LQ0VYCJF5zlXP5372OmNrPZc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ZzvchWXOl+JQVQmLTNV+s/DhqlpFOgGhZYmmsrwGYCgqsfjny1kJULs0jGdR9UIxm 8YO9044oSN87lLNiPwvlOrlo8qujAkR4IM17eUs+t/4oEBY+Znx1YvDC2wWAhHWfMT 7nbDvAk1OfMw4c+2I0kBKPlAUTBUWM/avVZKmO1yA4wfJW6Up6O6Cu3yzqNYKkqU1t rlU5FnVH3xX0vp05pLJndPoo0CUh/l17hUVRpL7KVxSB1yqYWSjFeaM5NMe1/kaPwo RaAGybqUzfIC+peF7Qds8NTJNexFLfOuFG6I+aQoLjn/MaDR6riHJT+wzOea9g3lWu Ju8+iayCCOPnA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DFB00695A6 for ; Tue, 20 Jan 2026 16:44:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768952680; bh=SVnysCULzSHtk2+Ss+GOStDPo5SIA3NVvCJwSBpnnaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OWOqeaVsW9pvEKNkCiiRrYMwp9xX1iqj2YpVUu63UuvhekeqOwAaj+Z5ISHpoFwkS 3++rmFokM4637A+GJ51WAR/e+B9GSpI7FBtcXayk4yn+XToHXeQqNOJKPAPz5U70+E /CGuXg1/kdXPcr5kmpF9thE48R60bfkR6Itf1ijsV7fQ9Zg4JufkS0aJS90jsZFORH B8EsKv/jk1gN6wcYLseHN3c+Jt+gOSh3e7kmw2zbG1/mnd5Ljqde4gcFy4K3FAMdUd 6DuPQ+fEMAJjTafpWZ2Oy+co3yTzbBDlW6kb+Ex1velDAyJezuakagnpi0qt4NYC6q EPlNuvtLjf33g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DE1BB69597; Tue, 20 Jan 2026 16:44:40 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id PkBQyXD2o7Zl; Tue, 20 Jan 2026 16:44:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768952676; bh=Q20/7xcl5vlJqEtwg6a/mulNeFhANtqlC8TykXUpUGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eQGAJZpXpnMy1jUs8F4n6GbpBUsD6K/WvGUV329+uy7+6zz4j6z/CMz2RFu2GnjzY Ysfy7byLX+w6+YLbKAN+QD7ivARIBk1JAy16sREAaAOORr1QuPSv6lm0+UMH9yLlPd 8JLlvJMtkyxi6lLUaFm5MC4w0tN8IXRWJUo/o8GT0GzMmc7IF79FGXtNhyyyHvVLOp ULig4yEtfwQ7UJsTYhpnG1aDltAbcBHQPc1Hmzs8PNba7zCbisx9tyrQCBWNuBZCwV HA3HSUU52n9KiMT7uLhwNcLaW1VTTxs190hauN9bfGJ7nC1U7Hvh6+zOV6+Y/S0Js7 djpuQXlOOEEOw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 759BC69555; Tue, 20 Jan 2026 16:44:36 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 20 Jan 2026 16:43:25 -0700 Message-ID: <20260120234344.495605-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120234344.495605-1-sjg@u-boot.org> References: <20260120234344.495605-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: URZ27TIWFFKJHMLCVD7UV5NVHUXSFI7D X-Message-ID-Hash: URZ27TIWFFKJHMLCVD7UV5NVHUXSFI7D X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/17] ext4l: Create asm-generic/bitops/le.h for little-endian bitops List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Move little-endian bit operations to asm-generic/bitops/le.h: - find_next_zero_bit_le, find_next_bit_le - test_bit_le, __set_bit_le, __clear_bit_le - __test_and_set_bit_le, __test_and_clear_bit_le This matches the Linux kernel header organisation and removes duplicate implementations from ext4_uboot.h. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 38 ++--------------- include/asm-generic/bitops/le.h | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 include/asm-generic/bitops/le.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index a493fb58ad7..6f2ea69a888 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -204,15 +204,8 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); * We implement them in interface.c for sandbox. */ -/* Little-endian bit operations - use arch-provided find_next_zero_bit */ -#define find_next_zero_bit_le(addr, size, offset) \ - find_next_zero_bit((void *)addr, size, offset) -#define __set_bit_le(nr, addr) set_bit(nr, addr) -#define test_bit_le(nr, addr) test_bit(nr, addr) -#define __test_and_clear_bit_le(nr, addr) \ - ({ int __old = test_bit(nr, addr); clear_bit(nr, addr); __old; }) -#define __test_and_set_bit_le(nr, addr) \ - ({ int __old = test_bit(nr, addr); set_bit(nr, addr); __old; }) +/* Little-endian bit operations - use asm-generic/bitops/le.h */ +#include /* KUNIT stub - use kunit/static_stub.h */ #include @@ -1280,32 +1273,7 @@ struct buffer_head *__bread(struct block_device *bdev, sector_t block, unsigned /* XArray is now in linux/xarray.h */ /* Per-CPU stubs are in linux/percpu.h */ -/* Bit operations for little-endian bitmaps */ -#define __clear_bit_le(bit, addr) clear_bit_le(bit, addr) - -static inline void clear_bit_le(int nr, void *addr) -{ - unsigned char *p = (unsigned char *)addr + (nr >> 3); - - *p &= ~(1 << (nr & 7)); -} - -#define find_next_bit_le(addr, size, offset) \ - ext4_find_next_bit_le(addr, size, offset) - -static inline unsigned long ext4_find_next_bit_le(const void *addr, - unsigned long size, - unsigned long offset) -{ - const unsigned char *p = addr; - unsigned long bit; - - for (bit = offset; bit < size; bit++) { - if (p[bit >> 3] & (1 << (bit & 7))) - return bit; - } - return size; -} +/* Little-endian bit operations are in asm-generic/bitops/le.h */ /* atomic64 operations are now in asm-generic/atomic.h */ diff --git a/include/asm-generic/bitops/le.h b/include/asm-generic/bitops/le.h new file mode 100644 index 00000000000..78c7207c691 --- /dev/null +++ b/include/asm-generic/bitops/le.h @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Little-endian bitops for U-Boot + * + * Based on Linux include/asm-generic/bitops/le.h + */ +#ifndef _ASM_GENERIC_BITOPS_LE_H +#define _ASM_GENERIC_BITOPS_LE_H + +#include + +/* + * Little-endian bit operations. + * These operate on byte boundaries regardless of CPU endianness. + */ + +#define find_next_zero_bit_le(addr, size, offset) \ + find_next_zero_bit((void *)(addr), (size), (offset)) + +#define find_next_bit_le(addr, size, offset) \ + ext4_find_next_bit_le((addr), (size), (offset)) + +static inline int test_bit_le(int nr, const void *addr) +{ + return test_bit(nr, addr); +} + +static inline void __set_bit_le(int nr, void *addr) +{ + set_bit(nr, addr); +} + +static inline void __clear_bit_le(int nr, void *addr) +{ + clear_bit(nr, addr); +} + +static inline int __test_and_set_bit_le(int nr, void *addr) +{ + int old = test_bit(nr, addr); + + set_bit(nr, addr); + return old; +} + +static inline int __test_and_clear_bit_le(int nr, void *addr) +{ + int old = test_bit(nr, addr); + + clear_bit(nr, addr); + return old; +} + +/* + * ext4_find_next_bit_le - find next set bit in little-endian bitmap + * @addr: bitmap address + * @size: bitmap size in bits + * @offset: starting bit position + * + * Return: bit position of next set bit, or @size if none found + */ +static inline unsigned long ext4_find_next_bit_le(const void *addr, + unsigned long size, + unsigned long offset) +{ + const unsigned char *p = addr; + unsigned long bit; + + for (bit = offset; bit < size; bit++) { + if (p[bit >> 3] & (1 << (bit & 7))) + return bit; + } + return size; +} + +#endif /* _ASM_GENERIC_BITOPS_LE_H */