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