Skip to content

Commit c90fe9c

Browse files
peterhurleygregkh
authored andcommitted
of: earlycon: Move address translation to of_setup_earlycon()
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 <[email protected]> Signed-off-by: Peter Hurley <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 088da2a commit c90fe9c

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

drivers/of/fdt.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,19 +827,13 @@ static int __init early_init_dt_scan_chosen_serial(void)
827827
return -ENODEV;
828828

829829
for (match = __earlycon_table; match < __earlycon_table_end; match++) {
830-
u64 addr;
831-
832830
if (!match->compatible[0])
833831
continue;
834832

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

838-
addr = fdt_translate_address(fdt, offset);
839-
if (addr == OF_BAD_ADDR)
840-
return -ENXIO;
841-
842-
of_setup_earlycon(addr, match, offset, options);
836+
of_setup_earlycon(match, offset, options);
843837
return 0;
844838
}
845839
return -ENODEV;

drivers/of/fdt_address.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static int __init fdt_translate_one(const void *blob, int parent,
161161
* that can be mapped to a cpu physical address). This is not really specified
162162
* that way, but this is traditionally the way IBM at least do things
163163
*/
164-
u64 __init fdt_translate_address(const void *blob, int node_offset)
164+
static u64 __init fdt_translate_address(const void *blob, int node_offset)
165165
{
166166
int parent, len;
167167
const struct of_bus *bus, *pbus;
@@ -239,3 +239,12 @@ u64 __init fdt_translate_address(const void *blob, int node_offset)
239239
bail:
240240
return result;
241241
}
242+
243+
/**
244+
* of_flat_dt_translate_address - translate DT addr into CPU phys addr
245+
* @node: node in the flat blob
246+
*/
247+
u64 __init of_flat_dt_translate_address(unsigned long node)
248+
{
249+
return fdt_translate_address(initial_boot_params, node);
250+
}

drivers/tty/serial/earlycon.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/io.h>
2020
#include <linux/serial_core.h>
2121
#include <linux/sizes.h>
22+
#include <linux/of.h>
2223
#include <linux/of_fdt.h>
2324

2425
#ifdef CONFIG_FIX_EARLYCON_MEM
@@ -218,21 +219,26 @@ early_param("earlycon", param_setup_earlycon);
218219

219220
#ifdef CONFIG_OF_EARLY_FLATTREE
220221

221-
int __init of_setup_earlycon(unsigned long addr,
222-
const struct earlycon_id *match,
222+
int __init of_setup_earlycon(const struct earlycon_id *match,
223223
unsigned long node,
224224
const char *options)
225225
{
226226
int err;
227227
struct uart_port *port = &early_console_dev.port;
228228
const __be32 *val;
229229
bool big_endian;
230+
u64 addr;
230231

231232
spin_lock_init(&port->lock);
232233
port->iotype = UPIO_MEM;
234+
addr = of_flat_dt_translate_address(node);
235+
if (addr == OF_BAD_ADDR) {
236+
pr_warn("[%s] bad address\n", match->name);
237+
return -ENXIO;
238+
}
233239
port->mapbase = addr;
234240
port->uartclk = BASE_BAUD * 16;
235-
port->membase = earlycon_map(addr, SZ_4K);
241+
port->membase = earlycon_map(port->mapbase, SZ_4K);
236242

237243
val = of_get_flat_dt_prop(node, "reg-offset", NULL);
238244
if (val)

include/linux/of_fdt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extern void unflatten_device_tree(void);
8888
extern void unflatten_and_copy_device_tree(void);
8989
extern void early_init_devtree(void *);
9090
extern void early_get_first_memblock_info(void *, phys_addr_t *);
91-
extern u64 fdt_translate_address(const void *blob, int node_offset);
91+
extern u64 of_flat_dt_translate_address(unsigned long node);
9292
extern void of_fdt_limit_memory(int limit);
9393
#else /* CONFIG_OF_FLATTREE */
9494
static inline void early_init_fdt_scan_reserved_mem(void) {}

include/linux/serial_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ extern const struct earlycon_id __earlycon_table_end[];
359359
#define EARLYCON_DECLARE(_name, fn) OF_EARLYCON_DECLARE(_name, "", fn)
360360

361361
extern int setup_earlycon(char *buf);
362-
extern int of_setup_earlycon(unsigned long addr, const struct earlycon_id *match,
362+
extern int of_setup_earlycon(const struct earlycon_id *match,
363363
unsigned long node,
364364
const char *options);
365365

0 commit comments

Comments
 (0)