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