Skip to content

Commit

Permalink
console: add helper to create serial console nodes
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Jan 4, 2017
1 parent 8c0ec75 commit 7edaf63
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
43 changes: 31 additions & 12 deletions core/console.c
Expand Up @@ -103,6 +103,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);
Expand Down Expand Up @@ -396,20 +426,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");
Expand Down
24 changes: 8 additions & 16 deletions hw/fsp/fsp-console.c
Expand Up @@ -917,37 +917,29 @@ 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);
Expand Down
16 changes: 2 additions & 14 deletions hw/lpc-uart.c
Expand Up @@ -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", OUT_BUF_SIZE);

dt_add_property_string(dt_chosen, "linux,stdout-path",
"/ibm,opal/consoles/serial@0");
Expand Down
3 changes: 3 additions & 0 deletions include/console.h
Expand Up @@ -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 */

0 comments on commit 7edaf63

Please sign in to comment.