mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] devicetree misc updates
@ 2013-05-20 14:14 Sascha Hauer
  2013-05-20 14:14 ` [PATCH 1/8] ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target Sascha Hauer
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

This contains some misc devicetree updates, most important the
patches running gcc -E on .dts files needed for importing recent
devicetree files from the kernel.

Sascha

----------------------------------------------------------------
Sascha Hauer (8):
      ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target
      ARM: build dtbs during build process using extra-y
      scripts: fixdep: update from v3.10-rc1
      kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp
      of: When checking for existing devices also check resource end
      of: Call of_add_memory from of_probe
      of: Add of_match_node function
      of: populate devices based on "simple-bus" property

 arch/arm/Makefile      |   5 --
 arch/arm/dts/Makefile  |   8 +-
 drivers/of/base.c      |  93 +++++++++++++++-------
 include/driver.h       |   2 +-
 include/of.h           |   3 +
 scripts/Makefile.lib   |  21 +++--
 scripts/basic/fixdep.c | 206 ++++++++++++++++++++++++++++++++-----------------
 7 files changed, 218 insertions(+), 120 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/8] ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  2013-05-20 14:14 ` [PATCH 2/8] ARM: build dtbs during build process using extra-y Sascha Hauer
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

Otherwise the intermediate *.dtb.S will be removed every build.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/dts/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 3ee8924..45a3304 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1,6 +1,8 @@
 
-BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME)).dtb.o
-obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB)
+BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
+obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
+
+.SECONDARY: $(obj)/$(BUILTIN_DTB).dtb.S
 
 targets += dtbs
 targets += $(dtb-y)
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/8] ARM: build dtbs during build process using extra-y
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
  2013-05-20 14:14 ` [PATCH 1/8] ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  2013-05-20 14:14 ` [PATCH 3/8] scripts: fixdep: update from v3.10-rc1 Sascha Hauer
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

When using a builtin dtb the builtin dtb is built twice, once
from as a dependency of the 'dtbs' target and once as a dependency
of the corresponding dtb.o target. This can happen in parallel
with parallel make which results in build corruption when two
processes try to generate the dtb at the same time. Typical errors
include:

fixdep: error opening depfile: arch/arm/dts/.imx51-babbage.dtb.d: No such file or directory
make[1]: *** [arch/arm/dts/imx51-babbage.dtb] Error 2

fixdep: arch/arm/dts/.imx51-babbage.dtb.d is empty
mv: cannot stat `arch/arm/dts/.imx51-babbage.dtb.tmp': No such file or directory
make[1]: *** [arch/arm/dts/imx51-babbage.dtb] Error 1

To fix this build the devicetree blobs using extra-y instead of
a separate target.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/Makefile     | 5 -----
 arch/arm/dts/Makefile | 2 +-
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index d506b12..5da0a8f 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -274,11 +274,6 @@ dts := arch/arm/dts
 %.dtb: scripts
 	$(Q)$(MAKE) $(build)=$(dts) $(dts)/$@
 
-dtbs: scripts
-	$(Q)$(MAKE) $(build)=$(dts) dtbs
-
-KBUILD_DTBS := dtbs
-
 KBUILD_IMAGE ?= $(KBUILD_BINARY)
 
 archprepare: maketools
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 45a3304..4569e3d 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -7,6 +7,6 @@ obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
 targets += dtbs
 targets += $(dtb-y)
 
-dtbs: $(addprefix $(obj)/, $(dtb-y))
+extra-y += $(dtb-y)
 
 clean-files := *.dtb *.dtb.S
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/8] scripts: fixdep: update from v3.10-rc1
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
  2013-05-20 14:14 ` [PATCH 1/8] ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target Sascha Hauer
  2013-05-20 14:14 ` [PATCH 2/8] ARM: build dtbs during build process using extra-y Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  2013-05-20 14:14 ` [PATCH 4/8] kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp Sascha Hauer
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

