Merge branch 'vendor/GREP'
[dragonfly.git] / sys / bus / 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: src/sys/isa/syscons_isa.c,v 1.11.2.2 2001/08/01 10:42:28 yokota Exp $
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/systimer.h>
36 #include <sys/bus.h>
37 #include <sys/cons.h>
38
39 #include <machine/console.h>
40
41 #include <dev/misc/syscons/syscons.h>
42
43 #include "isareg.h"
44 #include "isavar.h"
45
46 static devclass_t       sc_devclass;
47
48 static int      scprobe(device_t dev);
49 static int      scattach(device_t dev);
50
51 static device_method_t sc_methods[] = {
52         DEVMETHOD(device_probe,         scprobe),
53         DEVMETHOD(device_attach,        scattach),
54         DEVMETHOD_END
55 };
56
57 static driver_t sc_driver = {
58         SC_DRIVER_NAME,
59         sc_methods,
60         sizeof(sc_softc_t),
61 };
62
63 static sc_softc_t main_softc;
64
65 static int
66 scprobe(device_t dev)
67 {
68         /* No pnp support */
69         if (isa_get_vendorid(dev))
70                 return (ENXIO);
71
72         device_set_desc(dev, "System console");
73         return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
74 }
75
76 static int
77 scattach(device_t dev)
78 {
79         return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
80 }
81
82 int
83 sc_max_unit(void)
84 {
85         return devclass_get_maxunit(sc_devclass);
86 }
87
88 sc_softc_t *
89 sc_get_softc(int unit, int flags)
90 {
91         sc_softc_t *sc;
92
93         if (unit < 0)
94                 return NULL;
95         if (flags & SC_KERNEL_CONSOLE) {
96                 /* FIXME: clear if it is wired to another unit! */
97                 sc = &main_softc;
98         } else {
99                 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
100                 if (sc == NULL)
101                         return NULL;
102         }
103         sc->unit = unit;
104         if (!(sc->flags & SC_INIT_DONE)) {
105                 sc->keyboard = -1;
106                 sc->adapter = -1;
107                 sc->cursor_char = SC_CURSOR_CHAR;
108                 sc->mouse_char = SC_MOUSE_CHAR;
109         }
110         return sc;
111 }
112
113 sc_softc_t *
114 sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
115 {
116         sc_softc_t *sc;
117         int units;
118         int i;
119
120         sc = &main_softc;
121         if (((adp == NULL) || (adp == sc->adp))
122             && ((kbd == NULL) || (kbd == sc->kbd)))
123                 return sc;
124         units = devclass_get_maxunit(sc_devclass);
125         for (i = 0; i < units; ++i) {
126                 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
127                 if (sc == NULL)
128                         continue;
129                 if (((adp == NULL) || (adp == sc->adp))
130                     && ((kbd == NULL) || (kbd == sc->kbd)))
131                         return sc;
132         }
133         return NULL;
134 }
135
136 int
137 sc_get_cons_priority(int *unit, int *flags)
138 {
139         int disabled;
140         int u, f;
141         int i;
142
143         *unit = -1;
144         for (i = -1; (i = resource_locate(i, SC_DRIVER_NAME)) >= 0;) {
145                 u = resource_query_unit(i);
146                 if ((resource_int_value(SC_DRIVER_NAME, u, "disabled",
147                                         &disabled) == 0) && disabled)
148                         continue;
149                 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
150                         f = 0;
151                 if (f & SC_KERNEL_CONSOLE) {
152                         /* the user designates this unit to be the console */
153                         *unit = u;
154                         *flags = f;
155                         break;
156                 }
157                 if (*unit < 0) {
158                         /* ...otherwise remember the first found unit */
159                         *unit = u;
160                         *flags = f;
161                 }
162         }
163         if ((i < 0) && (*unit < 0))
164                 return CN_DEAD;
165 #if 0
166         return ((*flags & SC_KERNEL_CONSOLE) ? CN_INTERNAL : CN_NORMAL);
167 #endif
168         return CN_INTERNAL;
169 }
170
171 void
172 sc_get_bios_values(bios_values_t *values)
173 {
174         values->cursor_start = 0;
175         values->cursor_end = 32;
176         values->shift_state = 0;
177         values->bell_pitch = BELL_PITCH;
178 }
179
180 int
181 sc_tone(int hertz)
182 {
183         return EBUSY;
184 #if 0
185         /* XXX use sound device if available */
186         return 0;
187 #endif
188 }
189
190 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, NULL, NULL);