1 /*-
2 * Copyright (c) 1999 FreeBSD(98) Porting Team.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include "opt_syscons.h"
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/bus.h>
37 #include <sys/cons.h>
38 #include <sys/consio.h>
39 #include <sys/sysctl.h>
40
41 #include <machine/clock.h>
42
43 #include <pc98/pc98/pc98_machdep.h>
44
45 #include <dev/syscons/syscons.h>
46
47 #include <isa/isavar.h>
48
49 static devclass_t sc_devclass;
50
51 static sc_softc_t main_softc;
52
53 static void
54 scidentify(driver_t *driver, device_t parent)
55 {
56
57 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
58 }
59
60 static int
61 scprobe(device_t dev)
62 {
63
64 /* No pnp support */
65 if (isa_get_vendorid(dev))
66 return (ENXIO);
67
68 device_set_desc(dev, "System console");
69 return (sc_probe_unit(device_get_unit(dev), device_get_flags(dev)));
70 }
71
72 static int
73 scattach(device_t dev)
74 {
75
76 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
77 }
78
79 int
80 sc_max_unit(void)
81 {
82
83 return (devclass_get_maxunit(sc_devclass));
84 }
85
86 sc_softc_t
87 *sc_get_softc(int unit, int flags)
88 {
89 sc_softc_t *sc;
90
91 if (unit < 0)
92 return (NULL);
93 if ((flags & SC_KERNEL_CONSOLE) != 0) {
94 /* FIXME: clear if it is wired to another unit! */
95 sc = &main_softc;
96 } else {
97 sc = device_get_softc(devclass_get_device(sc_devclass, unit));
98 if (sc == NULL)
99 return (NULL);
100 }
101 sc->unit = unit;
102 if ((sc->flags & SC_INIT_DONE) == 0) {
103 sc->keyboard = -1;
104 sc->adapter = -1;
105 sc->mouse_char = SC_MOUSE_CHAR;
106 }
107 return (sc);
108 }
109
110 sc_softc_t
111 *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
112 {
113 sc_softc_t *sc;
114 int i;
115 int units;
116
117 sc = &main_softc;
118 if ((adp == NULL || adp == sc->adp) &&
119 (kbd == NULL || kbd == sc->kbd))
120 return (sc);
121 units = devclass_get_maxunit(sc_devclass);
122 for (i = 0; i < units; ++i) {
123 sc = device_get_softc(devclass_get_device(sc_devclass, i));
124 if (sc == NULL)
125 continue;
126 if ((adp == NULL || adp == sc->adp) &&
127 (kbd == NULL || kbd == sc->kbd))
128 return (sc);
129 }
130 return (NULL);
131 }
132
133 int
134 sc_get_cons_priority(int *unit, int *flags)
135 {
136 const char *at;
137 int f, u;
138
139 *unit = -1;
140 for (u = 0; u < 16; u++) {
141 if (resource_disabled(SC_DRIVER_NAME, u))
142 continue;
143 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
144 continue;
145 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
146 f = 0;
147 if (f & SC_KERNEL_CONSOLE) {
148 /* the user designates this unit to be the console */
149 *unit = u;
150 *flags = f;
151 break;
152 }
153 if (*unit < 0) {
154 /* ...otherwise remember the first found unit */
155 *unit = u;
156 *flags = f;
157 }
158 }
159 if (*unit < 0) {
160 *unit = 0;
161 *flags = 0;
162 }
163 return (CN_INTERNAL);
164 }
165
166 void
167 sc_get_bios_values(bios_values_t *values)
168 {
169 values->cursor_start = 15;
170 values->cursor_end = 16;
171 values->shift_state = 0;
172 values->bell_pitch = BELL_PITCH;
173 }
174
175 int
176 sc_tone(int herz)
177 {
178
179 if (herz) {
180 if (timer_spkr_acquire())
181 return (EBUSY);
182 timer_spkr_setfreq(herz);
183 } else
184 timer_spkr_release();
185
186 return (0);
187 }
188
189 static device_method_t sc_methods[] = {
190 DEVMETHOD(device_identify, scidentify),
191 DEVMETHOD(device_probe, scprobe),
192 DEVMETHOD(device_attach, scattach),
193 { 0, 0 }
194 };
195
196 static driver_t sc_driver = {
197 SC_DRIVER_NAME,
198 sc_methods,
199 sizeof(sc_softc_t),
200 };
201
202 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);
Cache object: 4f6b0f2f58c1ae9e42903280a4c11c60
|