This brings us the following which we need for dtb file generation.

  commit 2ab8a99661f4ce052bbad064237c441371df8751
  Author: Stephen Warren <swarren@nvidia.com>
  Date:   Wed Mar 6 10:27:45 2013 -0700

      kbuild: fixdep: support concatenated dep files

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/basic/fixdep.c | 206 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 135 insertions(+), 71 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index ea26b23..078fe1d 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -138,38 +138,36 @@ static void print_cmdline(void)
 	printf("cmd_%s := %s\n\n", target, cmdline);
 }
 
-char * str_config  = NULL;
-int    size_config = 0;
-int    len_config  = 0;
+struct item {
+	struct item	*next;
+	unsigned int	len;
+	unsigned int	hash;
+	char		name[0];
+};
 
-/*
- * Grow the configuration string to a desired length.
- * Usually the first growth is plenty.
- */
-static void grow_config(int len)
-{
-	while (len_config + len > size_config) {
-		if (size_config == 0)
-			size_config = 2048;
-		str_config = realloc(str_config, size_config *= 2);
-		if (str_config == NULL)
-			{ perror("fixdep:malloc"); exit(1); }
-	}
-}
+#define HASHSZ 256
+static struct item *hashtab[HASHSZ];
 
+static unsigned int strhash(const char *str, unsigned int sz)
+{
+	/* fnv32 hash */
+	unsigned int i, hash = 2166136261U;
 
+	for (i = 0; i < sz; i++)
+		hash = (hash ^ str[i]) * 0x01000193;
+	return hash;
+}
 
 /*
  * Lookup a value in the configuration string.
  */
-static int is_defined_config(const char * name, int len)
+static int is_defined_config(const char *name, int len, unsigned int hash)
 {
-	const char * pconfig;
-	const char * plast = str_config + len_config - len;
-	for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) {
-		if (pconfig[ -1] == '\n'
-		&&  pconfig[len] == '\n'
-		&&  !memcmp(pconfig, name, len))
+	struct item *aux;
+
+	for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) {
+		if (aux->hash == hash && aux->len == len &&
+		    memcmp(aux->name, name, len) == 0)
 			return 1;
 	}
 	return 0;
@@ -178,13 +176,19 @@ static int is_defined_config(const char * name, int len)
 /*
  * Add a new value to the configuration string.
  */
-static void define_config(const char * name, int len)
+static void define_config(const char *name, int len, unsigned int hash)
 {
-	grow_config(len + 1);
+	struct item *aux = malloc(sizeof(*aux) + len);
 
-	memcpy(str_config+len_config, name, len);
-	len_config += len;
-	str_config[len_config++] = '\n';
+	if (!aux) {
+		perror("fixdep:malloc");
+		exit(1);
+	}
+	memcpy(aux->name, name, len);
+	aux->len = len;
+	aux->hash = hash;
+	aux->next = hashtab[hash % HASHSZ];
+	hashtab[hash % HASHSZ] = aux;
 }
 
 /*
@@ -192,40 +196,49 @@ static void define_config(const char * name, int len)
  */
 static void clear_config(void)
 {
-	len_config = 0;
-	define_config("", 0);
+	struct item *aux, *next;
+	unsigned int i;
+
+	for (i = 0; i < HASHSZ; i++) {
+		for (aux = hashtab[i]; aux; aux = next) {
+			next = aux->next;
+			free(aux);
+		}
+		hashtab[i] = NULL;
+	}
 }
 
 /*
  * Record the use of a CONFIG_* word.
  */
