Skip to content

Commit a752ee5

Browse files
committed
tty: Update hypervisor tty drivers to use core stdout parsing code.
The evh_bytechan, hvc_opal and hvc_vio drivers all open code the parsing of the stdout node in the device tree. This patch simplifies the driver by removing the duplicated functionality. Signed-off-by: Grant Likely <grant.likely@linaro.org>
1 parent 0038821 commit a752ee5

5 files changed

Lines changed: 22 additions & 71 deletions

File tree

‎drivers/of/base.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct device_node *of_allnodes;
3636
EXPORT_SYMBOL(of_allnodes);
3737
struct device_node *of_chosen;
3838
struct device_node *of_aliases;
39-
static struct device_node *of_stdout;
39+
struct device_node *of_stdout;
4040

4141
static struct kset *of_kset;
4242

@@ -2063,9 +2063,12 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
20632063
of_chosen = of_find_node_by_path("/chosen@0");
20642064

20652065
if (of_chosen) {
2066+
/* linux,stdout-path and /aliases/stdout are for legacy compatibility */
20662067
const char *name = of_get_property(of_chosen, "stdout-path", NULL);
20672068
if (!name)
20682069
name = of_get_property(of_chosen, "linux,stdout-path", NULL);
2070+
if (IS_ENABLED(CONFIG_PPC) && !name)
2071+
name = of_get_property(of_aliases, "stdout", NULL);
20692072
if (name)
20702073
of_stdout = of_find_node_by_path(name);
20712074
}

‎drivers/tty/ehv_bytechan.c‎

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -108,55 +108,23 @@ static void disable_tx_interrupt(struct ehv_bc_data *bc)
108108
*
109109
* The byte channel to be used for the console is specified via a "stdout"
110110
* property in the /chosen node.
111-
*
112-
* For compatible with legacy device trees, we also look for a "stdout" alias.
113111
*/
114112
static int find_console_handle(void)
115113
{
116-
struct device_node *np, *np2;
114+
struct device_node *np = of_stdout;
117115
const char *sprop = NULL;
118116
const uint32_t *iprop;
119117

120-
np = of_find_node_by_path("/chosen");
121-
if (np)
122-
sprop = of_get_property(np, "stdout-path", NULL);
123-
124-
if (!np || !sprop) {
125-
of_node_put(np);
126-
np = of_find_node_by_name(NULL, "aliases");
127-
if (np)
128-
sprop = of_get_property(np, "stdout", NULL);
129-
}
130-
131-
if (!sprop) {
132-
of_node_put(np);
133-
return 0;
134-
}
135-
136118
/* We don't care what the aliased node is actually called. We only
137119
* care if it's compatible with "epapr,hv-byte-channel", because that
138-
* indicates that it's a byte channel node. We use a temporary
139-
* variable, 'np2', because we can't release 'np' until we're done with
140-
* 'sprop'.
120+
* indicates that it's a byte channel node.
141121
*/
142-
np2 = of_find_node_by_path(sprop);
143-
of_node_put(np);
144-
np = np2;
145-
if (!np) {
146-
pr_warning("ehv-bc: stdout node '%s' does not exist\n", sprop);
147-
return 0;
148-
}
149-
150-
/* Is it a byte channel? */
151-
if (!of_device_is_compatible(np, "epapr,hv-byte-channel")) {
152-
of_node_put(np);
122+
if (!np || !of_device_is_compatible(np, "epapr,hv-byte-channel"))
153123
return 0;
154-
}
155124

156125
stdout_irq = irq_of_parse_and_map(np, 0);
157126
if (stdout_irq == NO_IRQ) {
158-
pr_err("ehv-bc: no 'interrupts' property in %s node\n", sprop);
159-
of_node_put(np);
127+
pr_err("ehv-bc: no 'interrupts' property in %s node\n", np->full_name);
160128
return 0;
161129
}
162130

@@ -167,12 +135,9 @@ static int find_console_handle(void)
167135
if (!iprop) {
168136
pr_err("ehv-bc: no 'hv-handle' property in %s node\n",
169137
np->name);
170-
of_node_put(np);
171138
return 0;
172139
}
173140
stdout_bc = be32_to_cpu(*iprop);
174-
175-
of_node_put(np);
176141
return 1;
177142
}
178143

‎drivers/tty/hvc/hvc_opal.c‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,13 @@ static void udbg_init_opal_common(void)
342342

