2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_syscons.h"
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
39 #include <sys/consio.h>
40 #include <sys/sysctl.h>
44 #include <machine/clock.h>
45 #include <machine/md_var.h>
46 #include <machine/pc/bios.h>
50 #include <vm/vm_param.h>
52 #include <i386/isa/timerreg.h>
54 #define BIOS_CLKED (1 << 6)
55 #define BIOS_NLKED (1 << 5)
56 #define BIOS_SLKED (1 << 4)
61 #include <dev/syscons/syscons.h>
63 #include <isa/isareg.h>
64 #include <isa/isavar.h>
66 static devclass_t sc_devclass;
68 static sc_softc_t main_softc;
69 #ifdef SC_NO_SUSPEND_VTYSWITCH
70 static int sc_no_suspend_vtswitch = 1;
72 static int sc_no_suspend_vtswitch = 0;
74 static int sc_cur_scr;
76 TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch);
77 SYSCTL_DECL(_hw_syscons);
78 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW,
79 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
82 scidentify (driver_t *driver, device_t parent)
84 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
91 if (isa_get_vendorid(dev))
94 device_set_desc(dev, "System console");
95 return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
99 scattach(device_t dev)
101 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
105 scsuspend(device_t dev)
113 if (sc->cur_scp == NULL)
116 sc_cur_scr = sc->cur_scp->index;
118 if (sc_no_suspend_vtswitch)
122 sc_switch_scr(sc, 0);
123 if (!sc->switch_in_progress) {
126 tsleep(&dummy, 0, "scsuspend", 100);
133 scresume(device_t dev)
137 if (sc_no_suspend_vtswitch)
141 sc_switch_scr(sc, sc_cur_scr);
149 return devclass_get_maxunit(sc_devclass);
153 *sc_get_softc(int unit, int flags)
159 if (flags & SC_KERNEL_CONSOLE) {
160 /* FIXME: clear if it is wired to another unit! */
163 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
168 if (!(sc->flags & SC_INIT_DONE)) {
171 sc->cursor_char = SC_CURSOR_CHAR;
172 sc->mouse_char = SC_MOUSE_CHAR;
178 *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
185 if (((adp == NULL) || (adp == sc->adp))
186 && ((kbd == NULL) || (kbd == sc->kbd)))
188 units = devclass_get_maxunit(sc_devclass);
189 for (i = 0; i < units; ++i) {
190 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
193 if (((adp == NULL) || (adp == sc->adp))
194 && ((kbd == NULL) || (kbd == sc->kbd)))
201 sc_get_cons_priority(int *unit, int *flags)
207 for (u = 0; u < 16; u++) {
208 if (resource_disabled(SC_DRIVER_NAME, u))
210 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
212 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
214 if (f & SC_KERNEL_CONSOLE) {
215 /* the user designates this unit to be the console */
221 /* ...otherwise remember the first found unit */
229 return ((*flags & SC_KERNEL_CONSOLE) ? CN_INTERNAL : CN_NORMAL);
235 sc_get_bios_values(bios_values_t *values)
240 values->cursor_start = *(u_int8_t *)BIOS_PADDRTOVADDR(0x461);
241 values->cursor_end = *(u_int8_t *)BIOS_PADDRTOVADDR(0x460);
242 shift = *(u_int8_t *)BIOS_PADDRTOVADDR(0x417);
243 values->shift_state = ((shift & BIOS_CLKED) ? CLKED : 0)
244 | ((shift & BIOS_NLKED) ? NLKED : 0)
245 | ((shift & BIOS_SLKED) ? SLKED : 0)
246 | ((shift & BIOS_ALKED) ? ALKED : 0);
247 values->bell_pitch = BELL_PITCH;
248 #else /* !__i386__ */
249 values->cursor_start = 0;
250 values->cursor_end = 32;
251 values->shift_state = 0;
252 values->bell_pitch = BELL_PITCH;
253 #endif /* __i386__ */
263 /* set command for counter 2, 2 byte write */
264 if (acquire_timer2(TIMER_16BIT | TIMER_SQWAVE))
267 pitch = timer_freq/herz;
268 outb(TIMER_CNTR2, pitch);
269 outb(TIMER_CNTR2, pitch >> 8);
270 /* enable counter 2 output to speaker */
271 outb(IO_PPI, inb(IO_PPI) | 3);
273 /* disable counter 2 output to speaker */
274 outb(IO_PPI, inb(IO_PPI) & 0xFC);
277 #endif /* __i386__ */
282 static device_method_t sc_methods[] = {
283 DEVMETHOD(device_identify, scidentify),
284 DEVMETHOD(device_probe, scprobe),
285 DEVMETHOD(device_attach, scattach),
286 DEVMETHOD(device_suspend, scsuspend),
287 DEVMETHOD(device_resume, scresume),
291 static driver_t sc_driver = {
297 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);