From: Simon Glass <simon.glass@canonical.com> Add stub headers for various Linux kernel interfaces that ext4 code expects: - sched.h: scheduler stubs (task_struct, cond_resched, yield) - wait.h: wait queue stubs - rwsem.h: read-write semaphore stubs - percpu_counter.h: percpu counter implementation (single-threaded) - random.h: random number stubs - quotaops.h: disk quota operation stubs - part_stat.h: partition statistics stubs - prefetch.h: prefetch operation stubs - sort.h: sort wrapper using stdlib qsort - swap.h: swap/memory management stubs Update compat.h to include new headers and remove duplicate definitions. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- include/linux/compat.h | 28 ++---------- include/linux/part_stat.h | 16 +++++++ include/linux/percpu_counter.h | 80 ++++++++++++++++++++++++++++++++++ include/linux/prefetch.h | 17 ++++++++ include/linux/quotaops.h | 38 ++++++++++++++++ include/linux/random.h | 15 +++++++ include/linux/rwsem.h | 28 ++++++++++++ include/linux/sched.h | 36 +++++++++++++++ include/linux/sort.h | 19 ++++++++ include/linux/swap.h | 18 ++++++++ include/linux/wait.h | 31 +++++++++++++ 11 files changed, 302 insertions(+), 24 deletions(-) create mode 100644 include/linux/part_stat.h create mode 100644 include/linux/percpu_counter.h create mode 100644 include/linux/prefetch.h create mode 100644 include/linux/quotaops.h create mode 100644 include/linux/random.h create mode 100644 include/linux/rwsem.h create mode 100644 include/linux/sched.h create mode 100644 include/linux/sort.h create mode 100644 include/linux/swap.h create mode 100644 include/linux/wait.h diff --git a/include/linux/compat.h b/include/linux/compat.h index 6892decf3ec..d5e4c3b4530 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -11,12 +11,16 @@ #include <linux/types.h> #include <linux/err.h> +#include <linux/cred.h> #include <linux/export.h> #include <linux/freezer.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/kthread.h> #include <linux/module.h> +#include <linux/random.h> +#include <linux/rwsem.h> +#include <linux/sched.h> #include <linux/slab.h> #include <linux/timer.h> #include <linux/uaccess.h> @@ -93,8 +97,6 @@ extern struct p_current *current; #define PAGE_SIZE 4096 #endif -/* drivers/char/random.c */ -#define get_random_bytes(...) /* include/linux/leds.h */ struct led_trigger {}; @@ -180,23 +182,9 @@ typedef int wait_queue_head_t; #define mutex_lock(...) #define mutex_unlock(...) -#define init_rwsem(...) do { } while (0) -#define down_read(...) do { } while (0) -#define down_write(...) do { } while (0) -#define down_write_trylock(...) 1 -#define up_read(...) do { } while (0) -#define up_write(...) do { } while (0) -#define cond_resched() do { } while (0) -#define yield() do { } while (0) - -struct rw_semaphore { int i; }; -#define down_write(...) do { } while (0) -#define up_write(...) do { } while (0) -#define down_read(...) do { } while (0) -#define up_read(...) do { } while (0) struct device { struct device *parent; struct class *class; @@ -217,15 +205,7 @@ struct cdev { #define cdev_add(...) 0 #define cdev_del(...) do { } while (0) -#define prandom_u32(...) 0 - -typedef struct { - uid_t val; -} kuid_t; -typedef struct { - gid_t val; -} kgid_t; /* from include/linux/types.h */ diff --git a/include/linux/part_stat.h b/include/linux/part_stat.h new file mode 100644 index 00000000000..8c998b99786 --- /dev/null +++ b/include/linux/part_stat.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Stub definitions for partition statistics. + * U-Boot doesn't track I/O statistics. + */ +#ifndef _LINUX_PART_STAT_H +#define _LINUX_PART_STAT_H + +#define STAT_READ 0 +#define STAT_WRITE 1 + +#define part_stat_read(bdev, field) 0 +#define part_stat_inc(bdev, field) do { } while (0) +#define part_stat_add(bdev, field, val) do { } while (0) + +#endif /* _LINUX_PART_STAT_H */ diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h new file mode 100644 index 00000000000..425648e6377 --- /dev/null +++ b/include/linux/percpu_counter.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * A simple "approximate counter" for use in ext2 and ext3 superblocks. + * + * WARNING: these things are HUGE. 4 kbytes per counter on 32-way P4. + * + * Stub definitions for percpu counters. + * U-Boot is single-threaded, use simple counters. + */ +#ifndef _LINUX_PERCPU_COUNTER_H +#define _LINUX_PERCPU_COUNTER_H + +#include <linux/types.h> + +struct percpu_counter { + s64 count; +}; + +static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount, + gfp_t gfp) +{ + fbc->count = amount; + return 0; +} + +static inline void percpu_counter_destroy(struct percpu_counter *fbc) +{ +} + +static inline void percpu_counter_set(struct percpu_counter *fbc, s64 amount) +{ + fbc->count = amount; +} + +static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount) +{ + fbc->count += amount; +} + +static inline void percpu_counter_sub(struct percpu_counter *fbc, s64 amount) +{ + fbc->count -= amount; +} + +static inline void percpu_counter_inc(struct percpu_counter *fbc) +{ + fbc->count++; +} + +static inline void percpu_counter_dec(struct percpu_counter *fbc) +{ + fbc->count--; +} + +static inline s64 percpu_counter_read(struct percpu_counter *fbc) +{ + return fbc->count; +} + +static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc) +{ + return fbc->count > 0 ? fbc->count : 0; +} + +static inline s64 percpu_counter_sum(struct percpu_counter *fbc) +{ + return fbc->count; +} + +static inline s64 percpu_counter_sum_positive(struct percpu_counter *fbc) +{ + return fbc->count > 0 ? fbc->count : 0; +} + +static inline bool percpu_counter_initialized(struct percpu_counter *fbc) +{ + return true; +} + +#endif /* _LINUX_PERCPU_COUNTER_H */ diff --git a/include/linux/prefetch.h b/include/linux/prefetch.h new file mode 100644 index 00000000000..4b9bbfbe7e9 --- /dev/null +++ b/include/linux/prefetch.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Generic cache management functions. Everything is arch-specific, + * but this header exists to make sure the defines/functions can be + * used in a generic way. + * + * 2000-11-13 Arjan van de Ven <arjan@fenrus.demon.nl> + * + * Stub definitions for prefetch operations. + */ +#ifndef _LINUX_PREFETCH_H +#define _LINUX_PREFETCH_H + +#define prefetch(x) do { } while (0) +#define prefetchw(x) do { } while (0) + +#endif /* _LINUX_PREFETCH_H */ diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h new file mode 100644 index 00000000000..04988ace843 --- /dev/null +++ b/include/linux/quotaops.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Definitions for diskquota-operations. When diskquota is configured these + * macros expand to the right source-code. + * + * Author: Marco van Wieringen <mvw@planets.elm.net> + * + * Stub definitions for quota operations. + * U-Boot doesn't support disk quotas. + */ +#ifndef _LINUX_QUOTAOPS_H +#define _LINUX_QUOTAOPS_H + +struct inode; +struct dentry; +struct kqid; + +#define dquot_initialize(inode) 0 +#define dquot_drop(inode) do { } while (0) +#define dquot_alloc_inode(inode) 0 +#define dquot_free_inode(inode) do { } while (0) +#define dquot_transfer(inode, attr) 0 +#define dquot_claim_space_nodirty(inode, nr) 0 +#define dquot_reclaim_space_nodirty(inode, nr) do { } while (0) +#define dquot_disable(sb, type, flags) 0 +#define dquot_suspend(sb, type) 0 +#define dquot_resume(sb, type) 0 +#define dquot_file_open(inode, file) 0 + +#define sb_has_quota_usage_enabled(sb, type) 0 +#define sb_has_quota_limits_enabled(sb, type) 0 +#define sb_has_quota_suspended(sb, type) 0 +#define sb_has_quota_loaded(sb, type) 0 +#define sb_has_quota_active(sb, type) 0 +#define sb_any_quota_loaded(sb) 0 +#define sb_any_quota_active(sb) 0 + +#endif /* _LINUX_QUOTAOPS_H */ diff --git a/include/linux/random.h b/include/linux/random.h new file mode 100644 index 00000000000..cb09c6c6b05 --- /dev/null +++ b/include/linux/random.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Stub definitions for random number generation. + */ +#ifndef _LINUX_RANDOM_H +#define _LINUX_RANDOM_H + +#include <linux/types.h> + +#define get_random_bytes(buf, len) do { } while (0) +#define prandom_u32() 0 +#define get_random_u32() 0 +#define get_random_u64() 0ULL + +#endif /* _LINUX_RANDOM_H */ diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h new file mode 100644 index 00000000000..ea70829d135 --- /dev/null +++ b/include/linux/rwsem.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* rwsem.h: R/W semaphores, public interface + * + * Written by David Howells (dhowells@redhat.com). + * Derived from asm-i386/semaphore.h + * + * Stub definitions for Linux kernel read-write semaphores. + * U-Boot is single-threaded, no locking needed. + */ +#ifndef _LINUX_RWSEM_H +#define _LINUX_RWSEM_H + +struct rw_semaphore { + int count; +}; + +#define DECLARE_RWSEM(name) struct rw_semaphore name = { 0 } + +#define init_rwsem(sem) do { } while (0) +#define down_read(sem) do { } while (0) +#define down_read_trylock(sem) 1 +#define up_read(sem) do { } while (0) +#define down_write(sem) do { } while (0) +#define down_write_trylock(sem) 1 +#define up_write(sem) do { } while (0) +#define downgrade_write(sem) do { } while (0) + +#endif /* _LINUX_RWSEM_H */ diff --git a/include/linux/sched.h b/include/linux/sched.h new file mode 100644 index 00000000000..e62a2a40c77 --- /dev/null +++ b/include/linux/sched.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Define 'struct task_struct' and provide the main scheduler + * APIs (schedule(), wakeup variants, etc.) + * + * Stub definitions for Linux kernel scheduler. + * U-Boot is single-threaded. + */ +#ifndef _LINUX_SCHED_H +#define _LINUX_SCHED_H + +#include <linux/types.h> + +struct task_struct { + int pid; + char comm[16]; +}; + +extern struct task_struct *current; + +#define TASK_RUNNING 0 +#define TASK_INTERRUPTIBLE 1 +#define TASK_UNINTERRUPTIBLE 2 + +#define cond_resched() do { } while (0) +#define yield() do { } while (0) +#define schedule() do { } while (0) + +#define in_interrupt() 0 +#define in_atomic() 0 +#define in_task() 1 + +#define signal_pending(task) 0 +#define fatal_signal_pending(task) 0 + +#endif /* _LINUX_SCHED_H */ diff --git a/include/linux/sort.h b/include/linux/sort.h new file mode 100644 index 00000000000..dc222d8dc89 --- /dev/null +++ b/include/linux/sort.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Sorting functions - use stdlib qsort. + */ +#ifndef _LINUX_SORT_H +#define _LINUX_SORT_H + +#include <linux/types.h> +#include <stdlib.h> + +typedef int (*cmp_func_t)(const void *, const void *); + +static inline void sort(void *base, size_t num, size_t size, + cmp_func_t cmp, void *swap) +{ + qsort(base, num, size, cmp); +} + +#endif /* _LINUX_SORT_H */ diff --git a/include/linux/swap.h b/include/linux/swap.h new file mode 100644 index 00000000000..1c714db6ae2 --- /dev/null +++ b/include/linux/swap.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Stub definitions for swap/memory management. + * U-Boot doesn't use swap. + */ +#ifndef _LINUX_SWAP_H +#define _LINUX_SWAP_H + +#define mark_page_accessed(page) do { } while (0) + +struct address_space; +struct folio; + +static inline void folio_mark_accessed(struct folio *folio) +{ +} + +#endif /* _LINUX_SWAP_H */ diff --git a/include/linux/wait.h b/include/linux/wait.h new file mode 100644 index 00000000000..1eb1263639e --- /dev/null +++ b/include/linux/wait.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Linux wait queue related types and methods + * + * Stub definitions for Linux kernel wait queues. + * U-Boot doesn't use wait queues. + */ +#ifndef _LINUX_WAIT_H +#define _LINUX_WAIT_H + +typedef int wait_queue_head_t; + +struct wait_queue_entry { + int dummy; +}; + +#define DECLARE_WAITQUEUE(name, task) struct wait_queue_entry name = { 0 } +#define DECLARE_WAIT_QUEUE_HEAD(name) wait_queue_head_t name = 0 + +#define init_waitqueue_head(wq) do { } while (0) +#define add_wait_queue(wq, entry) do { } while (0) +#define remove_wait_queue(wq, entry) do { } while (0) +#define wake_up(wq) do { } while (0) +#define wake_up_all(wq) do { } while (0) +#define wake_up_interruptible(wq) do { } while (0) +#define wake_up_interruptible_all(wq) do { } while (0) + +#define wait_event(wq, condition) do { } while (0) +#define wait_event_interruptible(wq, condition) 0 + +#endif /* _LINUX_WAIT_H */ -- 2.43.0