1 /* $NetBSD: console.c,v 1.13 2021/09/04 02:19:56 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 2000 Soren S. Jorvang. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
11 * 2. 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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: console.c,v 1.13 2021/09/04 02:19:56 tsutsui Exp $");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34 #include <sys/conf.h>
35
36 #include <sys/bus.h>
37 #include <machine/nvram.h>
38 #include <machine/bootinfo.h>
39
40 #include <dev/cons.h>
41
42 #include <cobalt/dev/com_mainbusvar.h>
43 #include <machine/z8530var.h>
44
45 #include "com_mainbus.h"
46 #include "zsc.h"
47 #include "nullcons.h"
48
49 int console_present = 0; /* Do we have a console? */
50
51 struct consdev constab[] = {
52 #if NCOM_MAINBUS > 0
53 {
54 .cn_probe = com_mainbus_cnprobe,
55 .cn_init = com_mainbus_cninit,
56 .cn_getc = NULL,
57 .cn_putc = NULL,
58 .cn_pollc = NULL,
59 .cn_bell = NULL,
60 .cn_halt = NULL,
61 .cn_flush = NULL,
62 .cn_dev = 0,
63 .cn_pri = CN_DEAD
64 },
65 #endif
66 #if NZSC > 0
67 {
68 .cn_probe = zscnprobe,
69 .cn_init = zscninit,
70 .cn_getc = zscngetc,
71 .cn_putc = zscnputc,
72 .cn_pollc = nullcnpollc,
73 .cn_bell = NULL,
74 .cn_halt = NULL,
75 .cn_flush = NULL,
76 .cn_dev = NODEV,
77 .cn_pri = CN_DEAD
78 },
79 #endif
80 #if NNULLCONS > 0
81 {
82 .cn_probe = nullcnprobe,
83 .cn_init = nullcninit,
84 .cn_getc = NULL,
85 .cn_putc = NULL,
86 .cn_pollc = NULL,
87 .cn_bell = NULL,
88 .cn_halt = NULL,
89 .cn_flush = NULL,
90 .cn_dev = 0,
91 .cn_pri = CN_DEAD
92 },
93 #endif
94 {
95 .cn_probe = NULL,
96 .cn_init = NULL,
97 .cn_getc = NULL,
98 .cn_putc = NULL,
99 .cn_pollc = NULL,
100 .cn_bell = NULL,
101 .cn_halt = NULL,
102 .cn_flush = NULL,
103 .cn_dev = 0,
104 .cn_pri = CN_DEAD
105 }
106 };
107
108 #define CONSOLE_PROBE 0x0020001c /* console flag passed by firmware */
109
110 void
consinit(void)111 consinit(void)
112 {
113 struct btinfo_flags *bi_flags;
114 static int initted;
115
116 if (initted)
117 return;
118 initted = 1;
119
120 /*
121 * Linux code has a comment that serial console must be probed
122 * early, otherwise the value which allows to detect serial port
123 * could be overwritten. Okay, probe here and record the result
124 * for the future use.
125 *
126 * Note that if the kernel was booted with a boot loader,
127 * the latter *has* to provide a flag indicating whether console
128 * is present or not because the value might be overwritten by
129 * the loaded kernel.
130 */
131 bi_flags = lookup_bootinfo(BTINFO_FLAGS);
132 if (bi_flags == NULL) {
133 /* No boot information, probe console now */
134 console_present =
135 *(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(CONSOLE_PROBE);
136 } else {
137 /* Get the value determined by the boot loader. */
138 console_present = bi_flags->bi_flags & BI_SERIAL_CONSOLE;
139 }
140
141 cninit();
142 }
143