[Skiboot] [PATCH 03/14] console: add helper to create serial console nodes

Oliver O'Halloran oohall at gmail.com
Fri Nov 18 16:01:41 AEDT 2016


The creation of /ibm,skiboot/console/serial@<xyz> nodes is pretty much
identical across the various OPAL console drivers. This patch moves it
into a helper function as a cleanup.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/console.c       | 44 +++++++++++++++++++++++++++++++-------------
 hw/fsp/fsp-console.c | 28 ++++++++++------------------
 hw/lpc-uart.c        | 16 ++--------------
 include/console.h    |  3 +++
 4 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/core/console.c b/core/console.c
index 20de285f5104..bb8a8b4bbe8f 100644
--- a/core/console.c
+++ b/core/console.c
@@ -61,7 +61,6 @@ void force_dummy_console(void)
 						NULL, 0);
 }
 
-
 static int mambo_char = -1;
 
 static bool mambo_con_poll_read(void)
@@ -103,6 +102,36 @@ void enable_mambo_console(void)
 	set_console(&mambo_con_driver);
 }
 
+/*
+ * Helper function for adding /ibm,opal/consoles/serial@<xyz> nodes
+ */
+struct dt_node *add_opal_console_node(int index, const char *type,
+	uint32_t write_buffer_size)
+{
+	struct dt_node *con, *consoles;
+	char buffer[32];
+
+	consoles = dt_find_by_name(opal_node, "consoles");
+	if (!consoles) {
+		consoles = dt_new(opal_node, "consoles");
+		assert(consoles);
+		dt_add_property_cells(consoles, "#address-cells", 1);
+		dt_add_property_cells(consoles, "#size-cells", 0);
+	}
+
+	con = dt_new_addr(consoles, "serial", index);
+	assert(con);
+
+	snprintf(buffer, sizeof(buffer), "ibm,opal-console-%s", type);
+	dt_add_property_string(con, "compatible", buffer);
+
+	dt_add_property_cells(con, "#write-buffer-size", write_buffer_size);
+	dt_add_property_cells(con, "reg", index);
+	dt_add_property_string(con, "device_type", "serial");
+
+	return con;
+}
+
 void clear_console(void)
 {
 	memset(con_buf, 0, INMEM_CON_LEN);
@@ -399,20 +428,9 @@ static void dummy_console_poll(void *data __unused)
 
 void dummy_console_add_nodes(void)
 {
-	struct dt_node *con, *consoles;
 	struct dt_property *p;
 
-	consoles = dt_new(opal_node, "consoles");
-	assert(consoles);
-	dt_add_property_cells(consoles, "#address-cells", 1);
-	dt_add_property_cells(consoles, "#size-cells", 0);
-
-	con = dt_new_addr(consoles, "serial", 0);
-	assert(con);
-	dt_add_property_string(con, "compatible", "ibm,opal-console-raw");
-	dt_add_property_cells(con, "#write-buffer-size", INMEM_CON_OUT_LEN);
-	dt_add_property_cells(con, "reg", 0);
-	dt_add_property_string(con, "device_type", "serial");
+	add_opal_console_node(0, "raw", memcons.obuf_size);
 
 	/* Mambo might have left a crap one, clear it */
 	p = __dt_find_property(dt_chosen, "linux,stdout-path");
diff --git a/hw/fsp/fsp-console.c b/hw/fsp/fsp-console.c
index 46ac28bbd822..8a88f2876aa8 100644
--- a/hw/fsp/fsp-console.c
+++ b/hw/fsp/fsp-console.c
@@ -917,40 +917,32 @@ void fsp_console_reset(void)
 
 void fsp_console_add_nodes(void)
 {
+	struct dt_node *opal_event;
 	unsigned int i;
-	struct dt_node *consoles, *opal_event;
 
-	consoles = dt_new(opal_node, "consoles");
-	dt_add_property_cells(consoles, "#address-cells", 1);
-	dt_add_property_cells(consoles, "#size-cells", 0);
+	opal_event = dt_find_by_name(opal_node, "event");
+
 	for (i = 0; i < MAX_SERIAL; i++) {
 		struct fsp_serial *fs = &fsp_serials[i];
 		struct dt_node *fs_node;
-		char name[32];
+		const char *type;
 
 		if (fs->log_port || !fs->available)
 			continue;
 
-		snprintf(name, sizeof(name), "serial@%d", i);
-		fs_node = dt_new(consoles, name);
 		if (fs->rsrc_id == 0xffff)
-			dt_add_property_string(fs_node, "compatible",
-					       "ibm,opal-console-raw");
+			type = "raw";
 		else
-			dt_add_property_string(fs_node, "compatible",
-					       "ibm,opal-console-hvsi");
-		dt_add_property_cells(fs_node,
-				     "#write-buffer-size", SER_BUF_DATA_SIZE);
-		dt_add_property_cells(fs_node, "reg", i);
-		dt_add_property_string(fs_node, "device_type", "serial");
+			type = "hvsi";
+
+		fs_node = add_opal_console_node(i, type, SER_BUF_DATA_SIZE);
 
 		fs->irq = opal_dynamic_event_alloc();
 		dt_add_property_cells(fs_node, "interrupts", ilog2(fs->irq));
 
-		opal_event = dt_find_by_name(opal_node, "event");
 		if (opal_event)
-			dt_add_property_cells(fs_node, "interrupt-parent",
-					      opal_event->phandle);
+			dt_add_property_cells(fs_node,
+				"interrupt-parent", opal_event->phandle);
 	}
 }
 
diff --git a/hw/lpc-uart.c b/hw/lpc-uart.c
index 66932652608e..f91bccf7c716 100644
--- a/hw/lpc-uart.c
+++ b/hw/lpc-uart.c
@@ -420,20 +420,8 @@ void uart_setup_linux_passthrough(void)
 
 void uart_setup_opal_console(void)
 {
-	struct dt_node *con, *consoles;
-
-	/* Create OPAL console node */
-	consoles = dt_new(opal_node, "consoles");
-	assert(consoles);
-	dt_add_property_cells(consoles, "#address-cells", 1);
-	dt_add_property_cells(consoles, "#size-cells", 0);
-
-	con = dt_new_addr(consoles, "serial", 0);
-	assert(con);
-	dt_add_property_string(con, "compatible", "ibm,opal-console-raw");
-	dt_add_property_cells(con, "#write-buffer-size", INMEM_CON_OUT_LEN);
-	dt_add_property_cells(con, "reg", 0);
-	dt_add_property_string(con, "device_type", "serial");
+	/* Add the opal console node */
+	add_opal_console_node(0, "raw", INMEM_CON_OUT_LEN);
 
 	dt_add_property_string(dt_chosen, "linux,stdout-path",
 			       "/ibm,opal/consoles/serial at 0");
diff --git a/include/console.h b/include/console.h
index 4c77433421f6..6a80bef96c7a 100644
--- a/include/console.h
+++ b/include/console.h
@@ -71,4 +71,7 @@ extern void clear_console(void);
 extern void memcons_add_properties(void);
 extern void dummy_console_add_nodes(void);
 
+struct dt_node *add_opal_console_node(int index, const char *type,
+	uint32_t write_buffer_size);
+
 #endif /* __CONSOLE_H */
-- 
2.5.5



More information about the Skiboot mailing list