[Concept,11/19] linux: Add smp.h header with SMP stubs

Message ID 20260117011448.3007171-12-sjg@u-boot.org
State New
Headers
Series ext4l: Reduce ext4_uboot.h size by moving code to include/linux |

Commit Message

Simon Glass Jan. 17, 2026, 1:14 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move SMP-related stubs to a dedicated header file that mirrors the
Linux kernel organisation.

smp.h provides:
- raw_smp_processor_id() and smp_processor_id() - always return 0
- smp_rmb(), smp_wmb(), smp_mb() - memory barriers (no-ops)
- smp_mb__after_atomic() - post-atomic memory barrier (no-op)

These are all stubs since U-Boot is single-threaded.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/ext4_uboot.h | 13 +++-------
 include/linux/smp.h   | 60 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 9 deletions(-)
 create mode 100644 include/linux/smp.h
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index f26006f9291..57d967965da 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -88,13 +88,11 @@ 
 #include <linux/fs_parser.h>
 #include <linux/dcache.h>
 #include <linux/uuid.h>
+#include <linux/smp.h>
 
 /* atomic_dec_if_positive, atomic_add_unless, etc. are now in asm-generic/atomic.h */
-
-/* SMP stubs - U-Boot is single-threaded */
-#define raw_smp_processor_id()	0
-
 /* cmpxchg is now in asm-generic/atomic.h */
+/* SMP stubs (raw_smp_processor_id, smp_*mb) are now in linux/smp.h */
 
 /* Reference count type */
 typedef struct { atomic_t refs; } refcount_t;
@@ -255,10 +253,7 @@  struct buffer_head *sb_getblk(struct super_block *sb, sector_t block);
 /* inode_needs_sync - stub */
 #define inode_needs_sync(inode)		(0)
 
-/* Memory barriers - stubs for single-threaded */
-#define smp_rmb()	do { } while (0)
-#define smp_wmb()	do { } while (0)
-#define smp_mb()	do { } while (0)
+/* Memory barriers are now in linux/smp.h */
 
 /*
  * set_bit/clear_bit are declared extern in asm/bitops.h but not implemented.
@@ -1897,7 +1892,7 @@  struct wait_bit_entry {
 
 /* JBD2 commit.c stubs (folio_trylock is in linux/pagemap.h) */
 #define clear_bit_unlock(nr, addr)	clear_bit(nr, addr)
-#define smp_mb__after_atomic()		do { } while (0)
+/* smp_mb__after_atomic is now in linux/smp.h */
 #define ktime_get_coarse_real_ts64(ts)	do { (ts)->tv_sec = 0; (ts)->tv_nsec = 0; } while (0)
 #define filemap_fdatawait_range_keep_errors(m, s, e) \
 	({ (void)(m); (void)(s); (void)(e); 0; })
diff --git a/include/linux/smp.h b/include/linux/smp.h
new file mode 100644
index 00000000000..15fb7fa656f
--- /dev/null
+++ b/include/linux/smp.h
@@ -0,0 +1,60 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SMP stubs for U-Boot
+ *
+ * U-Boot is single-threaded, so all SMP operations are stubs.
+ */
+#ifndef _LINUX_SMP_H
+#define _LINUX_SMP_H
+
+#include <linux/types.h>
+
+/**
+ * raw_smp_processor_id() - get current processor ID
+ *
+ * U-Boot stub - always returns 0 (single CPU).
+ */
+#define raw_smp_processor_id()	0
+
+/**
+ * smp_processor_id() - get current processor ID
+ *
+ * U-Boot stub - always returns 0 (single CPU).
+ */
+#define smp_processor_id()	0
+
+/* Memory barriers - stubs for single-threaded U-Boot */
+
+/**
+ * smp_rmb() - read memory barrier
+ *
+ * Ensures that all reads before this point are completed before
+ * any reads after this point. No-op in single-threaded U-Boot.
+ */
+#define smp_rmb()		do { } while (0)
+
+/**
+ * smp_wmb() - write memory barrier
+ *
+ * Ensures that all writes before this point are completed before
+ * any writes after this point. No-op in single-threaded U-Boot.
+ */
+#define smp_wmb()		do { } while (0)
+
+/**
+ * smp_mb() - full memory barrier
+ *
+ * Ensures that all memory operations before this point are completed
+ * before any memory operations after this point. No-op in single-threaded
+ * U-Boot.
+ */
+#define smp_mb()		do { } while (0)
+
+/**
+ * smp_mb__after_atomic() - memory barrier after atomic operation
+ *
+ * No-op in single-threaded U-Boot.
+ */
+#define smp_mb__after_atomic()	do { } while (0)
+
+#endif /* _LINUX_SMP_H */