All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path
@ 2015-07-29  7:39 Andrew Jones
  2015-07-29  7:39 ` [kvm-unit-tests PATCH v2 1/2] devicetree: add /chosen/stdout-path support Andrew Jones
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Jones @ 2015-07-29  7:39 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini

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(-)

-- 
2.4.3


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

* [kvm-unit-tests PATCH v2 1/2] devicetree: add /chosen/stdout-path support
  2015-07-29  7:39 [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path Andrew Jones
@ 2015-07-29  7:39 ` Andrew Jones
  2015-07-29  7:39 ` [kvm-unit-tests PATCH v2 2/2] arm/arm64: uart0_init: check /chosen/stdout-path Andrew Jones
  2015-07-29 13:55 ` [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2015-07-29  7:39 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/devicetree.c | 19 +++++++++++++++++++
 lib/devicetree.h |  9 +++++++++
 2 files changed, 28 insertions(+)

diff --git a/lib/devicetree.c b/lib/devicetree.c
index 0f9b4e9942736..36cb28610ff41 100644
--- a/lib/devicetree.c
+++ b/lib/devicetree.c
@@ -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;
diff --git a/lib/devicetree.h b/lib/devicetree.h
index 7fddc2464de8a..c8c86eeae28b6 100644
--- a/lib/devicetree.h
+++ b/lib/devicetree.h
@@ -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
-- 
2.4.3


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

* [kvm-unit-tests PATCH v2 2/2] arm/arm64: uart0_init: check /chosen/stdout-path
  2015-07-29  7:39 [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path Andrew Jones
  2015-07-29  7:39 ` [kvm-unit-tests PATCH v2 1/2] devicetree: add /chosen/stdout-path support Andrew Jones
@ 2015-07-29  7:39 ` Andrew Jones
  2015-07-29 13:55 ` [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2015-07-29  7:39 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini

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.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/io.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/lib/arm/io.c b/lib/arm/io.c
index 8b1501886736a..a08d394e4aa1c 100644
--- a/lib/arm/io.c
+++ b/lib/arm/io.c
@@ -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)
-- 
2.4.3


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

* Re: [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path
  2015-07-29  7:39 [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path Andrew Jones
  2015-07-29  7:39 ` [kvm-unit-tests PATCH v2 1/2] devicetree: add /chosen/stdout-path support Andrew Jones
  2015-07-29  7:39 ` [kvm-unit-tests PATCH v2 2/2] arm/arm64: uart0_init: check /chosen/stdout-path Andrew Jones
@ 2015-07-29 13:55 ` Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2015-07-29 13:55 UTC (permalink / raw)
  To: Andrew Jones, kvm



On 29/07/2015 09:39, Andrew Jones wrote:
> 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(-)
> 

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

Paolo

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

end of thread, other threads:[~2015-07-29 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-29  7:39 [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path Andrew Jones
2015-07-29  7:39 ` [kvm-unit-tests PATCH v2 1/2] devicetree: add /chosen/stdout-path support Andrew Jones
2015-07-29  7:39 ` [kvm-unit-tests PATCH v2 2/2] arm/arm64: uart0_init: check /chosen/stdout-path Andrew Jones
2015-07-29 13:55 ` [kvm-unit-tests PATCH v2 0/2] lib: devicetree: add stdout-path Paolo Bonzini

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.