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