From: Grant Likely <grant.likely@secretlab.ca>
To: David Daney <ddaney@caviumnetworks.com>
Cc: linux-mips@linux-mips.org, ralf@linux-mips.org,
devicetree-discuss@lists.ozlabs.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2 02/12] of: Allow scripts/dtc/libfdt to be used from kernel code
Date: Fri, 4 Mar 2011 17:57:50 -0700 [thread overview]
Message-ID: <20110305005750.GC7579@angua.secretlab.ca> (raw)
In-Reply-To: <1299267744-17278-3-git-send-email-ddaney@caviumnetworks.com>
[cc'ing David Gibson]
On Fri, Mar 04, 2011 at 11:42:14AM -0800, David Daney wrote:
> Signed-off-by: David Daney <ddaney@caviumnetworks.com>
> ---
> include/linux/libfdt.h | 3 +++
> lib/Kconfig | 6 ++++++
> lib/Makefile | 2 ++
> lib/libfdt/Makefile | 7 +++++++
> lib/libfdt/libfdt_env.h | 21 +++++++++++++++++++++
> scripts/dtc/libfdt/libfdt.h | 4 ++--
> 6 files changed, 41 insertions(+), 2 deletions(-)
> create mode 100644 include/linux/libfdt.h
> create mode 100644 lib/libfdt/Makefile
> create mode 100644 lib/libfdt/libfdt_env.h
>
> diff --git a/include/linux/libfdt.h b/include/linux/libfdt.h
> new file mode 100644
> index 0000000..10bce91
> --- /dev/null
> +++ b/include/linux/libfdt.h
> @@ -0,0 +1,3 @@
> +#include "../../lib/libfdt/libfdt_env.h"
libfdt_env.h should be in include/linux
> +#include "../../scripts/dtc/libfdt/fdt.h"
> +#include "../../scripts/dtc/libfdt/libfdt.h"
Hmmm... I wonder if there is a better way to do this. I don't much
care for the relative path references.
Also, need to have #ifdef _INCLUDE_LIBFDT_H_ protection
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 0ee67e0..e8a2638 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -219,4 +219,10 @@ config LRU_CACHE
> config AVERAGE
> bool
>
> +#
> +# The Flattened Device Tree manipulation library
> +#
> +config LIBFDT
> + bool
> +
This should be in drivers/of/Kconfig
> endmenu
> diff --git a/lib/Makefile b/lib/Makefile
> index cbb774f..5840115 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -110,6 +110,8 @@ obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o
>
> obj-$(CONFIG_AVERAGE) += average.o
>
> +obj-$(CONFIG_LIBFDT) += libfdt/
> +
Ditto here; drivers/of/libfdt
> hostprogs-y := gen_crc32table
> clean-files := crc32table.h
>
> diff --git a/lib/libfdt/Makefile b/lib/libfdt/Makefile
> new file mode 100644
> index 0000000..6c1a496
> --- /dev/null
> +++ b/lib/libfdt/Makefile
> @@ -0,0 +1,7 @@
> +obj-y = fdt.o fdt_wip.o fdt_ro.o
> +
> +EXTRA_CFLAGS += -include $(src)/libfdt_env.h -I$(src)/../../scripts/dtc/libfdt
> +
> +$(obj)/%.o: $(src)/../../scripts/dtc/libfdt/%.c FORCE
> + $(call cmd,force_checksrc)
> + $(call if_changed_rule,cc_o_c)
> diff --git a/lib/libfdt/libfdt_env.h b/lib/libfdt/libfdt_env.h
> new file mode 100644
> index 0000000..d977b8b
> --- /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
> +
This isn't necessary, the kernel already has efficient architecture
macros for converting endianess.
#define fdt32_to_cpu(x) be32_to_cpu(x)
#define cpu_to_fdt32(x) cpu_to_be32(x)
#define fdt64_to_cpu(x) be64_to_cpu(x)
#define cpu_to_fdt64(x) cpu_to_be64(x)
> +#endif /* _LIBFDT_ENV_H */
> diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h
> index ce80e4f..33a0c4d 100644
> --- a/scripts/dtc/libfdt/libfdt.h
> +++ b/scripts/dtc/libfdt/libfdt.h
> @@ -51,8 +51,8 @@
> * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> */
>
> -#include <libfdt_env.h>
> -#include <fdt.h>
> +#include "libfdt_env.h"
> +#include "fdt.h"
This causes problems. libfdt is an external library that is
periodically copied into the kernel tree. It would be better to add
"-Iscripts/dtc/libfdt" to CFLAGS for .c files that want to call libfdt
routines.
>
> #define FDT_FIRST_SUPPORTED_VERSION 0x10
> #define FDT_LAST_SUPPORTED_VERSION 0x11
> --
> 1.7.2.3
>
WARNING: multiple messages have this Message-ID (diff)
From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: David Daney <ddaney-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org>
Cc: linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
ralf-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org
Subject: Re: [RFC PATCH v2 02/12] of: Allow scripts/dtc/libfdt to be used from kernel code
Date: Fri, 4 Mar 2011 17:57:50 -0700 [thread overview]
Message-ID: <20110305005750.GC7579@angua.secretlab.ca> (raw)
In-Reply-To: <1299267744-17278-3-git-send-email-ddaney-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org>
[cc'ing David Gibson]
On Fri, Mar 04, 2011 at 11:42:14AM -0800, David Daney wrote:
> Signed-off-by: David Daney <ddaney-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org>
> ---
> include/linux/libfdt.h | 3 +++
> lib/Kconfig | 6 ++++++
> lib/Makefile | 2 ++
> lib/libfdt/Makefile | 7 +++++++
> lib/libfdt/libfdt_env.h | 21 +++++++++++++++++++++
> scripts/dtc/libfdt/libfdt.h | 4 ++--
> 6 files changed, 41 insertions(+), 2 deletions(-)
> create mode 100644 include/linux/libfdt.h
> create mode 100644 lib/libfdt/Makefile
> create mode 100644 lib/libfdt/libfdt_env.h
>
> diff --git a/include/linux/libfdt.h b/include/linux/libfdt.h
> new file mode 100644
> index 0000000..10bce91
> --- /dev/null
> +++ b/include/linux/libfdt.h
> @@ -0,0 +1,3 @@
> +#include "../../lib/libfdt/libfdt_env.h"
libfdt_env.h should be in include/linux
> +#include "../../scripts/dtc/libfdt/fdt.h"
> +#include "../../scripts/dtc/libfdt/libfdt.h"
Hmmm... I wonder if there is a better way to do this. I don't much
care for the relative path references.
Also, need to have #ifdef _INCLUDE_LIBFDT_H_ protection
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 0ee67e0..e8a2638 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -219,4 +219,10 @@ config LRU_CACHE
> config AVERAGE
> bool
>
> +#
> +# The Flattened Device Tree manipulation library
> +#
> +config LIBFDT
> + bool
> +
This should be in drivers/of/Kconfig
> endmenu
> diff --git a/lib/Makefile b/lib/Makefile
> index cbb774f..5840115 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -110,6 +110,8 @@ obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o
>
> obj-$(CONFIG_AVERAGE) += average.o
>
> +obj-$(CONFIG_LIBFDT) += libfdt/
> +
Ditto here; drivers/of/libfdt
> hostprogs-y := gen_crc32table
> clean-files := crc32table.h
>
> diff --git a/lib/libfdt/Makefile b/lib/libfdt/Makefile
> new file mode 100644
> index 0000000..6c1a496
> --- /dev/null
> +++ b/lib/libfdt/Makefile
> @@ -0,0 +1,7 @@
> +obj-y = fdt.o fdt_wip.o fdt_ro.o
> +
> +EXTRA_CFLAGS += -include $(src)/libfdt_env.h -I$(src)/../../scripts/dtc/libfdt
> +
> +$(obj)/%.o: $(src)/../../scripts/dtc/libfdt/%.c FORCE
> + $(call cmd,force_checksrc)
> + $(call if_changed_rule,cc_o_c)
> diff --git a/lib/libfdt/libfdt_env.h b/lib/libfdt/libfdt_env.h
> new file mode 100644
> index 0000000..d977b8b
> --- /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
> +
This isn't necessary, the kernel already has efficient architecture
macros for converting endianess.
#define fdt32_to_cpu(x) be32_to_cpu(x)
#define cpu_to_fdt32(x) cpu_to_be32(x)
#define fdt64_to_cpu(x) be64_to_cpu(x)
#define cpu_to_fdt64(x) cpu_to_be64(x)
> +#endif /* _LIBFDT_ENV_H */
> diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h
> index ce80e4f..33a0c4d 100644
> --- a/scripts/dtc/libfdt/libfdt.h
> +++ b/scripts/dtc/libfdt/libfdt.h
> @@ -51,8 +51,8 @@
> * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> */
>
> -#include <libfdt_env.h>
> -#include <fdt.h>
> +#include "libfdt_env.h"
> +#include "fdt.h"
This causes problems. libfdt is an external library that is
periodically copied into the kernel tree. It would be better to add
"-Iscripts/dtc/libfdt" to CFLAGS for .c files that want to call libfdt
routines.
>
> #define FDT_FIRST_SUPPORTED_VERSION 0x10
> #define FDT_LAST_SUPPORTED_VERSION 0x11
> --
> 1.7.2.3
>
next prev parent reply other threads:[~2011-03-05 0:58 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-04 19:42 [RFC PATCH v2 00/12] MIPS: Octeon: Use Device Tree David Daney
2011-03-04 19:42 ` David Daney
2011-03-04 19:42 ` [RFC PATCH v2 01/12] MIPS: Octeon: Move some Ethernet support files out of staging David Daney
2011-03-04 19:42 ` [RFC PATCH v2 02/12] of: Allow scripts/dtc/libfdt to be used from kernel code David Daney
2011-03-05 0:57 ` Grant Likely [this message]
2011-03-05 0:57 ` Grant Likely
2011-03-05 0:59 ` Grant Likely
2011-03-05 0:59 ` Grant Likely
2011-03-05 22:04 ` Sam Ravnborg
2011-03-05 8:24 ` David Gibson
2011-03-05 8:24 ` David Gibson
2011-03-04 19:42 ` [RFC PATCH v2 03/12] of: Make of_find_node_by_path() traverse /aliases for relative paths David Daney
2011-03-04 19:42 ` David Daney
2011-03-04 21:55 ` Grant Likely
2011-03-04 19:42 ` [RFC PATCH v2 04/12] MIPS: Octeon: Add device tree source files David Daney
2011-03-04 19:42 ` David Daney
2011-03-05 1:15 ` Grant Likely
2011-03-05 1:15 ` Grant Likely
2011-03-04 19:42 ` [RFC PATCH v2 05/12] MIPS: Prune some target specific code out of prom.c David Daney
2011-03-04 19:42 ` David Daney
2011-03-04 19:42 ` [RFC PATCH v2 06/12] MIPS: Octeon: Add a irq_create_of_mapping() implementation David Daney
2011-03-04 19:42 ` David Daney
2011-03-05 1:07 ` Grant Likely
2011-03-11 18:27 ` David Daney
2011-03-04 19:42 ` [RFC PATCH v2 07/12] MIPS: Octeon: Rearrance CVMX files in preperation for device tree David Daney
2011-03-04 19:42 ` [RFC PATCH v2 08/12] MIPS: Octeon: Initialize and fixup " David Daney
2011-03-04 19:42 ` David Daney
2011-03-05 3:05 ` Grant Likely
2011-03-05 3:05 ` Grant Likely
[not found] ` <1299267744-17278-1-git-send-email-ddaney-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org>
2011-03-04 19:42 ` [RFC PATCH v2 09/12] i2c: Convert i2c-octeon.c to use " David Daney
2011-03-04 19:42 ` David Daney
2011-03-04 19:42 ` [RFC PATCH v2 10/12] netdev: mdio-octeon.c: Convert " David Daney
2011-03-04 19:42 ` David Daney
2011-03-04 21:10 ` David Miller
2011-03-04 19:42 ` [RFC PATCH v2 11/12] netdev: octeon_mgmt: " David Daney
2011-03-04 19:42 ` David Daney
2011-03-04 21:10 ` David Miller
2011-03-04 19:42 ` [RFC PATCH v2 12/12] staging: octeon_ethernet: " David Daney
2011-03-04 19:42 ` David Daney
2011-03-04 21:10 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110305005750.GC7579@angua.secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=ddaney@caviumnetworks.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.