-static void use_config(char *m, int slen)
+static void use_config(const char *m, int slen)
 {
-	char s[PATH_MAX];
-	char *p;
+	unsigned int hash = strhash(m, slen);
+	int c, i;
 
-	if (is_defined_config(m, slen))
+	if (is_defined_config(m, slen, hash))
 	    return;
 
-	define_config(m, slen);
-
-	memcpy(s, m, slen); s[slen] = 0;
+	define_config(m, slen, hash);
 
-	for (p = s; p < s + slen; p++) {
-		if (*p == '_')
-			*p = '/';
+	printf("    $(wildcard include/config/");
+	for (i = 0; i < slen; i++) {
+		c = m[i];
+		if (c == '_')
+			c = '/';
 		else
-			*p = tolower((int)*p);
+			c = tolower(c);
+		putchar(c);
 	}
-	printf("    $(wildcard include/config/%s.h) \\\n", s);
+	printf(".h) \\\n");
 }
 
-static void parse_config_file(char *map, size_t len)
+static void parse_config_file(const char *map, size_t len)
 {
-	int *end = (int *) (map + len);
+	const int *end = (const int *) (map + len);
 	/* start at +1, so that p can never be < map */
-	int *m   = (int *) map + 1;
-	char *p, *q;
+	const int *m   = (const int *) map + 1;
+	const char *p, *q;
 
 	for (; m < end; m++) {
 		if (*m == INT_CONF) { p = (char *) m  ; goto conf; }
@@ -265,7 +278,7 @@ static int strrcmp(char *s, char *sub)
 	return memcmp(s + slen - sublen, sub, sublen);
 }
 
-static void do_config_file(char *filename)
+static void do_config_file(const char *filename)
 {
 	struct stat st;
 	int fd;
@@ -273,7 +286,7 @@ static void do_config_file(char *filename)
 
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
-		fprintf(stderr, "fixdep: ");
+		fprintf(stderr, "fixdep: error opening config file: ");
 		perror(filename);
 		exit(2);
 	}
@@ -296,42 +309,89 @@ static void do_config_file(char *filename)
 	close(fd);
 }
 
+/*
+ * Important: The below generated source_foo.o and deps_foo.o variable
+ * assignments are parsed not only by make, but also by the rather simple
+ * parser in scripts/mod/sumversion.c.
+ */
 static void parse_dep_file(void *map, size_t len)
 {
 	char *m = map;
 	char *end = m + len;
 	char *p;
 	char s[PATH_MAX];
-
-	p = strchr(m, ':');
-	if (!p) {
-		fprintf(stderr, "fixdep: parse error\n");
-		exit(1);
-	}
-	memcpy(s, m, p-m); s[p-m] = 0;
-	printf("deps_%s := \\\n", target);
-	m = p+1;
+	int is_target;
+	int saw_any_target = 0;
+	int is_first_dep = 0;
 
 	clear_config();
 
 	while (m < end) {
+		/* Skip any "white space" */
 		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
 			m++;
+		/* Find next "white space" */
 		p = m;
-		while (p < end && *p != ' ') p++;
-		if (p == end) {
-			do p--; while (!isalnum(*p));
+		while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
 			p++;
+		/* Is the token we found a target name? */
+		is_target = (*(p-1) == ':');
+		/* Don't write any target names into the dependency file */
+		if (is_target) {
+			/* The /next/ file is the first dependency */
+			is_first_dep = 1;
+		} else {
+			/* Save this token/filename */
+			memcpy(s, m, p-m);
+			s[p - m] = 0;
+
+			/* Ignore certain dependencies */
+			if (strrcmp(s, "include/generated/autoconf.h") &&
+			    strrcmp(s, "arch/um/include/uml-config.h") &&
+			    strrcmp(s, "include/linux/kconfig.h") &&
+			    strrcmp(s, ".ver")) {
+				/*
+				 * Do not list the source file as dependency,
+				 * so that kbuild is not confused if a .c file
+				 * is rewritten into .S or vice versa. Storing
+				 * it in source_* is needed for modpost to
+				 * compute srcversions.
+				 */
+				if (is_first_dep) {
+					/*
+					 * If processing the concatenation of
+					 * multiple dependency files, only
+					 * process the first target name, which
+					 * will be the original source name,
+					 * and ignore any other target names,
+					 * which will be intermediate temporary
+					 * files.
+					 */
+					if (!saw_any_target) {
+						saw_any_target = 1;
+						printf("source_%s := %s\n\n",
+							target, s);
+						printf("deps_%s := \\\n",
+							target);
+					}
+					is_first_dep = 0;
+				} else
+					printf("  %s \\\n", s);
+				do_config_file(s);
+			}
 		}
-		memcpy(s, m, p-m); s[p-m] = 0;
-		if (strrcmp(s, "include/generated/autoconf.h") &&
-		    strrcmp(s, "arch/um/include/uml-config.h") &&
-		    strrcmp(s, ".ver")) {
-			printf("  %s \\\n", s);
-			do_config_file(s);
-		}
+		/*
+		 * Start searching for next token immediately after the first
+		 * "whitespace" character that follows this token.
+		 */
 		m = p + 1;
 	}
+
+	if (!saw_any_target) {
+		fprintf(stderr, "fixdep: parse error; no targets found\n");
+		exit(1);
+	}
+
 	printf("\n%s: $(deps_%s)\n\n", target, target);
 	printf("$(deps_%s):\n", target);
 }
@@ -344,11 +404,15 @@ static void print_deps(void)
 
 	fd = open(depfile, O_RDONLY);
 	if (fd < 0) {
-		fprintf(stderr, "fixdep: ");
+		fprintf(stderr, "fixdep: error opening depfile: ");
 		perror(depfile);
 		exit(2);
 	}
-	fstat(fd, &st);
+	if (fstat(fd, &st) < 0) {
+                fprintf(stderr, "fixdep: error fstat'ing depfile: ");
+                perror(depfile);
+                exit(2);
+        }
 	if (st.st_size == 0) {
 		fprintf(stderr,"fixdep: %s is empty\n",depfile);
 		close(fd);
@@ -374,7 +438,7 @@ static void traps(void)
 	int *p = (int *)test;
 
 	if (*p != INT_CONF) {
-		fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
+		fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
 			*p);
 		exit(2);
 	}
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/8] kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-05-20 14:14 ` [PATCH 3/8] scripts: fixdep: update from v3.10-rc1 Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  2013-05-20 14:14 ` [PATCH 5/8] of: When checking for existing devices also check resource end Sascha Hauer
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

Based on the same Linux commit from Stephen Warren:

commit b40b25fff8205dd18124d8fc87b2c9c57f269b5f
Author: Stephen Warren <swarren@nvidia.com>
Date:   Wed Mar 6 10:58:37 2013 -0700

    kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp

    Replace cmd_dtc with cmd_dtc_cpp, and delete the latter.

    Previously, a special file extension (.dtsp) was required to trigger
    the C pre-processor to run on device tree files. This was ugly. Now that
    previous changes have enhanced cmd_dtc_cpp to collect dependency
    information from both gcc -E and dtc, we can transparently run the pre-
    processor on all device tree files, irrespective of whether they
    use /include/ or #include syntax to include *.dtsi.

    Signed-off-by: Stephen Warren <swarren@nvidia.com>
    Acked-by: Rob Herring <rob.herring@calxeda.com>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/Makefile.lib | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index bbfd4cd..c50bb4e 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -141,10 +141,10 @@ cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)
 
 ld_flags       = $(LDFLAGS) $(EXTRA_LDFLAGS)
 
