source: mainline/kernel/arch/sparc64/src/drivers/tty.c

Last change on this file was 1b1be5f, checked in by Jakub Jermar <jakub@…>, 6 years ago

Add support for serial kernel console on sun4u

This feature is currently disabled by default (CONFIG_SUN_TTY) due to
the following behavior observed with QEMU 3.1. After producing a couple
of lines of serial output, the kernel seems to hang on an IO read of the
NS 16550's LSR register (which it needs in order to test for
LSR_TH_READY). Providing some input on the serial console results in
unblocking the kernel for a while until it blocks again a couple of
lines of output later.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2019 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kernel_sparc64
30 * @{
31 */
32/** @file
33 */
34
35#include <genarch/ofw/ofw_tree.h>
36#include <genarch/ofw/ebus.h>
37#include <console/console.h>
38#include <genarch/srln/srln.h>
39#include <ddi/irq.h>
40#include <typedefs.h>
41#include <align.h>
42#include <str.h>
43#include <log.h>
44
45#ifdef CONFIG_SUN_TTY
46#include <arch/drivers/tty.h>
47#endif
48
49#ifdef CONFIG_NS16550
50#include <genarch/drivers/ns16550/ns16550.h>
51#endif
52
53#ifdef CONFIG_SUN_TTY
54
55#ifdef CONFIG_NS16550
56
57static bool tty_ns16550_init(ofw_tree_node_t *node)
58{
59 const char *name = ofw_tree_node_name(node);
60
61 if (str_cmp(name, "su") != 0)
62 return false;
63
64 /*
65 * Read 'interrupts' property.
66 */
67 ofw_tree_property_t *prop = ofw_tree_getprop(node, "interrupts");
68 if ((!prop) || (!prop->value)) {
69 log(LF_ARCH, LVL_ERROR,
70 "ns16550: Unable to find interrupts property");
71 return false;
72 }
73
74 uint32_t interrupts = *((uint32_t *) prop->value);
75
76 /*
77 * Read 'reg' property.
78 */
79 prop = ofw_tree_getprop(node, "reg");
80 if ((!prop) || (!prop->value)) {
81 log(LF_ARCH, LVL_ERROR,
82 "ns16550: Unable to find reg property");
83 return false;
84 }
85
86 uintptr_t pa = 0; // Prevent -Werror=maybe-uninitialized
87 if (!ofw_ebus_apply_ranges(node->parent,
88 ((ofw_ebus_reg_t *) prop->value), &pa)) {
89 log(LF_ARCH, LVL_ERROR,
90 "ns16550: Failed to determine address");
91 return false;
92 }
93
94 inr_t inr;
95 cir_t cir;
96 void *cir_arg;
97 if (!ofw_ebus_map_interrupt(node->parent,
98 ((ofw_ebus_reg_t *) prop->value), interrupts, &inr, &cir,
99 &cir_arg)) {
100 log(LF_ARCH, LVL_ERROR,
101 "ns16550: Failed to determine interrupt");
102 return false;
103 }
104
105 outdev_t *ns16550_out;
106 ns16550_instance_t *ns16550_instance = ns16550_init((ioport8_t *) pa, 0,
107 inr, cir, cir_arg, &ns16550_out);
108 if (ns16550_instance) {
109 srln_instance_t *srln_instance = srln_init();
110 if (srln_instance) {
111 indev_t *sink = stdin_wire();
112 indev_t *srln = srln_wire(srln_instance, sink);
113 ns16550_wire(ns16550_instance, srln);
114 }
115 stdout_wire(ns16550_out);
116 }
117
118 return true;
119}
120
121#endif /* CONFIG_NS16550 */
122
123/** Initialize tty.
124 *
125 * Traverse OpenFirmware device tree in order to find necessary
126 * info about the keyboard device.
127 *
128 * @param node Keyboard device node.
129 *
130 */
131void tty_init(ofw_tree_node_t *node)
132{
133#ifdef CONFIG_NS16550
134 tty_ns16550_init(node);
135#endif
136}
137
138#endif /* CONFIG_SUN_TTY */
139
140/** @}
141 */
Note: See TracBrowser for help on using the repository browser.