[PATCH v9 2/5] include/linux_scaffold: add FIELD_GET() bitfield helper

Xin Wang
2025-12-31T05:55:32Z

Add __bf_shf() and FIELD_GET() so code can extract bitfields from
registers using a mask, matching the common Linux FIELD_GET()
semantics without pulling in kernel headers.

Signed-off-by: Xin Wang <x.wang@intel.com>
---
include/linux_scaffold.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux_scaffold.h b/include/linux_scaffold.h
index f6620ad0a..bd69c1ed2 100644
--- a/include/linux_scaffold.h
+++ b/include/linux_scaffold.h
@@ -51,4 +51,9 @@ static inline s64 sign_extend64(u64 value, int index)
#define BITS_PER_LONG BITS_PER_TYPE(long)
#define BITS_PER_LONG_LONG BITS_PER_TYPE(long long)

+#define __bf_shf(x) (__builtin_ffsll(x) - 1)
+
+#define FIELD_GET(mask, reg) \
+ (typeof(mask))(((reg) & (mask)) >> __bf_shf(mask))
+
#endif /* _INTEL_GPU_COMMANDS_SCAFFOLD_H_ */
--
2.43.0