Thread (25 messages) 25 messages, 5 authors, 2011-03-11

Re: [RFC PATCH v2 02/12] of: Allow scripts/dtc/libfdt to be used from kernel code

From: David Gibson <hidden>
Date: 2011-03-05 08:30:05
Also in: linux-mips, lkml

On Fri, Mar 04, 2011 at 11:42:14AM -0800, David Daney wrote:
Signed-off-by: David Daney <redacted>
[snip]
quoted hunk ↗ jump to hunk
--- /dev/null
+++ b/lib/libfdt/libfdt_env.h
@@ -0,0 +1,21 @@
+#ifndef _LIBFDT_ENV_H
+#define _LIBFDT_ENV_H
+
+#include <linux/string.h>
+
+#define _B(n)	((unsigned long long)((uint8_t *)&x)[n])
+static inline uint32_t fdt32_to_cpu(uint32_t x)
+{
+	return (_B(0) << 24) | (_B(1) << 16) | (_B(2) << 8) | _B(3);
+}
+#define cpu_to_fdt32(x) fdt32_to_cpu(x)
+
+static inline uint64_t fdt64_to_cpu(uint64_t x)
+{
+	return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32)
+		| (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7);
+}
+#define cpu_to_fdt64(x) fdt64_to_cpu(x)
+#undef _B
Ah, yuck.  I only used those nasty macros in the userspace version of
libfdt_env.h because bytesex.h is such a portability nightmare.  The
kernel already has cpu_to_be{32,64}(), and the fdt byteswapping
functions should just be aliased to them.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help