syscons - Untangle device attachement from isa?, attach to nexus? instead.
[dragonfly.git] / sys / dev / misc / syscons / syscons_nexus.c
blob7a93d83571057556fe6e429fdc39e6ef9838403b
1 /*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
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.
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.
26 * $FreeBSD: src/sys/isa/syscons_isa.c,v 1.11.2.2 2001/08/01 10:42:28 yokota Exp $
29 #include "opt_syscons.h"
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>
39 #include <machine/console.h>
40 #include <machine/framebuffer.h>
42 #include <dev/misc/syscons/syscons.h>
44 static devclass_t sc_devclass;
46 static void scidentify(driver_t *driver, device_t parent);
47 static int scprobe(device_t dev);
48 static int scattach(device_t dev);
50 static device_method_t sc_methods[] = {
51 DEVMETHOD(device_identify, scidentify),
52 DEVMETHOD(device_probe, scprobe),
53 DEVMETHOD(device_attach, scattach),
54 DEVMETHOD_END
57 static driver_t sc_driver = {
58 SC_DRIVER_NAME,
59 sc_methods,
60 sizeof(sc_softc_t),
63 static sc_softc_t main_softc;
65 static void
66 scidentify(driver_t *driver, device_t parent)
68 device_t child;
69 int i, u;
70 int f;
72 for (i = -1; (i = resource_locate(i, SC_DRIVER_NAME)) >= 0;) {
73 u = resource_query_unit(i);
74 if (u < 0)
75 continue;
76 if (resource_disabled(SC_DRIVER_NAME, u))
77 continue;
78 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
79 f = 0;
80 child = BUS_ADD_CHILD(parent, parent, 0, "sc", u);
81 if (child == NULL)
82 panic("%s", __func__);
83 device_set_flags(child, f);
87 static int
88 scprobe(device_t dev)
90 device_set_desc(dev, "System console");
91 return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
94 static int
95 scattach(device_t dev)
97 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
101 sc_max_unit(void)
103 return devclass_get_maxunit(sc_devclass);
106 sc_softc_t *
107 sc_get_softc(int unit, int flags)
109 sc_softc_t *sc;
111 if (unit < 0)
112 return NULL;
113 if (flags & SC_KERNEL_CONSOLE) {
114 /* FIXME: clear if it is wired to another unit! */
115 sc = &main_softc;
116 } else {
117 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
118 if (sc == NULL)
119 return NULL;
121 sc->unit = unit;
122 if (!(sc->flags & SC_INIT_DONE)) {
123 sc->keyboard = -1;
124 sc->adapter = -1;
125 sc->cursor_char = SC_CURSOR_CHAR;
126 sc->mouse_char = SC_MOUSE_CHAR;
128 return sc;
131 sc_softc_t *
132 sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
134 sc_softc_t *sc;
135 int units;
136 int i;
138 sc = &main_softc;
139 if (((adp == NULL) || (adp == sc->adp))
140 && ((kbd == NULL) || (kbd == sc->kbd)))
141 return sc;
142 units = devclass_get_maxunit(sc_devclass);
143 for (i = 0; i < units; ++i) {
144 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
145 if (sc == NULL)
146 continue;
147 if (((adp == NULL) || (adp == sc->adp))
148 && ((kbd == NULL) || (kbd == sc->kbd)))
149 return sc;
151 return NULL;
155 sc_get_cons_priority(int *unit, int *flags)
157 int u, f;
158 int i;
159 int have_efi_fb = (probe_efi_fb(1) == 0);
161 *unit = -1;
162 for (i = -1; (i = resource_locate(i, SC_DRIVER_NAME)) >= 0;) {
163 u = resource_query_unit(i);
164 if (resource_disabled(SC_DRIVER_NAME, u))
165 continue;
166 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
167 f = 0;
168 /* We prefer the EFI Framebuffer over other video devices */
169 if (have_efi_fb && !(f & SC_EFI_FB))
170 continue;
171 if (f & SC_KERNEL_CONSOLE) {
172 /* the user designates this unit to be the console */
173 *unit = u;
174 *flags = f;
175 break;
177 if (*unit < 0) {
178 /* ...otherwise remember the first found unit */
179 *unit = u;
180 *flags = f;
183 if ((i < 0) && (*unit < 0))
184 return CN_DEAD;
185 if (!have_efi_fb)
186 *flags &= ~SC_EFI_FB;
187 #if 0
188 return ((*flags & SC_KERNEL_CONSOLE) ? CN_INTERNAL : CN_NORMAL);
189 #endif
190 return CN_INTERNAL;
193 void
194 sc_get_bios_values(bios_values_t *values)
196 values->cursor_start = 0;
197 values->cursor_end = 32;
198 values->shift_state = 0;
199 values->bell_pitch = BELL_PITCH;
203 sc_tone(int hertz)
205 return EBUSY;
206 #if 0
207 /* XXX use sound device if available */
208 return 0;
209 #endif
212 DRIVER_MODULE(sc, nexus, sc_driver, sc_devclass, NULL, NULL);