343343
void __init hvc_opal_init_early(void)
344344
{
345-
struct device_node *stdout_node = NULL;
345+
struct device_node *stdout_node = of_node_get(of_stdout);
346346
const __be32 *termno;
347-
const char *name = NULL;
348347
const struct hv_ops *ops;
349348
u32 index;
350349

351-
/* find the boot console from /chosen/stdout */
352-
if (of_chosen)
353-
name = of_get_property(of_chosen, "linux,stdout-path", NULL);
354-
if (name) {
355-
stdout_node = of_find_node_by_path(name);
356-
if (!stdout_node) {
357-
pr_err("hvc_opal: Failed to locate default console!\n");
358-
return;
359-
}
360-
} else {
350+
/* If the console wasn't in /chosen, try /ibm,opal */
351+
if (!stdout_node) {
361352
struct device_node *opal, *np;
362353

363354
/* Current OPAL takeover doesn't provide the stdout

‎drivers/tty/hvc/hvc_vio.c‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -404,50 +404,43 @@ module_exit(hvc_vio_exit);
404404

405405
void __init hvc_vio_init_early(void)
406406
{
407-
struct device_node *stdout_node;
408407
const __be32 *termno;
409408
const char *name;
410409
const struct hv_ops *ops;
411410

412411
/* find the boot console from /chosen/stdout */
413-
if (!of_chosen)
412+
if (!of_stdout)
414413
return;
415-
name = of_get_property(of_chosen, "linux,stdout-path", NULL);
416-
if (name == NULL)
417-
return;
418-
stdout_node = of_find_node_by_path(name);
419-
if (!stdout_node)
420-
return;
421-
name = of_get_property(stdout_node, "name", NULL);
414+
name = of_get_property(of_stdout, "name", NULL);
422415
if (!name) {
423416
printk(KERN_WARNING "stdout node missing 'name' property!\n");
424-
goto out;
417+
return;
425418
}
426419

427420
/* Check if it's a virtual terminal */
428421
if (strncmp(name, "vty", 3) != 0)
429-
goto out;
430-
termno = of_get_property(stdout_node, "reg", NULL);
422+
return;
423+
termno = of_get_property(of_stdout, "reg", NULL);
431424
if (termno == NULL)
432-
goto out;
425+
return;
433426
hvterm_priv0.termno = of_read_number(termno, 1);
434427
spin_lock_init(&hvterm_priv0.buf_lock);
435428
hvterm_privs[0] = &hvterm_priv0;
436429

437430
/* Check the protocol */
438-
if (of_device_is_compatible(stdout_node, "hvterm1")) {
431+
if (of_device_is_compatible(of_stdout, "hvterm1")) {
439432
hvterm_priv0.proto = HV_PROTOCOL_RAW;
440433
ops = &hvterm_raw_ops;
441434
}
442-
else if (of_device_is_compatible(stdout_node, "hvterm-protocol")) {
435+
else if (of_device_is_compatible(of_stdout, "hvterm-protocol")) {
443436
hvterm_priv0.proto = HV_PROTOCOL_HVSI;
444437
ops = &hvterm_hvsi_ops;
445438
hvsilib_init(&hvterm_priv0.hvsi, hvc_get_chars, hvc_put_chars,
446439
hvterm_priv0.termno, 1);
447440
/* HVSI, perform the handshake now */
448441
hvsilib_establish(&hvterm_priv0.hvsi);
449442
} else
450-
goto out;
443+
return;
451444
udbg_putc = udbg_hvc_putc;
452445
udbg_getc = udbg_hvc_getc;
453446
udbg_getc_poll = udbg_hvc_getc_poll;
@@ -456,14 +449,12 @@ void __init hvc_vio_init_early(void)
456449
* backend for HVSI, only do udbg
457450
*/
458451
if (hvterm_priv0.proto == HV_PROTOCOL_HVSI)
459-
goto out;
452+
return;
460453
#endif
461454
/* Check whether the user has requested a different console. */
462455
if (!strstr(cmd_line, "console="))
463456
add_preferred_console("hvc", 0, NULL);
464457
hvc_instantiate(0, 0, ops);
465-
out:
466-
of_node_put(stdout_node);
467458
}
468459

469460
/* call this from early_init() for a working debug console on

‎include/linux/of.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static inline void of_node_put(struct device_node *node) { }
113113
extern struct device_node *of_allnodes;
114114
extern struct device_node *of_chosen;
115115
extern struct device_node *of_aliases;
116+
extern struct device_node *of_stdout;
116117
extern raw_spinlock_t devtree_lock;
117118

118119
static inline bool of_have_populated_dt(void)

0 commit comments

Comments
 (0)