]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/pc98/cbus/syscons_cbus.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / pc98 / cbus / syscons_cbus.c
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  * $FreeBSD$
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/consio.h>
38 #include <sys/sysctl.h>
39
40 #include <machine/clock.h>
41
42 #include <pc98/pc98/pc98_machdep.h>
43
44 #include <dev/syscons/syscons.h>
45
46 #include <isa/isavar.h>
47
48 static devclass_t       sc_devclass;
49
50 static sc_softc_t main_softc;
51 #ifdef SC_NO_SUSPEND_VTYSWITCH
52 static int sc_no_suspend_vtswitch = 1;
53 #else
54 static int sc_no_suspend_vtswitch = 0;
55 #endif
56 static int sc_cur_scr;
57
58 TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch);
59 SYSCTL_DECL(_hw_syscons);
60 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW,
61         &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
62
63 static void
64 scidentify (driver_t *driver, device_t parent)
65 {
66         BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
67 }
68
69 static int
70 scprobe(device_t dev)
71 {
72         /* No pnp support */
73         if (isa_get_vendorid(dev))
74                 return (ENXIO);
75
76         device_set_desc(dev, "System console");
77         return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
78 }
79
80 static int
81 scattach(device_t dev)
82 {
83         return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
84 }
85
86 static int
87 scsuspend(device_t dev)
88 {
89         int             retry = 10;
90         sc_softc_t      *sc;
91
92         sc = &main_softc;
93
94         if (sc->cur_scp == NULL)
95                 return (0);
96
97         sc_cur_scr = sc->cur_scp->index;
98
99         if (sc_no_suspend_vtswitch)
100                 return (0);
101
102         do {
103                 sc_switch_scr(sc, 0);
104                 if (!sc->switch_in_progress) {
105                         break;
106                 }
107                 pause("scsuspend", hz);
108         } while (retry--);
109
110         return (0);
111 }
112
113 static int
114 scresume(device_t dev)
115 {
116         sc_softc_t      *sc;
117
118         if (sc_no_suspend_vtswitch)
119                 return (0);
120
121         sc = &main_softc;
122         sc_switch_scr(sc, sc_cur_scr);
123
124         return (0);
125 }
126
127 int
128 sc_max_unit(void)
129 {
130         return devclass_get_maxunit(sc_devclass);
131 }
132
133 sc_softc_t
134 *sc_get_softc(int unit, int flags)
135 {
136         sc_softc_t *sc;
137
138         if (unit < 0)
139                 return NULL;
140         if (flags & SC_KERNEL_CONSOLE) {
141                 /* FIXME: clear if it is wired to another unit! */
142                 sc = &main_softc;
143         } else {
144                 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
145                 if (sc == NULL)
146                         return NULL;
147         }
148         sc->unit = unit;
149         if (!(sc->flags & SC_INIT_DONE)) {
150                 sc->keyboard = -1;
151                 sc->adapter = -1;
152                 sc->mouse_char = SC_MOUSE_CHAR;
153         }
154         return sc;
155 }
156
157 sc_softc_t
158 *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
159 {
160         sc_softc_t *sc;
161         int units;
162         int i;
163
164         sc = &main_softc;
165         if (((adp == NULL) || (adp == sc->adp))
166             && ((kbd == NULL) || (kbd == sc->kbd)))
167                 return sc;
168         units = devclass_get_maxunit(sc_devclass);
169         for (i = 0; i < units; ++i) {
170                 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
171                 if (sc == NULL)
172                         continue;
173                 if (((adp == NULL) || (adp == sc->adp))
174                     && ((kbd == NULL) || (kbd == sc->kbd)))
175                         return sc;
176         }
177         return NULL;
178 }
179
180 int
181 sc_get_cons_priority(int *unit, int *flags)
182 {
183         const char *at;
184         int u, f;
185
186         *unit = -1;
187         for (u = 0; u < 16; u++) {
188                 if (resource_disabled(SC_DRIVER_NAME, u))
189                         continue;
190                 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
191                         continue;
192                 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
193                         f = 0;
194                 if (f & SC_KERNEL_CONSOLE) {
195                         /* the user designates this unit to be the console */
196                         *unit = u;
197                         *flags = f;
198                         break;
199                 }
200                 if (*unit < 0) {
201                         /* ...otherwise remember the first found unit */
202                         *unit = u;
203                         *flags = f;
204                 }
205         }
206         if (*unit < 0) {
207                 *unit = 0;
208                 *flags = 0;
209         }
210         return CN_INTERNAL;
211 }
212
213 void
214 sc_get_bios_values(bios_values_t *values)
215 {
216         values->cursor_start = 15;
217         values->cursor_end = 16;
218         values->shift_state = 0;
219         values->bell_pitch = BELL_PITCH;
220 }
221
222 int
223 sc_tone(int herz)
224 {
225
226         if (herz) {
227                 if (timer_spkr_acquire())
228                         return EBUSY;
229                 timer_spkr_setfreq(herz);
230         } else {
231                 timer_spkr_release();
232         }
233         return 0;
234 }
235
236 static device_method_t sc_methods[] = {
237         DEVMETHOD(device_identify,      scidentify),
238         DEVMETHOD(device_probe,         scprobe),
239         DEVMETHOD(device_attach,        scattach),
240         DEVMETHOD(device_suspend,       scsuspend),
241         DEVMETHOD(device_resume,        scresume),
242         { 0, 0 }
243 };
244
245 static driver_t sc_driver = {
246         SC_DRIVER_NAME,
247         sc_methods,
248         sizeof(sc_softc_t),
249 };
250
251 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);