1 /* $NetBSD: consinit.c,v 1.13 2013/11/06 02:35:26 christos Exp $ */
2
3 /*
4 * Copyright (c) 1998
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.13 2013/11/06 02:35:26 christos Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <dev/cons.h>
36 #include <sys/bus.h>
37 #include <dev/isa/isavar.h>
38
39 #include "vga.h"
40 #if (NVGA > 0)
41 #include <dev/ic/mc6845reg.h>
42 #include <dev/ic/pcdisplayvar.h>
43 #include <dev/ic/vgareg.h>
44 #include <dev/ic/vgavar.h>
45 #endif
46 #include "vga_ofbus.h"
47 #if (NVGA_OFBUS > 0)
48 #include <shark/ofw/vga_ofbusvar.h>
49 #endif
50
51 #include "pckbc.h"
52 #if (NPCKBC > 0)
53 #include <dev/isa/isareg.h>
54 #include <dev/ic/i8042reg.h>
55 #include <dev/ic/pckbcvar.h>
56 #include <dev/pckbport/pckbportvar.h>
57 #endif
58 #include "pckbd.h" /* for pckbc_machdep_cnattach */
59
60 #include "com.h"
61 #if (NCOM > 0)
62 #include <sys/termios.h>
63 #include <dev/ic/comreg.h>
64 #include <dev/ic/comvar.h>
65 #endif
66
67 #include "ofcons.h"
68 #if (NOFCONS > 0)
69 cons_decl(ofcons_)
70 static struct consdev ofcons = cons_init(ofcons_);
71 #endif
72
73 #include "igsfb_ofbus.h"
74 #include "chipsfb_ofbus.h"
75 #include <shark/ofw/igsfb_ofbusvar.h>
76
77 #if (NCHIPSFB_OFBUS > 0)
78 extern int chipsfb_ofbus_cnattach(bus_space_tag_t, bus_space_tag_t);
79 #endif
80
81 #if (NCOM > 0)
82 #ifndef CONADDR
83 #define CONADDR 0x3f8
84 #endif
85 #ifndef CONSPEED
86 #define CONSPEED TTYDEF_SPEED
87 #endif
88 #ifndef CONMODE
89 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
90 #endif
91 int comcnmode = CONMODE;
92 #endif /* NCOM */
93 #ifdef COMCONSOLE
94 int comconsole = 1;
95 #else
96 int comconsole = 0;
97 #endif
98
99 /*
100 * consinit:
101 * initialize the system console.
102 */
103 void
consinit(void)104 consinit(void)
105 {
106 static int initted;
107
108 if (initted)
109 return;
110 initted = 1;
111
112 #if (NVGA > 0)
113 /* The font built into the VGA ROM is broken: all the characters
114 * above the 127th do not match the standard set expected by the
115 * console. E.g. boxes drawn using the ACS are incorrect. */
116 vga_no_builtinfont = 1;
117 #endif
118
119 if (!comconsole) {
120 #if (NVGA > 0) || (NCHIPSFB_OFBUS > 0) || (NIGSFB_OFBUS > 0)
121 #if (NIGSFB_OFBUS > 0)
122 if (!igsfb_ofbus_cnattach(&isa_io_bs_tag, &isa_mem_bs_tag)) {
123 #if (NPCKBC > 0)
124 pckbc_cnattach(&isa_io_bs_tag, IO_KBD, KBCMDP,
125 PCKBC_KBD_SLOT, 0);
126 #endif /* NPCKBC */
127 return;
128 }
129 #endif /* NIGSFB_OFBUS */
130 #if (NCHIPSFB_OFBUS > 0)
131 if (!chipsfb_ofbus_cnattach(&isa_io_bs_tag, &isa_mem_bs_tag)) {
132 #if (NPCKBC > 0)
133 pckbc_cnattach(&isa_io_bs_tag, IO_KBD, KBCMDP,
134 PCKBC_KBD_SLOT, 0);
135 #endif /* NPCKBC */
136 return;
137 }
138 #endif /* NCHIPSFB_OFBUS */
139 #if (NVGA_OFBUS > 0)
140 if (!vga_ofbus_cnattach(&isa_io_bs_tag, &isa_mem_bs_tag)) {
141 #if (NPCKBC > 0)
142 pckbc_cnattach(&isa_io_bs_tag, IO_KBD, KBCMDP,
143 PCKBC_KBD_SLOT, 0);
144 #endif /* NPCKBC */
145 return;
146 }
147 #endif /* NVGA_OFBUS */
148
149 #else /* NVGA */
150 #if (NOFCONS > 0)
151 struct consdev *cp = &ofcons;
152 ofcons_cnprobe(cp);
153 if (cp->cn_pri == CN_INTERNAL) {
154 ofcons_cninit(cp);
155 cn_tab = cp;
156 return;
157 }
158 #endif /* NOFCONS */
159 #endif /* NVGA */
160 }
161 #if (NCOM > 0)
162 if (comcnattach(&isa_io_bs_tag, CONADDR, CONSPEED, COM_FREQ,
163 COM_TYPE_NORMAL, comcnmode))
164 panic("can't init serial console");
165 #endif
166 }
167