-dtc_cpp_flags  = -Wp,-MD,$(depfile) -nostdinc		\
-      -I$(srctree)/arch/$(SRCARCH)/dts			\
-      -I$(srctree)/arch/$(SRCARCH)/include/dts		\
-      -undef -D__DTS__
+dtc_cpp_flags  = -Wp,-MD,$(depfile).pre -nostdinc                        \
+		 -I$(srctree)/arch/$(SRCARCH)/dts                        \
+		 -I$(srctree)/arch/$(SRCARCH)/dts/include                \
+		 -undef -D__DTS__
 
 # Finds the multi-part object the current object will be linked into
 modname-multi = $(sort $(foreach m,$(multi-used),\
@@ -212,20 +212,17 @@ $(obj)/%.dtb.S: $(obj)/%.dtb
 	$(call cmd,dt_S_dtb)
 
 quiet_cmd_dtc = DTC     $@
-cmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) -d $(depfile) $<
+cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
+	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
+		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
+		-d $(depfile).dtc $(dtc-tmp) ; \
+	cat $(depfile).pre $(depfile).dtc > $(depfile)
 
 $(obj)/%.dtb: $(src)/%.dts FORCE
 	$(call if_changed_dep,dtc)
 
 dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
 
-quiet_cmd_dtc_cpp = DTC+CPP $@
-cmd_dtc_cpp = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
-	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) $(dtc-tmp)
-
-$(obj)/%.dtb: $(src)/%.dtsp FORCE
-	$(call if_changed_dep,dtc_cpp)
-
 # Bzip2
 # ---------------------------------------------------------------------------
 
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/8] of: When checking for existing devices also check resource end
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-05-20 14:14 ` [PATCH 4/8] kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  2013-05-20 14:14 ` [PATCH 6/8] of: Call of_add_memory from of_probe Sascha Hauer
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

