From patchwork Sat Jan 17 01:14:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1566 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=1768612526; bh=k699ZLdGrucdqJUYo3pXxBeLdn0cwt01H2iIiJheG58=; 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=Bx2Uau2/mF6xCxpv500JMSCw+zDeQ9Za/sJTljEP70KR/pr6iBjRmSYiYNfYppQhP Udc4PZi9ELEGK/ku8JXvY3YfvY2Iix8wTv9WWwYnQ1kWdt05FWvCNipZp/CFloRV/j UXjQXGry8ZwTPIhsfiNSJJqZ670zvLLK2C+UX4I7LWeb95TlKPDrqOWskhj0TYGI4n O0l8kdZEPf+HwT44SZmMYOPWOh/4p7qlgLEXQ47khAuVG/snOKznlE+NjrJPkz/dli Pbp0QkWM/O3Af6EGJYZDFbqF8I/bxu0JoS4phxGG5ubzSxhwIFdZ2toscFZj1xI5am fh1pDBOpQhluw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F2D5B69404 for ; Fri, 16 Jan 2026 18:15:26 -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 D6gFAlJ6u_pL for ; Fri, 16 Jan 2026 18:15:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612526; bh=k699ZLdGrucdqJUYo3pXxBeLdn0cwt01H2iIiJheG58=; 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=Bx2Uau2/mF6xCxpv500JMSCw+zDeQ9Za/sJTljEP70KR/pr6iBjRmSYiYNfYppQhP Udc4PZi9ELEGK/ku8JXvY3YfvY2Iix8wTv9WWwYnQ1kWdt05FWvCNipZp/CFloRV/j UXjQXGry8ZwTPIhsfiNSJJqZ670zvLLK2C+UX4I7LWeb95TlKPDrqOWskhj0TYGI4n O0l8kdZEPf+HwT44SZmMYOPWOh/4p7qlgLEXQ47khAuVG/snOKznlE+NjrJPkz/dli Pbp0QkWM/O3Af6EGJYZDFbqF8I/bxu0JoS4phxGG5ubzSxhwIFdZ2toscFZj1xI5am fh1pDBOpQhluw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E29BC693F4 for ; Fri, 16 Jan 2026 18:15:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612525; bh=+RJt0c8bHpdvfG2+CzYqkmewVNEB083Izl6Umv5rii4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hlKMZWc8paQgbTlLTUb8jSxvAQv/fBIxYNPGp+7GrWFTod5VA4kgJF2ifLGzVISuf TRO6/Xf8b0GqcMhmzgw8uAQtAbDb4p9zaMNIGEzWLBeu+oITZjK9o58MHsjY/MeEPu b7ZgqCt5IS8TuaSsoEv3YKG/MwWU3bncsUUJb52nTYw6GJzHrIyxHP3EJph2fqTN97 maiE1RinmwfrLfrOw7bdMOXOWb1IGbD2nLSEPCqE5uXgbka7RHO9xVufvWCqaLxsml JpwTNf3W/luPJBC7vxRPGDev9UbHoqo6VsprUKWJakunlmGYzoWOx7lvLmZ2IN2RKE EXwTr3xi05y3g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 26C506913F; Fri, 16 Jan 2026 18:15:25 -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 dRu5Y-1yrSrz; Fri, 16 Jan 2026 18:15:25 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612521; bh=HFwaEf9KRx//rTiYePjdSOJzboXcEiWcrNe3mllQ5Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIP1ssS1AE/sMDnpKRKvANp/hIlk80JFOCdA3b3+SGGqG0iwXZVIHzH13dq2iXlsU WvFlnzbFFTu8IRsN8+cjXBbsA8mNMDNDl9W+SrraoCjwwWn6QD6Dcmo/z5DHpiscje 6Ng5y9NHwg9zlBqjTd8GoGopJMXaTt5YRuBqPGGlAcbIoVRVpYRbWwwKRXGKU0IwxU WpCt9r6+ix35BxD9Vfrgrg0orm+XpZPE/ACvTq0mPPA900foa3DQthD8gZGHXiXzEb LNKnqFJAfZFTJO5Kbl0dU1XY7q4MZnYu/a6Jg+0KcxNrhYA0aHXROqMKRiRTGTlX25 wZmKxy6qj/XSw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C94C7693E0; Fri, 16 Jan 2026 18:15:20 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 18:14:28 -0700 Message-ID: <20260117011448.3007171-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260117011448.3007171-1-sjg@u-boot.org> References: <20260117011448.3007171-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6ICBKW2JOILPUA7QOKJN5I2OQWTF2CS4 X-Message-ID-Hash: 6ICBKW2JOILPUA7QOKJN5I2OQWTF2CS4 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 06/19] linux: Add bio.h header with block I/O stubs 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 U-Boot does not have a real block I/O layer. The ext4l filesystem uses bio structures which are currently defined inline in ext4_uboot.h. Create a new linux/bio.h header file with stub implementations to better match the Linux kernel structure. Types and operations moved: - struct bio_vec - struct bvec_iter - struct bio - bio_sectors() - struct folio_iter - BIO_MAX_VECS - bio_for_each_folio_all() - bio_put() / bio_alloc() - submit_bio() - bio_add_folio() - blk_status_to_errno() - mapping_set_error() Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 65 ++--------------------- include/linux/bio.h | 117 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 62 deletions(-) create mode 100644 include/linux/bio.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 40c68085c7a..b49e6604589 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -1972,60 +1972,9 @@ static inline unsigned long ext4_find_next_bit_le(const void *addr, ({ (void)(bdev); 0U; }) /* - * Stubs for page-io.c + * Stubs for page-io.c - bio types are in linux/bio.h */ - -/* bio_vec - segment in a bio */ -struct bio_vec { - struct page *bv_page; - unsigned int bv_len; - unsigned int bv_offset; -}; - -/* bvec_iter - iterator for bio_vec */ -struct bvec_iter { - sector_t bi_sector; - unsigned int bi_size; - unsigned int bi_idx; - unsigned int bi_bvec_done; -}; - -/* bio - block I/O structure */ -struct bio { - struct bio *bi_next; - struct block_device *bi_bdev; - unsigned long bi_opf; - unsigned short bi_flags; - unsigned short bi_ioprio; - unsigned short bi_write_hint; - int bi_status; - struct bvec_iter bi_iter; - atomic_t __bi_remaining; - void *bi_private; - void (*bi_end_io)(struct bio *); -}; - -/* bio_sectors - return number of sectors in bio */ -static inline unsigned int bio_sectors(struct bio *bio) -{ - return bio->bi_iter.bi_size >> 9; -} - -/* folio_iter for bio iteration */ -struct folio_iter { - int i; - struct folio *folio; - size_t offset; - size_t length; -}; - -/* bio operations - stubs */ -#define bio_for_each_folio_all(fi, bio) \ - for ((fi).i = 0; (fi).i < 0; (fi).i++) -#define bio_put(bio) free(bio) -#define bio_alloc(bdev, vecs, op, gfp) ((struct bio *)calloc(1, sizeof(struct bio))) -#define submit_bio(bio) do { } while (0) -#define BIO_MAX_VECS 256 +#include /* refcount operations - map to atomic */ #define refcount_set(r, v) atomic_set((atomic_t *)(r), v) @@ -2037,12 +1986,6 @@ struct folio_iter { /* printk_ratelimited is in linux/printk.h */ -/* mapping_set_error - record error in address_space */ -#define mapping_set_error(m, e) do { (void)(m); (void)(e); } while (0) - -/* blk_status_to_errno - convert block status to errno */ -#define blk_status_to_errno(status) (-(status)) - /* atomic_inc is in asm-generic/atomic.h */ /* GFP_NOIO is in linux/slab.h */ @@ -2059,9 +2002,7 @@ bool __folio_start_writeback(struct folio *folio, bool keep_write); #define wbc_account_cgroup_owner(wbc, folio, bytes) \ do { (void)(wbc); (void)(folio); (void)(bytes); } while (0) -/* bio operations */ -#define bio_add_folio(bio, folio, len, off) \ - ({ (void)(bio); (void)(folio); (void)(len); (void)(off); 1; }) +/* bio_add_folio is in linux/bio.h */ /* * Stubs for readpage.c diff --git a/include/linux/bio.h b/include/linux/bio.h new file mode 100644 index 00000000000..d8a955dba12 --- /dev/null +++ b/include/linux/bio.h @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Block I/O structures stub for U-Boot + * + * U-Boot doesn't have a real block I/O layer, so these are stubs. + */ +#ifndef __LINUX_BIO_H +#define __LINUX_BIO_H + +#include +#include + +/* Forward declarations */ +struct block_device; +struct page; +struct folio; + +/** + * struct bio_vec - segment in a bio + * @bv_page: page containing the data + * @bv_len: length of the segment + * @bv_offset: offset within the page + */ +struct bio_vec { + struct page *bv_page; + unsigned int bv_len; + unsigned int bv_offset; +}; + +/** + * struct bvec_iter - iterator for bio_vec + * @bi_sector: current sector + * @bi_size: remaining size + * @bi_idx: current index into bio_vec array + * @bi_bvec_done: bytes completed in current bvec + */ +struct bvec_iter { + sector_t bi_sector; + unsigned int bi_size; + unsigned int bi_idx; + unsigned int bi_bvec_done; +}; + +/** + * struct bio - block I/O structure + * @bi_next: next bio in chain + * @bi_bdev: target block device + * @bi_opf: operation and flags + * @bi_flags: bio flags + * @bi_ioprio: I/O priority + * @bi_write_hint: write lifetime hint + * @bi_status: completion status + * @bi_iter: current position iterator + * @__bi_remaining: remaining count for chained bios + * @bi_private: private data for completion + * @bi_end_io: completion callback + * + * U-Boot stub. + */ +struct bio { + struct bio *bi_next; + struct block_device *bi_bdev; + unsigned long bi_opf; + unsigned short bi_flags; + unsigned short bi_ioprio; + unsigned short bi_write_hint; + int bi_status; + struct bvec_iter bi_iter; + atomic_t __bi_remaining; + void *bi_private; + void (*bi_end_io)(struct bio *); +}; + +/** + * bio_sectors() - return number of sectors in bio + * @bio: bio to query + * + * Return: number of 512-byte sectors + */ +static inline unsigned int bio_sectors(struct bio *bio) +{ + return bio->bi_iter.bi_size >> 9; +} + +/** + * struct folio_iter - iterator for folio iteration over bio + * @i: current index + * @folio: current folio + * @offset: offset within folio + * @length: length of current segment + */ +struct folio_iter { + int i; + struct folio *folio; + size_t offset; + size_t length; +}; + +/* Maximum number of bio_vecs */ +#define BIO_MAX_VECS 256 + +/* bio operations - stubs */ +#define bio_for_each_folio_all(fi, bio) \ + for ((fi).i = 0; (fi).i < 0; (fi).i++) +#define bio_put(bio) free(bio) +#define bio_alloc(bdev, vecs, op, gfp) ((struct bio *)calloc(1, sizeof(struct bio))) +#define submit_bio(bio) do { } while (0) +#define bio_add_folio(bio, folio, len, off) \ + ({ (void)(bio); (void)(folio); (void)(len); (void)(off); 1; }) + +/* blk_status_to_errno - convert block status to errno */ +#define blk_status_to_errno(status) (-(status)) + +/* mapping_set_error - record error in address_space */ +#define mapping_set_error(m, e) do { (void)(m); (void)(e); } while (0) + +#endif /* __LINUX_BIO_H */