consinit.c revision 1.1 1 /* $NetBSD: consinit.c,v 1.1 2004/03/11 21:44:08 cl Exp $ */
2 /* NetBSD: consinit.c,v 1.3 2003/06/14 17:01:15 thorpej 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.1 2004/03/11 21:44:08 cl 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 "vga.h"
42 #include "ega.h"
43 #include "pcdisplay.h"
44 #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
45 #include <dev/ic/mc6845reg.h>
46 #include <dev/ic/pcdisplayvar.h>
47 #if (NVGA > 0)
48 #include <dev/ic/vgareg.h>
49 #include <dev/ic/vgavar.h>
50 #endif
51 #if (NEGA > 0)
52 #include <dev/isa/egavar.h>
53 #endif
54 #if (NPCDISPLAY > 0)
55 #include <dev/isa/pcdisplayvar.h>
56 #endif
57 #endif
58
59 #include "pckbc.h"
60 #if (NPCKBC > 0)
61 #include <dev/isa/isareg.h>
62 #include <dev/ic/i8042reg.h>
63 #include <dev/ic/pckbcvar.h>
64 #endif
65 #include "pckbd.h" /* for pckbc_machdep_cnattach */
66
67 #ifndef __x86_64__
68 #include "pc.h"
69 #endif
70 #if (NPC > 0)
71 #include <machine/pccons.h>
72 #endif
73
74 #include "opt_xen.h"
75 #if (XEN > 0)
76 #include <machine/xen.h>
77 #endif
78
79 #include "com.h"
80 #if (NCOM > 0)
81 #include <sys/termios.h>
82 #include <dev/ic/comreg.h>
83 #include <dev/ic/comvar.h>
84 #endif
85
86 #include "ukbd.h"
87 #if (NUKBD > 0)
88 #include <dev/usb/ukbdvar.h>
89 #endif
90
91 #ifndef CONSDEVNAME
92 #define CONSDEVNAME "pc"
93 #endif
94
95 #if (NCOM > 0)
96 #ifndef CONADDR
97 #define CONADDR 0x3f8
98 #endif
99 #ifndef CONSPEED
100 #define CONSPEED TTYDEF_SPEED
101 #endif
102 #ifndef CONMODE
103 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
104 #endif
105 int comcnmode = CONMODE;
106 #endif /* NCOM */
107
108 const struct btinfo_console default_consinfo = {
109 {0, 0},
110 CONSDEVNAME,
111 #if (NCOM > 0)
112 CONADDR, CONSPEED
113 #else
114 0, 0
115 #endif
116 };
117
118 #ifdef KGDB
119 #ifndef KGDB_DEVNAME
120 #define KGDB_DEVNAME "com"
121 #endif
122 const char kgdb_devname[] = KGDB_DEVNAME;
123
124 #if (NCOM > 0)
125 #ifndef KGDB_DEVADDR
126 #define KGDB_DEVADDR 0x3f8
127 #endif
128 int comkgdbaddr = KGDB_DEVADDR;
129 #ifndef KGDB_DEVRATE
130 #define KGDB_DEVRATE TTYDEF_SPEED
131 #endif
132 int comkgdbrate = KGDB_DEVRATE;
133 #ifndef KGDB_DEVMODE
134 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
135 #endif
136 int comkgdbmode = KGDB_DEVMODE;
137 #endif /* NCOM */
138
139 #endif /* KGDB */
140
141 /*
142 * consinit:
143 * initialize the system console.
144 * XXX - shouldn't deal with this initted thing, but then,
145 * it shouldn't be called from init386 either.
146 */
147 void
148 consinit()
149 {
150 const struct btinfo_console *consinfo;
151 static int initted;
152
153 if (initted)
154 return;
155 initted = 1;
156
157 #ifndef CONS_OVERRIDE
158 consinfo = lookup_bootinfo(BTINFO_CONSOLE);
159 if (!consinfo)
160 #endif
161 consinfo = &default_consinfo;
162
163 #if (NPC > 0) || (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
164 if (!strcmp(consinfo->devname, "pc")) {
165 #if (NVGA > 0)
166 if (!vga_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM,
167 -1, 1))
168 goto dokbd;
169 #endif
170 #if (NEGA > 0)
171 if (!ega_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM))
172 goto dokbd;
173 #endif
174 #if (NPCDISPLAY > 0)
175 if (!pcdisplay_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM))
176 goto dokbd;
177 #endif
178 #if (NPC > 0)
179 pccnattach();
180 #endif
181 if (0) goto dokbd; /* XXX stupid gcc */
182 dokbd:
183 #if (NPCKBC > 0)
184 pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP,
185 PCKBC_KBD_SLOT);
186 #endif
187 #if NPCKBC == 0 && NUKBD > 0
188 ukbd_cnattach();
189 #endif
190 return;
191 }
192 #endif /* PC | VT | VGA | PCDISPLAY */
193 #if (NCOM > 0)
194 if (!strcmp(consinfo->devname, "com")) {
195 bus_space_tag_t tag = X86_BUS_SPACE_IO;
196
197 if (comcnattach(tag, consinfo->addr, consinfo->speed,
198 COM_FREQ, COM_TYPE_NORMAL, comcnmode))
199 panic("can't init serial console @%x", consinfo->addr);
200
201 return;
202 }
203 #endif
204 #if (XEN > 0)
205 if (!strcmp(consinfo->devname, "xen")) {
206 xencn_attach();
207 printf("NetBSD Xen console attached.\n");
208 return;
209 }
210 #endif
211 panic("invalid console device %s", consinfo->devname);
212 }
213
214 #if (NPCKBC > 0) && (NPCKBD == 0)
215 /*
216 * glue code to support old console code with the
217 * mi keyboard controller driver
218 */
219 int
220 pckbc_machdep_cnattach(kbctag, kbcslot)
221 pckbc_tag_t kbctag;
222 pckbc_slot_t kbcslot;
223 {
224 #if (NPC > 0) && (NPCCONSKBD > 0)
225 return (pcconskbd_cnattach(kbctag, kbcslot));
226 #else
227 return (ENXIO);
228 #endif
229 }
230 #endif
231
232 #ifdef KGDB
233 void
234 kgdb_port_init()
235 {
236 #if (NCOM > 0)
237 if(!strcmp(kgdb_devname, "com")) {
238 bus_space_tag_t tag = X86_BUS_SPACE_IO;
239
240 com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ,
241 COM_TYPE_NORMAL, comkgdbmode);
242 }
243 #endif
244 }
245 #endif
246