When registering devices from the devicetree we check if these
devices already exist. When doing this not only check the resource
start but also the resource end.
This helps with the probing of simple buses for which child nodes
often begin at the very same address as the parents.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 8383549..ef97a15 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -970,7 +970,8 @@ static int add_of_device_resource(struct device_node *node)
 	for_each_device(dev) {
 		if (!dev->resource)
 			continue;
-		if (dev->resource->start == address) {
+		if (dev->resource->start == res->start &&
+				dev->resource->end == res->end) {
 			debug("connecting %s to %s\n", node->name, dev_name(dev));
 			node->device = dev;
 			dev->device_node = node;
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/8] of: Call of_add_memory from of_probe
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
                   ` (4 preceding siblings ...)
  2013-05-20 14:14 ` [PATCH 5/8] of: When checking for existing devices also check resource end Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  2013-05-20 14:14 ` [PATCH 7/8] of: Add of_match_node function Sascha Hauer
  2013-05-20 14:14 ` [PATCH 8/8] of: populate devices based on "simple-bus" property Sascha Hauer
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

memory is always in /mem, so call of_add_memory from of_probe once
instead of in the recursive tree iteration. This makes it possible
to limit the device population to nodes with the "simple-bus" property
set.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ef97a15..c3395cf 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -923,10 +923,6 @@ static int add_of_device_resource(struct device_node *node)
 	int na, nc, n_resources;
 	int ret, len, index;
 
-	ret = of_add_memory(node, false);
-	if (ret != -ENXIO)
-		return ret;
-
 	reg = of_get_property(node, "reg", &len);
 	if (!reg)
 		return -EINVAL;
@@ -1070,6 +1066,8 @@ const char *of_get_model(void)
 
 int of_probe(void)
 {
+	struct device_node *memory;
+
 	if(!root_node)
 		return -ENODEV;
 
@@ -1079,6 +1077,10 @@ int of_probe(void)
 	__of_parse_phandles(root_node);
 	__of_probe(root_node);
 
+	memory = of_find_node_by_path(root_node, "/memory");
+	if (memory)
+		of_add_memory(memory, false);
+
 	return 0;
 }
 
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/8] of: Add of_match_node function
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
                   ` (5 preceding siblings ...)
  2013-05-20 14:14 ` [PATCH 6/8] of: Call of_add_memory from of_probe Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  2013-05-20 14:14 ` [PATCH 8/8] of: populate devices based on "simple-bus" property Sascha Hauer
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

To match a of_device_id arrays against a device_node. Same functionality
as in the kernel.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 35 +++++++++++++++++++++++++----------
 include/driver.h  |  2 +-
 include/of.h      |  3 +++
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index c3395cf..85d9dc0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -295,21 +295,36 @@ int of_device_is_compatible(const struct device_node *device,
 }
 EXPORT_SYMBOL(of_device_is_compatible);
 
+/**
+ * of_match_node - Tell if an device_node has a matching of_match structure
+ *      @matches:       array of of device match structures to search in
+ *      @node:          the of device structure to match against
+ *
+ *      Low level utility function used by device matching.
+ */
+const struct of_device_id *of_match_node(const struct of_device_id *matches,
+					 const struct device_node *node)
+{
+	while (matches->compatible) {
+		if (of_device_is_compatible(node, matches->compatible) == 1)
+			return matches;
+		matches++;
+	}
+
+	return NULL;
+}
+
 int of_match(struct device_d *dev, struct driver_d *drv)
 {
-	struct of_device_id *id;
+	const struct of_device_id *id;
 
-	id = drv->of_compatible;
+	id = of_match_node(drv->of_compatible, dev->device_node);
+	if (!id)
+		return 1;
 
-	while (id->compatible) {
-		if (of_device_is_compatible(dev->device_node, id->compatible) == 1) {
-			dev->of_id_entry = id;
-			return 0;
-		}
-		id++;
-	}
+	dev->of_id_entry = id;
 
-	return 1;
+	return 0;
 }
 EXPORT_SYMBOL(of_match);
 
diff --git a/include/driver.h b/include/driver.h
index 716f792..7d5f65e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -106,7 +106,7 @@ struct device_d {
 	struct platform_device_id *id_entry;
 	struct device_node *device_node;
 
-	struct of_device_id *of_id_entry;
+	const struct of_device_id *of_id_entry;
 };
 
 /** @brief Describes a driver present in the system */
diff --git a/include/of.h b/include/of.h
index 4dcf37e..3f64667 100644
--- a/include/of.h
+++ b/include/of.h
@@ -170,6 +170,9 @@ struct device_node *of_create_node(struct device_node *root, const char *path);
 struct device_node *of_get_root_node(void);
 int of_set_root_node(struct device_node *);
 
+const struct of_device_id *of_match_node(const struct of_device_id *matches,
+					 const struct device_node *node);
+
 struct cdev;
 
 #ifdef CONFIG_OFTREE
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 8/8] of: populate devices based on "simple-bus" property
  2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
                   ` (6 preceding siblings ...)
  2013-05-20 14:14 ` [PATCH 7/8] of: Add of_match_node function Sascha Hauer
@ 2013-05-20 14:14 ` Sascha Hauer
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2013-05-20 14:14 UTC (permalink / raw)
  To: barebox

We used to populate the devices from the devicetree based on the
presence of the 'reg' property. This is incorrect since this only
allows us to probe devices with resources.
Instead use the 'simple-bus' property to see if we have iterate
deeper. This also registers devices with their buses as parents.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 47 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85d9dc0..3b9cc65 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -825,13 +825,16 @@ static struct device_d *add_of_amba_device(struct device_node *node)
 	return &dev->dev;
 }
 
