FreeBSD/Linux Kernel Cross Reference
sys/isa/syscons_isa.c
1 /*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: releng/5.1/sys/isa/syscons_isa.c 109279 2003-01-15 03:45:27Z mdodd $
27 */
28
29 #include "opt_syscons.h"
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/bus.h>
36 #include <sys/cons.h>
37 #include <sys/kbio.h>
38 #include <sys/consio.h>
39 #include <sys/sysctl.h>
40
41 #ifdef __i386__
42
43 #include <machine/clock.h>
44 #include <machine/md_var.h>
45 #include <machine/pc/bios.h>
46
47 #include <vm/vm.h>
48 #include <vm/pmap.h>
49
50 #include <i386/isa/timerreg.h>
51
52 #define BIOS_CLKED (1 << 6)
53 #define BIOS_NLKED (1 << 5)
54 #define BIOS_SLKED (1 << 4)
55 #define BIOS_ALKED 0
56
57 #endif /* __i386__ */
58
59 #include <dev/syscons/syscons.h>
60
61 #include <isa/isareg.h>
62 #include <isa/isavar.h>
63
64 static devclass_t sc_devclass;
65
66 static sc_softc_t main_softc;
67 #ifdef SC_NO_SUSPEND_VTYSWITCH
68 static int sc_no_suspend_vtswitch = 1;
69 #else
70 static int sc_no_suspend_vtswitch = 0;
71 #endif
72 static int sc_cur_scr;
73
74 TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch);
75 SYSCTL_DECL(_hw_syscons);
76 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW,
77 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
78
79 static void
80 scidentify (driver_t *driver, device_t parent)
81 {
82 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
83 }
84
85 static int
86 scprobe(device_t dev)
87 {
88 /* No pnp support */
89 if (isa_get_vendorid(dev))
90 return (ENXIO);
91
92 device_set_desc(dev, "System console");
93 return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
94 }
95
96 static int
97 scattach(device_t dev)
98 {
99 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
100 }
101
102 static int
103 scsuspend(device_t dev)
104 {
105 int retry = 10;
106 static int dummy;
107 sc_softc_t *sc;
108
109 sc = &main_softc;
110 sc_cur_scr = sc->cur_scp->index;
111
112 if (sc_no_suspend_vtswitch)
113 return (0);
114
115 do {
116 sc_switch_scr(sc, 0);
117 if (!sc->switch_in_progress) {
118 break;
119 }
120 tsleep(&dummy, 0, "scsuspend", 100);
121 } while (retry--);
122
123 return (0);
124 }
125
126 static int
127 scresume(device_t dev)
128 {
129 sc_softc_t *sc;
130
131 if (sc_no_suspend_vtswitch)
132 return (0);
133
134 sc = &main_softc;
135 sc_switch_scr(sc, sc_cur_scr);
136
137 return (0);
138 }
139
140 int
141 sc_max_unit(void)
142 {
143 return devclass_get_maxunit(sc_devclass);
144 }
145
146 sc_softc_t
147 *sc_get_softc(int unit, int flags)
148 {
149 sc_softc_t *sc;
150
151 if (unit < 0)
152 return NULL;
153 if (flags & SC_KERNEL_CONSOLE) {
154 /* FIXME: clear if it is wired to another unit! */
155 sc = &main_softc;
156 } else {
157 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
158 if (sc == NULL)
159 return NULL;
160 }
161 sc->unit = unit;
162 if (!(sc->flags & SC_INIT_DONE)) {
163 sc->keyboard = -1;
164 sc->adapter = -1;
165 sc->cursor_char = SC_CURSOR_CHAR;
166 sc->mouse_char = SC_MOUSE_CHAR;
167 }
168 return sc;
169 }
170
171 sc_softc_t
172 *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
173 {
174 sc_softc_t *sc;
175 int units;
176 int i;
177
178 sc = &main_softc;
179 if (((adp == NULL) || (adp == sc->adp))
180 && ((kbd == NULL) || (kbd == sc->kbd)))
181 return sc;
182 units = devclass_get_maxunit(sc_devclass);
183 for (i = 0; i < units; ++i) {
184 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
185 if (sc == NULL)
186 continue;
187 if (((adp == NULL) || (adp == sc->adp))
188 && ((kbd == NULL) || (kbd == sc->kbd)))
189 return sc;
190 }
191 return NULL;
192 }
193
194 int
195 sc_get_cons_priority(int *unit, int *flags)
196 {
197 int disabled;
198 const char *at;
199 int u, f;
200
201 *unit = -1;
202 for (u = 0; u < 16; u++) {
203 if ((resource_int_value(SC_DRIVER_NAME, u, "disabled",
204 &disabled) == 0) && disabled)
205 continue;
206 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
207 continue;
208 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
209 f = 0;
210 if (f & SC_KERNEL_CONSOLE) {
211 /* the user designates this unit to be the console */
212 *unit = u;
213 *flags = f;
214 break;
215 }
216 if (*unit < 0) {
217 /* ...otherwise remember the first found unit */
218 *unit = u;
219 *flags = f;
220 }
221 }
222 if (*unit < 0)
223 return CN_DEAD;
224 #if 0
225 return ((*flags & SC_KERNEL_CONSOLE) ? CN_INTERNAL : CN_NORMAL);
226 #endif
227 return CN_INTERNAL;
228 }
229
230 void
231 sc_get_bios_values(bios_values_t *values)
232 {
233 #ifdef __i386__
234 u_int8_t shift;
235
236 values->cursor_start = *(u_int8_t *)BIOS_PADDRTOVADDR(0x461);
237 values->cursor_end = *(u_int8_t *)BIOS_PADDRTOVADDR(0x460);
238 shift = *(u_int8_t *)BIOS_PADDRTOVADDR(0x417);
239 values->shift_state = ((shift & BIOS_CLKED) ? CLKED : 0)
240 | ((shift & BIOS_NLKED) ? NLKED : 0)
241 | ((shift & BIOS_SLKED) ? SLKED : 0)
242 | ((shift & BIOS_ALKED) ? ALKED : 0);
243 values->bell_pitch = BELL_PITCH;
244 #else /* !__i386__ */
245 values->cursor_start = 0;
246 values->cursor_end = 32;
247 values->shift_state = 0;
248 values->bell_pitch = BELL_PITCH;
249 #endif /* __i386__ */
250 }
251
252 int
253 sc_tone(int herz)
254 {
255 #ifdef __i386__
256 int pitch;
257
258 if (herz) {
259 /* set command for counter 2, 2 byte write */
260 if (acquire_timer2(TIMER_16BIT | TIMER_SQWAVE))
261 return EBUSY;
262 /* set pitch */
263 pitch = timer_freq/herz;
264 outb(TIMER_CNTR2, pitch);
265 outb(TIMER_CNTR2, pitch >> 8);
266 /* enable counter 2 output to speaker */
267 outb(IO_PPI, inb(IO_PPI) | 3);
268 } else {
269 /* disable counter 2 output to speaker */
270 outb(IO_PPI, inb(IO_PPI) & 0xFC);
271 release_timer2();
272 }
273 #endif /* __i386__ */
274
275 return 0;
276 }
277
278 static device_method_t sc_methods[] = {
279 DEVMETHOD(device_identify, scidentify),
280 DEVMETHOD(device_probe, scprobe),
281 DEVMETHOD(device_attach, scattach),
282 DEVMETHOD(device_suspend, scsuspend),
283 DEVMETHOD(device_resume, scresume),
284 { 0, 0 }
285 };
286
287 static driver_t sc_driver = {
288 SC_DRIVER_NAME,
289 sc_methods,
290 sizeof(sc_softc_t),
291 };
292
293 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);
Cache object: 2ae1be81e730270485b80a9be44db3b1
|