syscons_cbus.c revision 109303
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 109303 2003-01-15 13:12:12Z nyan $ 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.h> 43#include <pc98/pc98/pc98_machdep.h> 44 45#include <dev/syscons/syscons.h> 46 47#include <i386/isa/timerreg.h> 48 49#include <isa/isavar.h> 50 51static devclass_t sc_devclass; 52 53static sc_softc_t main_softc; 54#ifdef SC_NO_SUSPEND_VTYSWITCH 55static int sc_no_suspend_vtswitch = 1; 56#else 57static int sc_no_suspend_vtswitch = 0; 58#endif 59static int sc_cur_scr; 60 61TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch); 62SYSCTL_DECL(_hw_syscons); 63SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW, 64 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend."); 65 66static void 67scidentify (driver_t *driver, device_t parent) 68{ 69 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0); 70} 71 72static int 73scprobe(device_t dev) 74{ 75 /* No pnp support */ 76 if (isa_get_vendorid(dev)) 77 return (ENXIO); 78 79 device_set_desc(dev, "System console"); 80 return sc_probe_unit(device_get_unit(dev), device_get_flags(dev)); 81} 82 83static int 84scattach(device_t dev) 85{ 86 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev)); 87} 88 89static int 90scsuspend(device_t dev) 91{ 92 int retry = 10; 93 static int dummy; 94 sc_softc_t *sc; 95 96 sc = &main_softc; 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 tsleep(&dummy, 0, "scsuspend", 100); 108 } while (retry--); 109 110 return (0); 111} 112 113static int 114scresume(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 127int 128sc_max_unit(void) 129{ 130 return devclass_get_maxunit(sc_devclass); 131} 132 133sc_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 157sc_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 180int 181sc_get_cons_priority(int *unit, int *flags) 182{ 183 int disabled; 184 const char *at; 185 int u, f; 186 187 *unit = -1; 188 for (u = 0; u < 16; u++) { 189 if ((resource_int_value(SC_DRIVER_NAME, u, "disabled", 190 &disabled) == 0) && disabled) 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 int pitch; 229 230 if (herz) { 231 /* enable counter 1 */ 232 outb(0x35, inb(0x35) & 0xf7); 233 /* set command for counter 1, 2 byte write */ 234 if (acquire_timer1(TIMER_16BIT | TIMER_SQWAVE)) 235 return EBUSY; 236 /* set pitch */ 237 pitch = timer_freq/herz; 238 outb(TIMER_CNTR1, pitch); 239 outb(TIMER_CNTR1, pitch >> 8); 240 } else { 241 /* disable counter 1 */ 242 outb(0x35, inb(0x35) | 0x08); 243 release_timer1(); 244 } 245 return 0; 246} 247 248static device_method_t sc_methods[] = { 249 DEVMETHOD(device_identify, scidentify), 250 DEVMETHOD(device_probe, scprobe), 251 DEVMETHOD(device_attach, scattach), 252 DEVMETHOD(device_suspend, scsuspend), 253 DEVMETHOD(device_resume, scresume), 254 { 0, 0 } 255}; 256 257static driver_t sc_driver = { 258 SC_DRIVER_NAME, 259 sc_methods, 260 sizeof(sc_softc_t), 261}; 262 263DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); 264