-static struct device_d *add_of_platform_device(struct device_node *node)
+static struct device_d *add_of_platform_device(struct device_node *node,
+		struct device_d *parent)
 {
 	struct device_d *dev;
 	char *name, *at;
 
 	dev = xzalloc(sizeof(*dev));
 
+	dev->parent = parent;
+
 	name = xstrdup(node->name);
 	at = strchr(name, '@');
 	if (at) {
@@ -856,7 +859,8 @@ static struct device_d *add_of_platform_device(struct device_node *node)
 	return dev;
 }
 
-static struct device_d *add_of_device(struct device_node *node)
+static struct device_d *add_of_device(struct device_node *node,
+		struct device_d *parent)
 {
 	const struct property *cp;
 
@@ -871,7 +875,7 @@ static struct device_d *add_of_device(struct device_node *node)
 	    of_device_is_compatible(node, "arm,primecell") == 1)
 		return add_of_amba_device(node);
 	else
-		return add_of_platform_device(node);
+		return add_of_platform_device(node, parent);
 }
 EXPORT_SYMBOL(add_of_device);
 
@@ -928,7 +932,8 @@ int of_add_memory(struct device_node *node, bool dump)
 	return 0;
 }
 
-static int add_of_device_resource(struct device_node *node)
+static struct device_d *add_of_device_resource(struct device_node *node,
+		struct device_d *parent)
 {
 	u64 address = 0, size;
 	struct resource *res, *resp;
@@ -940,7 +945,7 @@ static int add_of_device_resource(struct device_node *node)
 
 	reg = of_get_property(node, "reg", &len);
 	if (!reg)
-		return -EINVAL;
+		return add_of_device(node, parent);
 
 	of_bus_count_cells(node, &na, &nc);
 
@@ -995,14 +1000,12 @@ static int add_of_device_resource(struct device_node *node)
 	node->resource = res;
 	node->num_resource = n_resources;
 
-	add_of_device(node);
-
-	return 0;
+	return add_of_device(node, parent);
 
 err_free:
 	free(res);
 
-	return ret;
+	return NULL;
 }
 
 void of_free(struct device_node *node)
