consinit.c revision 1.18 1 1.18 bouyer /* $NetBSD: consinit.c,v 1.18 2023/10/17 12:07:42 bouyer Exp $ */
2 1.3 cl /* NetBSD: consinit.c,v 1.4 2004/03/13 17:31:34 bjh21 Exp */
3 1.1 cl
4 1.1 cl /*
5 1.1 cl * Copyright (c) 1998
6 1.1 cl * Matthias Drochner. All rights reserved.
7 1.1 cl *
8 1.1 cl * Redistribution and use in source and binary forms, with or without
9 1.1 cl * modification, are permitted provided that the following conditions
10 1.1 cl * are met:
11 1.1 cl * 1. Redistributions of source code must retain the above copyright
12 1.1 cl * notice, this list of conditions and the following disclaimer.
13 1.1 cl * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cl * notice, this list of conditions and the following disclaimer in the
15 1.1 cl * documentation and/or other materials provided with the distribution.
16 1.1 cl *
17 1.1 cl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 cl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 cl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 cl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 cl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 cl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 cl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 cl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 cl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1 cl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 cl *
28 1.1 cl */
29 1.1 cl
30 1.1 cl #include <sys/cdefs.h>
31 1.18 bouyer __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.18 2023/10/17 12:07:42 bouyer Exp $");
32 1.1 cl
33 1.1 cl #include "opt_kgdb.h"
34 1.1 cl
35 1.1 cl #include <sys/param.h>
36 1.1 cl #include <sys/systm.h>
37 1.1 cl #include <sys/device.h>
38 1.15 dyoung #include <sys/bus.h>
39 1.1 cl #include <machine/bootinfo.h>
40 1.18 bouyer #include <arch/x86/include/genfb_machdep.h>
41 1.1 cl
42 1.4 bouyer #include "xencons.h"
43 1.1 cl #include "vga.h"
44 1.1 cl #include "ega.h"
45 1.1 cl #include "pcdisplay.h"
46 1.18 bouyer #include "genfb.h"
47 1.1 cl #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
48 1.1 cl #include <dev/ic/mc6845reg.h>
49 1.1 cl #include <dev/ic/pcdisplayvar.h>
50 1.1 cl #if (NVGA > 0)
51 1.1 cl #include <dev/ic/vgareg.h>
52 1.1 cl #include <dev/ic/vgavar.h>
53 1.1 cl #endif
54 1.1 cl #if (NEGA > 0)
55 1.1 cl #include <dev/isa/egavar.h>
56 1.1 cl #endif
57 1.1 cl #if (NPCDISPLAY > 0)
58 1.1 cl #include <dev/isa/pcdisplayvar.h>
59 1.1 cl #endif
60 1.1 cl #endif
61 1.1 cl
62 1.1 cl #include "pckbc.h"
63 1.1 cl #if (NPCKBC > 0)
64 1.1 cl #include <dev/isa/isareg.h>
65 1.1 cl #include <dev/ic/i8042reg.h>
66 1.1 cl #include <dev/ic/pckbcvar.h>
67 1.1 cl #endif
68 1.1 cl #include "pckbd.h" /* for pckbc_machdep_cnattach */
69 1.1 cl
70 1.5 bouyer #include "ukbd.h"
71 1.5 bouyer #if (NUKBD > 0)
72 1.5 bouyer #include <dev/usb/ukbdvar.h>
73 1.5 bouyer #endif
74 1.5 bouyer
75 1.18 bouyer #if (NGENFB > 0)
76 1.18 bouyer #include <dev/wsfb/genfbvar.h>
77 1.18 bouyer #endif
78 1.18 bouyer
79 1.1 cl #include "opt_xen.h"
80 1.1 cl #if (XEN > 0)
81 1.10 bouyer #include <xen/xen.h>
82 1.3 cl #include <dev/pckbport/pckbportvar.h>
83 1.10 bouyer #include <xen/hypervisor.h>
84 1.17 mrg #include "xen_def_cons.h"
85 1.1 cl #endif
86 1.1 cl
87 1.1 cl #include "com.h"
88 1.1 cl #if (NCOM > 0)
89 1.1 cl #include <sys/termios.h>
90 1.1 cl #include <dev/ic/comreg.h>
91 1.1 cl #include <dev/ic/comvar.h>
92 1.1 cl #endif
93 1.1 cl
94 1.1 cl #ifndef CONSDEVNAME
95 1.1 cl #define CONSDEVNAME "pc"
96 1.1 cl #endif
97 1.1 cl
98 1.1 cl #if (NCOM > 0)
99 1.1 cl #ifndef CONADDR
100 1.1 cl #define CONADDR 0x3f8
101 1.1 cl #endif
102 1.1 cl #ifndef CONSPEED
103 1.1 cl #define CONSPEED TTYDEF_SPEED
104 1.1 cl #endif
105 1.1 cl #ifndef CONMODE
106 1.1 cl #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
107 1.1 cl #endif
108 1.1 cl int comcnmode = CONMODE;
109 1.1 cl #endif /* NCOM */
110 1.1 cl
111 1.1 cl const struct btinfo_console default_consinfo = {
112 1.1 cl {0, 0},
113 1.1 cl CONSDEVNAME,
114 1.1 cl #if (NCOM > 0)
115 1.1 cl CONADDR, CONSPEED
116 1.1 cl #else
117 1.1 cl 0, 0
118 1.1 cl #endif
119 1.1 cl };
120 1.1 cl
121 1.1 cl #ifdef KGDB
122 1.1 cl #ifndef KGDB_DEVNAME
123 1.1 cl #define KGDB_DEVNAME "com"
124 1.1 cl #endif
125 1.1 cl const char kgdb_devname[] = KGDB_DEVNAME;
126 1.1 cl
127 1.1 cl #if (NCOM > 0)
128 1.1 cl #ifndef KGDB_DEVADDR
129 1.1 cl #define KGDB_DEVADDR 0x3f8
130 1.1 cl #endif
131 1.1 cl int comkgdbaddr = KGDB_DEVADDR;
132 1.1 cl #ifndef KGDB_DEVRATE
133 1.1 cl #define KGDB_DEVRATE TTYDEF_SPEED
134 1.1 cl #endif
135 1.1 cl int comkgdbrate = KGDB_DEVRATE;
136 1.1 cl #ifndef KGDB_DEVMODE
137 1.1 cl #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
138 1.1 cl #endif
139 1.1 cl int comkgdbmode = KGDB_DEVMODE;
140 1.1 cl #endif /* NCOM */
141 1.1 cl
142 1.1 cl #endif /* KGDB */
143 1.1 cl
144 1.1 cl /*
145 1.1 cl * consinit:
146 1.1 cl * initialize the system console.
147 1.1 cl * XXX - shouldn't deal with this initted thing, but then,
148 1.1 cl * it shouldn't be called from init386 either.
149 1.1 cl */
150 1.1 cl void
151 1.12 cegger consinit(void)
152 1.1 cl {
153 1.4 bouyer static int initted = 0;
154 1.4 bouyer union xen_cmdline_parseinfo xcp;
155 1.18 bouyer #if (NGENFB > 0)
156 1.18 bouyer const struct btinfo_framebuffer *fbinfo = NULL;
157 1.18 bouyer #endif
158 1.18 bouyer
159 1.1 cl
160 1.4 bouyer if (initted) {
161 1.1 cl return;
162 1.4 bouyer }
163 1.18 bouyer
164 1.18 bouyer xen_early_console();
165 1.18 bouyer
166 1.18 bouyer #if (NGENFB > 0) && defined(DOM0OPS)
167 1.18 bouyer if (xendomain_is_dom0())
168 1.18 bouyer fbinfo = xen_genfb_getbtinfo();
169 1.18 bouyer #endif
170 1.18 bouyer
171 1.1 cl initted = 1;
172 1.4 bouyer xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp);
173 1.4 bouyer
174 1.18 bouyer #if (NVGA > 0) || (NGENFB > 0)
175 1.11 cegger if (xendomain_is_privileged()) {
176 1.4 bouyer #ifdef CONS_OVERRIDE
177 1.4 bouyer if (strcmp(default_consinfo.devname, "tty0") == 0 ||
178 1.7 bouyer strcmp(default_consinfo.devname, "pc") == 0) {
179 1.4 bouyer #else
180 1.4 bouyer if (strcmp(xcp.xcp_console, "tty0") == 0 || /* linux name */
181 1.4 bouyer strcmp(xcp.xcp_console, "pc") == 0) { /* NetBSD name */
182 1.4 bouyer #endif /* CONS_OVERRIDE */
183 1.5 bouyer int error;
184 1.18 bouyer
185 1.18 bouyer #if (NGENFB > 0)
186 1.18 bouyer if (fbinfo && fbinfo->physaddr > 0) {
187 1.18 bouyer if (x86_genfb_cnattach() == -1) {
188 1.18 bouyer initted = 0; /* defer */
189 1.18 bouyer return;
190 1.18 bouyer }
191 1.18 bouyer genfb_cnattach();
192 1.18 bouyer goto dokbd;
193 1.18 bouyer } else {
194 1.18 bouyer genfb_disable();
195 1.18 bouyer }
196 1.18 bouyer #endif
197 1.14 dyoung vga_cnattach(x86_bus_space_io, x86_bus_space_mem,
198 1.4 bouyer -1, 1);
199 1.18 bouyer #if (NGENFB > 0)
200 1.18 bouyer dokbd:
201 1.18 bouyer #endif
202 1.5 bouyer error = ENODEV;
203 1.18 bouyer
204 1.5 bouyer #if (NPCKBC > 0)
205 1.14 dyoung error = pckbc_cnattach(x86_bus_space_io, IO_KBD, KBCMDP,
206 1.16 jdc PCKBC_KBD_SLOT, 0);
207 1.5 bouyer #endif
208 1.5 bouyer #if (NUKBD > 0)
209 1.5 bouyer if (error)
210 1.5 bouyer error = ukbd_cnattach();
211 1.5 bouyer #endif
212 1.5 bouyer if (error)
213 1.5 bouyer printf("WARNING: no console keyboard, "
214 1.5 bouyer "error=%d\n", error);
215 1.3 cl return;
216 1.3 cl }
217 1.3 cl }
218 1.4 bouyer #endif /* NVGA */
219 1.4 bouyer #if NXENCONS > 0
220 1.3 cl xenconscn_attach();
221 1.3 cl return;
222 1.4 bouyer #endif /* NXENCONS */
223 1.4 bouyer panic("consinit: no console");
224 1.1 cl }
225 1.1 cl
226 1.1 cl #ifdef KGDB
227 1.1 cl void
228 1.13 cegger kgdb_port_init(void)
229 1.1 cl {
230 1.1 cl #if (NCOM > 0)
231 1.1 cl if(!strcmp(kgdb_devname, "com")) {
232 1.14 dyoung bus_space_tag_t tag = x86_bus_space_io;
233 1.1 cl
234 1.1 cl com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ,
235 1.1 cl COM_TYPE_NORMAL, comkgdbmode);
236 1.1 cl }
237 1.1 cl #endif
238 1.1 cl }
239 1.1 cl #endif
240