1 /* $OpenBSD: wscons_machdep.c,v 1.20 2023/01/30 10:49:05 jsg Exp $ */
2
3 /*
4 * Copyright (c) 2001 Aaron Campbell
5 * 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 OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/conf.h>
32
33 #include <machine/bus.h>
34
35 #include <dev/cons.h>
36
37 #include "vga.h"
38 #include "pcdisplay.h"
39 #if (NVGA > 0) || (NPCDISPLAY > 0)
40 #include <dev/ic/mc6845reg.h>
41 #include <dev/ic/pcdisplayvar.h>
42 #if (NVGA > 0)
43 #include <dev/ic/vgareg.h>
44 #include <dev/ic/vgavar.h>
45 #endif
46 #if (NPCDISPLAY > 0)
47 #include <dev/isa/pcdisplayvar.h>
48 #endif
49 #endif
50
51 #include "wsdisplay.h"
52 #if NWSDISPLAY > 0
53 #include <dev/wscons/wsdisplayvar.h>
54 #endif
55
56 #include "pckbc.h"
57 #if (NPCKBC > 0)
58 #include <dev/isa/isareg.h>
59 #include <dev/ic/i8042reg.h>
60 #include <dev/ic/pckbcvar.h>
61 #endif
62 #include "ukbd.h"
63 #if (NUKBD > 0)
64 #include <dev/usb/ukbdvar.h>
65 #endif
66 #include "wskbd.h"
67 #if NWSKBD > 0
68 #include <dev/wscons/wskbdvar.h>
69 #endif
70
71 void wscn_video_init(void);
72 void wscn_input_init(int);
73
74 cons_decl(ws);
75
76 void
wscnprobe(struct consdev * cp)77 wscnprobe(struct consdev *cp)
78 {
79 int maj;
80
81 /* locate the major number */
82 for (maj = 0; maj < nchrdev; maj++) {
83 if (cdevsw[maj].d_open == wsdisplayopen)
84 break;
85 }
86
87 if (maj == nchrdev) {
88 /* we are not in cdevsw[], give up */
89 panic("wsdisplay is not in cdevsw[]");
90 }
91
92 cp->cn_dev = makedev(maj, 0);
93 cp->cn_pri = CN_MIDPRI;
94 }
95
96 void
wscninit(struct consdev * cp)97 wscninit(struct consdev *cp)
98 {
99 static int initted = 0;
100
101 if (initted)
102 return;
103 initted = 1;
104
105 wscn_video_init();
106 wscn_input_init(0);
107 }
108
109 void
wscnputc(dev_t dev,int i)110 wscnputc(dev_t dev, int i)
111 {
112 wsdisplay_cnputc(dev, i);
113 }
114
115 int
wscngetc(dev_t dev)116 wscngetc(dev_t dev)
117 {
118 return (wskbd_cngetc(dev));
119 }
120
121 void
wscnpollc(dev_t dev,int on)122 wscnpollc(dev_t dev, int on)
123 {
124 wskbd_cnpollc(dev, on);
125 }
126
127 /*
128 * Configure the display part of the console.
129 */
130 void
wscn_video_init(void)131 wscn_video_init(void)
132 {
133 #if (NVGA > 0)
134 if (vga_cnattach(I386_BUS_SPACE_IO, I386_BUS_SPACE_MEM, -1, 1) == 0)
135 return;
136 #endif
137 #if (NPCDISPLAY > 0)
138 if (pcdisplay_cnattach(I386_BUS_SPACE_IO, I386_BUS_SPACE_MEM) == 0)
139 return;
140 #endif
141 }
142
143 /*
144 * Configure the keyboard part of the console.
145 * This is tricky, because of the games USB controllers play.
146 *
147 * On a truly legacy-free design, no PS/2 keyboard controller will be
148 * found, so we'll settle for the first USB keyboard as the console
149 * input device.
150 *
151 * Otherwise, the PS/2 controller will claim console, even if no PS/2
152 * keyboard is plugged into it. This is intentional, so that a PS/2
153 * keyboard can be plugged late (even though this is theoretically not
154 * allowed, most PS/2 controllers survive this).
155 *
156 * However, if there isn't any PS/2 keyboard connector, but an USB
157 * controller in Legacy mode, the kernel will detect a PS/2 keyboard
158 * connected (while there really isn't any), until the USB controller
159 * driver attaches. At that point the ghost of the legacy keyboard
160 * flees away.
161 *
162 * The pckbc(4) driver will, however, detect that the keyboard is gone
163 * missing, and will invoke this function again, allowing a new console
164 * input device choice.
165 */
166 void
wscn_input_init(int pass)167 wscn_input_init(int pass)
168 {
169 if (pass != 0) {
170 #if NWSKBD > 0
171 wskbd_cndetach();
172 #endif
173 }
174
175 #if (NPCKBC > 0)
176 if (pass == 0 &&
177 pckbc_cnattach(I386_BUS_SPACE_IO, IO_KBD, KBCMDP, 0) == 0)
178 return;
179 #endif
180 #if (NUKBD > 0)
181 if (ukbd_cnattach() == 0)
182 return;
183 #endif
184 }
185