@@ -1042,17 +1045,23 @@ void of_free(struct device_node *node)
 		of_set_root_node(NULL);
 }
 
-static void __of_probe(struct device_node *node)
+static void __of_probe(struct device_node *node,
+		const struct of_device_id *matches,
+		struct device_d *parent)
 {
 	struct device_node *n;
+	struct device_d *dev;
 
 	if (node->device)
 		return;
 
-	add_of_device_resource(node);
+	dev = add_of_device_resource(node, parent);
+
+	if (!of_match_node(matches, node))
+		return;
 
 	list_for_each_entry(n, &node->children, parent_list)
-		__of_probe(n);
+		__of_probe(n, matches, dev);
 }
 
 static void __of_parse_phandles(struct device_node *node)
@@ -1079,9 +1088,17 @@ const char *of_get_model(void)
 	return of_model;
 }
 
+const struct of_device_id of_default_bus_match_table[] = {
+	{
+		.compatible = "simple-bus",
+	}, {
+		/* sentinel */
+	}
+};
+
 int of_probe(void)
 {
-	struct device_node *memory;
+	struct device_node *memory, *n;
 
 	if(!root_node)
 		return -ENODEV;
@@ -1090,12 +1107,14 @@ int of_probe(void)
 	of_property_read_string(root_node, "model", &of_model);
 
 	__of_parse_phandles(root_node);
-	__of_probe(root_node);
 
 	memory = of_find_node_by_path(root_node, "/memory");
 	if (memory)
 		of_add_memory(memory, false);
 
+	list_for_each_entry(n, &root_node->children, parent_list)
+		__of_probe(n, of_default_bus_match_table, NULL);
+
 	return 0;
 }
 
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-20 14:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
2013-05-20 14:14 ` [PATCH 1/8] ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target Sascha Hauer
2013-05-20 14:14 ` [PATCH 2/8] ARM: build dtbs during build process using extra-y Sascha Hauer
2013-05-20 14:14 ` [PATCH 3/8] scripts: fixdep: update from v3.10-rc1 Sascha Hauer
2013-05-20 14:14 ` [PATCH 4/8] kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp Sascha Hauer
2013-05-20 14:14 ` [PATCH 5/8] of: When checking for existing devices also check resource end Sascha Hauer
2013-05-20 14:14 ` [PATCH 6/8] of: Call of_add_memory from of_probe Sascha Hauer
2013-05-20 14:14 ` [PATCH 7/8] of: Add of_match_node function Sascha Hauer
2013-05-20 14:14 ` [PATCH 8/8] of: populate devices based on "simple-bus" property Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox