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>
42 #if defined(__i386__) || defined(__amd64__)
44 #include <machine/clock.h>
45 #include <machine/md_var.h>
46 #include <machine/pc/bios.h>
50 #include <vm/vm_param.h>
52 #define BIOS_CLKED (1 << 6)
53 #define BIOS_NLKED (1 << 5)
54 #define BIOS_SLKED (1 << 4)
59 #include <dev/syscons/syscons.h>
61 #include <isa/isavar.h>
63 static devclass_t sc_devclass;
65 static sc_softc_t main_softc;
68 scidentify(driver_t *driver, device_t parent)
71 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
79 if (isa_get_vendorid(dev))
82 device_set_desc(dev, "System console");
83 return (sc_probe_unit(device_get_unit(dev), device_get_flags(dev)));
87 scattach(device_t dev)
90 return (sc_attach_unit(device_get_unit(dev), device_get_flags(dev) |
98 return (devclass_get_maxunit(sc_devclass));
102 *sc_get_softc(int unit, int flags)
108 if ((flags & SC_KERNEL_CONSOLE) != 0) {
109 /* FIXME: clear if it is wired to another unit! */
112 sc = device_get_softc(devclass_get_device(sc_devclass, unit));
117 if ((sc->flags & SC_INIT_DONE) == 0) {
120 sc->cursor_char = SC_CURSOR_CHAR;
121 sc->mouse_char = SC_MOUSE_CHAR;
127 *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
134 if ((adp == NULL || adp == sc->adp) &&
135 (kbd == NULL || kbd == sc->kbd))
137 units = devclass_get_maxunit(sc_devclass);
138 for (i = 0; i < units; ++i) {
139 sc = device_get_softc(devclass_get_device(sc_devclass, i));
142 if ((adp == NULL || adp == sc->adp) &&
143 (kbd == NULL || kbd == sc->kbd))
150 sc_get_cons_priority(int *unit, int *flags)
156 for (u = 0; u < 16; u++) {
157 if (resource_disabled(SC_DRIVER_NAME, u))
159 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
161 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
163 if (f & SC_KERNEL_CONSOLE) {
164 /* the user designates this unit to be the console */
170 /* ...otherwise remember the first found unit */
180 return ((*flags & SC_KERNEL_CONSOLE) != 0 ? CN_INTERNAL : CN_NORMAL);
182 return (CN_INTERNAL);
186 sc_get_bios_values(bios_values_t *values)
188 #if defined(__i386__) || defined(__amd64__)
191 shift = *(uint8_t *)BIOS_PADDRTOVADDR(0x417);
192 values->shift_state = ((shift & BIOS_CLKED) != 0 ? CLKED : 0) |
193 ((shift & BIOS_NLKED) != 0 ? NLKED : 0) |
194 ((shift & BIOS_SLKED) != 0 ? SLKED : 0) |
195 ((shift & BIOS_ALKED) != 0 ? ALKED : 0);
197 values->bell_pitch = BELL_PITCH;
204 #if defined(HAS_TIMER_SPKR)
206 if (timer_spkr_acquire())
208 timer_spkr_setfreq(herz);
210 timer_spkr_release();
216 static device_method_t sc_methods[] = {
217 DEVMETHOD(device_identify, scidentify),
218 DEVMETHOD(device_probe, scprobe),
219 DEVMETHOD(device_attach, scattach),
223 static driver_t sc_driver = {
229 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);