Skip to content

Commit

Permalink
of: earlycon: Move address translation to of_setup_earlycon()
Browse files Browse the repository at this point in the history
Cleanup the early DT/earlycon separation; remove the 'addr' parameter
from of_setup_earlycon() and get the uart phys addr directly with a
new wrapper function, of_flat_dt_translate_addr(). Limit
fdt_translate_address() to file scope.

Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Hurley authored and Greg Kroah-Hartman committed Feb 7, 2016
1 parent 088da2a commit c90fe9c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
8 changes: 1 addition & 7 deletions drivers/of/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,19 +827,13 @@ static int __init early_init_dt_scan_chosen_serial(void)
return -ENODEV;

for (match = __earlycon_table; match < __earlycon_table_end; match++) {
u64 addr;

if (!match->compatible[0])
continue;

if (fdt_node_check_compatible(fdt, offset, match->compatible))
continue;

addr = fdt_translate_address(fdt, offset);
if (addr == OF_BAD_ADDR)
return -ENXIO;

of_setup_earlycon(addr, match, offset, options);
of_setup_earlycon(match, offset, options);
return 0;
}
return -ENODEV;
Expand Down
11 changes: 10 additions & 1 deletion drivers/of/fdt_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static int __init fdt_translate_one(const void *blob, int parent,
* that can be mapped to a cpu physical address). This is not really specified
* that way, but this is traditionally the way IBM at least do things
*/
u64 __init fdt_translate_address(const void *blob, int node_offset)
static u64 __init fdt_translate_address(const void *blob, int node_offset)
{
int parent, len;
const struct of_bus *bus, *pbus;
Expand Down Expand Up @@ -239,3 +239,12 @@ u64 __init fdt_translate_address(const void *blob, int node_offset)
bail:
return result;
}

/**
* of_flat_dt_translate_address - translate DT addr into CPU phys addr
* @node: node in the flat blob
*/
u64 __init of_flat_dt_translate_address(unsigned long node)
{
return fdt_translate_address(initial_boot_params, node);
}
12 changes: 9 additions & 3 deletions drivers/tty/serial/earlycon.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/io.h>
#include <linux/serial_core.h>
#include <linux/sizes.h>
#include <linux/of.h>
#include <linux/of_fdt.h>

#ifdef CONFIG_FIX_EARLYCON_MEM
Expand Down Expand Up @@ -218,21 +219,26 @@ early_param("earlycon", param_setup_earlycon);

#ifdef CONFIG_OF_EARLY_FLATTREE

int __init of_setup_earlycon(unsigned long addr,
const struct earlycon_id *match,
int __init of_setup_earlycon(const struct earlycon_id *match,
unsigned long node,
const char *options)
{
int err;
struct uart_port *port = &early_console_dev.port;
const __be32 *val;
bool big_endian;
u64 addr;

spin_lock_init(&port->lock);
port->iotype = UPIO_MEM;
addr = of_flat_dt_translate_address(node);
if (addr == OF_BAD_ADDR) {
pr_warn("[%s] bad address\n", match->name);
return -ENXIO;
}
port->mapbase = addr;
port->uartclk = BASE_BAUD * 16;
port->membase = earlycon_map(addr, SZ_4K);
port->membase = earlycon_map(port->mapbase, SZ_4K);

val = of_get_flat_dt_prop(node, "reg-offset", NULL);
if (val)
Expand Down
2 changes: 1 addition & 1 deletion include/linux/of_fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extern void unflatten_device_tree(void);
extern void unflatten_and_copy_device_tree(void);
extern void early_init_devtree(void *);
extern void early_get_first_memblock_info(void *, phys_addr_t *);
extern u64 fdt_translate_address(const void *blob, int node_offset);
extern u64 of_flat_dt_translate_address(unsigned long node);
extern void of_fdt_limit_memory(int limit);
#else /* CONFIG_OF_FLATTREE */
static inline void early_init_fdt_scan_reserved_mem(void) {}
Expand Down
2 changes: 1 addition & 1 deletion include/linux/serial_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ extern const struct earlycon_id __earlycon_table_end[];
#define EARLYCON_DECLARE(_name, fn) OF_EARLYCON_DECLARE(_name, "", fn)

extern int setup_earlycon(char *buf);
extern int of_setup_earlycon(unsigned long addr, const struct earlycon_id *match,
extern int of_setup_earlycon(const struct earlycon_id *match,
unsigned long node,
const char *options);

Expand Down

0 comments on commit c90fe9c

Please sign in to comment.