Skip to contentSkip to conversation

lib: devicetree: add stdout-path

PATCH In review Andrew Jones 2 participants 4 messages Jul 29, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover lib: devicetree: add stdout-path

Easy addition to the devicetree support that may come in handy for powerpc (and it may not - I have a ppc series ready to post that doesn't actually bother with stdout-path yet, but whatever...)

For v2 I decided it's better to return -FDT_ERR_BADPATH from dt_get_default_console_node, if there's a bad path. Also, shortened an overly long name in lib/arm/io.c

Andrew Jones (2):
devicetree: add /chosen/stdout-path support arm/arm64: uart0_init: check /chosen/stdout-path

 lib/arm/io.c     | 36 +++++++++++++++++++++++++++---------
 lib/devicetree.c | 19 +++++++++++++++++++
 lib/devicetree.h |  9 +++++++++
 3 files changed, 55 insertions(+), 9 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/2 devicetree: add /chosen/stdout-path support

---
 lib/devicetree.c | 19 +++++++++++++++++++
 lib/devicetree.h |  9 +++++++++
 2 files changed, 28 insertions(+)
lib/devicetree.c +19 -0
index 0f9b4e9942736..36cb28610ff41 100644
@@ -246,6 +246,25 @@ int dt_get_bootargs(const char **bootargs)
 	return 0;
 }
 
+int dt_get_default_console_node(void)
+{
+	const struct fdt_property *prop;
+	int node, len;
+
+	node = fdt_path_offset(fdt, "/chosen");
+	if (node < 0)
+		return node;
+
+	prop = fdt_get_property(fdt, node, "stdout-path", &len);
+	if (!prop) {
+		prop = fdt_get_property(fdt, node, "linux,stdout-path", &len);
+		if (!prop)
+			return len;
+	}
+
+	return fdt_path_offset(fdt, prop->data);
+}
+
 int dt_init(const void *fdt_ptr)
 {
 	struct dt_bus *defbus = (struct dt_bus *)&dt_default_bus;
lib/devicetree.h +9 -0
index 7fddc2464de8a..c8c86eeae28b6 100644
@@ -215,6 +215,15 @@ extern int dt_get_reg(int fdtnode, int regidx, struct dt_reg *reg);
 extern int dt_get_bootargs(const char **bootargs);
 
 /*
+ * dt_get_default_console_node gets the node of the path stored in
+ * /chosen/stdout-path (or the deprecated /chosen/linux,stdout-path)
+ * returns
+ *  - the node (>= 0) on success
+ *  - a negative FDT_ERR_* value on failure
+ */
+extern int dt_get_default_console_node(void);
+
+/*
  * dt_get_memory_params gets the memory parameters from the /memory node(s)
  * storing each memory region ("address size" tuple) in consecutive entries
  * of @regs, up to @nr_regs
Signature · 1 line
2.4.3
#2 lore raw

PATCH v2 2/2 arm/arm64: uart0_init: check /chosen/stdout-path

In reply to Andrew Jones

Arguably all of uart0_init() is unnecessary, as we're pretty sure that the address we initialize uart0_base to is correct. We go through the motions of finding the uart anyway though, because it's easy. It's also easy to check chosen/stdout-path first, so let's do that too. But, just to make all this stuff a little less unnecessary, let's add a warning when we do actually find an address that doesn't match our initializer.

---
 lib/arm/io.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)
lib/arm/io.c +27 -9
index 8b1501886736a..a08d394e4aa1c 100644
@@ -19,12 +19,14 @@ extern void halt(int code);
 /*
  * Use this guess for the pl011 base in order to make an attempt at
  * having earlier printf support. We'll overwrite it with the real
- * base address that we read from the device tree later.
+ * base address that we read from the device tree later. This is
+ * the address we expect QEMU's mach-virt machine type to put in
+ * its generated device tree.
  */
-#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL
+#define UART_EARLY_BASE 0x09000000UL
 
 static struct spinlock uart_lock;
-static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_BASE;
+static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE;
 
 static void uart0_init(void)
 {
@@ -32,16 +34,32 @@ static void uart0_init(void)
 	struct dt_pbus_reg base;
 	int ret;
 
-	ret = dt_pbus_get_base_compatible(compatible, &base);
-	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	ret = dt_get_default_console_node();
+	assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND);
 
-	if (ret) {
-		printf("%s: %s not found in the device tree, aborting...\n",
-			__func__, compatible);
-		abort();
+	if (ret == -FDT_ERR_NOTFOUND) {
+
+		ret = dt_pbus_get_base_compatible(compatible, &base);
+		assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+
+		if (ret) {
+			printf("%s: %s not found in the device tree, "
+				"aborting...\n",
+				__func__, compatible);
+			abort();
+		}
+
+	} else {
+		assert(dt_pbus_translate_node(ret, 0, &base) == 0);
 	}
 
 	uart0_base = ioremap(base.addr, base.size);
+
+	if (uart0_base != (u8 *)UART_EARLY_BASE) {
+		printf("WARNING: early print support may not work. "
+		       "Found uart at %p, but early base is %p.\n",
+			uart0_base, (u8 *)UART_EARLY_BASE);
+	}
 }
 
 void io_init(void)
Signature · 1 line
2.4.3
maintainer
#3 lore raw
In reply to Andrew Jones
Quoted 8 lines · Andrew Jones

Easy addition to the devicetree support that may come in handy for powerpc (and it may not - I have a ppc series ready to post that doesn't actually bother with stdout-path yet, but whatever...)

For v2 I decided it's better to return -FDT_ERR_BADPATH from dt_get_default_console_node, if there's a bad path. Also, shortened an overly long name in lib/arm/io.c

Quoted 9 lines

Andrew Jones (2):
devicetree: add /chosen/stdout-path support arm/arm64: uart0_init: check /chosen/stdout-path

 lib/arm/io.c     | 36 +++++++++++++++++++++++++++---------
 lib/devicetree.c | 19 +++++++++++++++++++
 lib/devicetree.h |  9 +++++++++
 3 files changed, 55 insertions(+), 9 deletions(-)

Looks good. I haven't yet tested it, but I plan on applying it as soon
as I do.

Paolo