consinit.c revision 1.7 1 /* $NetBSD: consinit.c,v 1.7 2006/12/09 10:37:52 bouyer Exp $ */
2 /* NetBSD: consinit.c,v 1.4 2004/03/13 17:31:34 bjh21 Exp */
3
4 /*
5 * Copyright (c) 1998
6 * Matthias Drochner. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
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
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.7 2006/12/09 10:37:52 bouyer Exp $");
32
33 #include "opt_kgdb.h"
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <machine/bus.h>
39 #include <machine/bootinfo.h>
40
41 #include "xencons.h"
42 #include "vga.h"
43 #include "ega.h"
44 #include "pcdisplay.h"
45 #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
46 #include <dev/ic/mc6845reg.h>
47 #include <dev/ic/pcdisplayvar.h>
48 #if (NVGA > 0)
49 #include <dev/ic/vgareg.h>
50 #include <dev/ic/vgavar.h>
51 #endif
52 #if (NEGA > 0)
53 #include <dev/isa/egavar.h>
54 #endif
55 #if (NPCDISPLAY > 0)
56 #include <dev/isa/pcdisplayvar.h>
57 #endif
58 #endif
59
60 #include "pckbc.h"
61 #if (NPCKBC > 0)
62 #include <dev/isa/isareg.h>
63 #include <dev/ic/i8042reg.h>
64 #include <dev/ic/pckbcvar.h>
65 #endif
66 #include "pckbd.h" /* for pckbc_machdep_cnattach */
67
68 #include "ukbd.h"
69 #if (NUKBD > 0)
70 #include <dev/usb/ukbdvar.h>
71 #endif
72
73 #ifndef __x86_64__
74 #include "pc.h"
75 #endif
76 #if (NPC > 0)
77 #include <machine/pccons.h>
78 #endif
79
80 #include "opt_xen.h"
81 #if (XEN > 0)
82 #include <machine/xen.h>
83 #include <dev/pckbport/pckbportvar.h>
84 #include <machine/hypervisor.h>
85 #endif
86
87 #include "com.h"
88 #if (NCOM > 0)
89 #include <sys/termios.h>
90 #include <dev/ic/comreg.h>
91 #include <dev/ic/comvar.h>
92 #endif
93
94 #include "ukbd.h"
95 #if (NUKBD > 0)
96 #include <dev/usb/ukbdvar.h>
97 #endif
98
99 #ifndef CONSDEVNAME
100 #define CONSDEVNAME "pc"
101 #endif
102
103 #if (NCOM > 0)
104 #ifndef CONADDR
105 #define CONADDR 0x3f8
106 #endif
107 #ifndef CONSPEED
108 #define CONSPEED TTYDEF_SPEED
109 #endif
110 #ifndef CONMODE
111 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
112 #endif
113 int comcnmode = CONMODE;
114 #endif /* NCOM */
115
116 const struct btinfo_console default_consinfo = {
117 {0, 0},
118 CONSDEVNAME,
119 #if (NCOM > 0)
120 CONADDR, CONSPEED
121 #else
122 0, 0
123 #endif
124 };
125
126 #ifdef KGDB
127 #ifndef KGDB_DEVNAME
128 #define KGDB_DEVNAME "com"
129 #endif
130 const char kgdb_devname[] = KGDB_DEVNAME;
131
132 #if (NCOM > 0)
133 #ifndef KGDB_DEVADDR
134 #define KGDB_DEVADDR 0x3f8
135 #endif
136 int comkgdbaddr = KGDB_DEVADDR;
137 #ifndef KGDB_DEVRATE
138 #define KGDB_DEVRATE TTYDEF_SPEED
139 #endif
140 int comkgdbrate = KGDB_DEVRATE;
141 #ifndef KGDB_DEVMODE
142 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
143 #endif
144 int comkgdbmode = KGDB_DEVMODE;
145 #endif /* NCOM */
146
147 #endif /* KGDB */
148
149 /*
150 * consinit:
151 * initialize the system console.
152 * XXX - shouldn't deal with this initted thing, but then,
153 * it shouldn't be called from init386 either.
154 */
155 void
156 consinit()
157 {
158 static int initted = 0;
159 union xen_cmdline_parseinfo xcp;
160
161 if (initted) {
162 return;
163 }
164 initted = 1;
165 xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp);
166
167 #if (NVGA > 0)
168 if (xen_start_info.flags & SIF_PRIVILEGED) {
169 #ifdef CONS_OVERRIDE
170 if (strcmp(default_consinfo.devname, "tty0") == 0 ||
171 strcmp(default_consinfo.devname, "pc") == 0) {
172 #else
173 if (strcmp(xcp.xcp_console, "tty0") == 0 || /* linux name */
174 strcmp(xcp.xcp_console, "pc") == 0) { /* NetBSD name */
175 #endif /* CONS_OVERRIDE */
176 int error;
177 vga_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM,
178 -1, 1);
179 error = ENODEV;
180 #if (NPCKBC > 0)
181 error = pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP,
182 PCKBC_KBD_SLOT);
183 #endif
184 #if (NUKBD > 0)
185 if (error)
186 error = ukbd_cnattach();
187 #endif
188 if (error)
189 printf("WARNING: no console keyboard, "
190 "error=%d\n", error);
191 return;
192 }
193 }
194 #endif /* NVGA */
195 #if NXENCONS > 0
196 xenconscn_attach();
197 return;
198 #endif /* NXENCONS */
199 panic("consinit: no console");
200 }
201
202 #if (NPCKBC > 0) && (NPCKBD == 0)
203 /*
204 * glue code to support old console code with the
205 * mi keyboard controller driver
206 */
207 int
208 pckbport_machdep_cnattach(kbctag, kbcslot)
209 pckbport_tag_t kbctag;
210 pckbport_slot_t kbcslot;
211 {
212 #if (NPC > 0) && (NPCCONSKBD > 0)
213 return (pcconskbd_cnattach(kbctag, kbcslot));
214 #else
215 return (ENXIO);
216 #endif
217 }
218 #endif
219
220 #ifdef KGDB
221 void
222 kgdb_port_init()
223 {
224 #if (NCOM > 0)
225 if(!strcmp(kgdb_devname, "com")) {
226 bus_space_tag_t tag = X86_BUS_SPACE_IO;
227
228 com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ,
229 COM_TYPE_NORMAL, comkgdbmode);
230 }
231 #endif
232 }
233 #endif
234