syscons_cbus.c revision 67370
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 67370 2000-10-20 10:35:44Z kato $ 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 78scresume(device_t dev) 79{ 80 return sc_resume_unit(device_get_unit(dev)); 81} 82 83int 84sc_max_unit(void) 85{ 86 return devclass_get_maxunit(sc_devclass); 87} 88 89sc_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->mouse_char = SC_MOUSE_CHAR; 109 } 110 return sc; 111} 112 113sc_softc_t 114*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd) 115{ 116 sc_softc_t *sc; 117 int units; 118 int i; 119 120 sc = &main_softc; 121 if (((adp == NULL) || (adp == sc->adp)) 122 && ((kbd == NULL) || (kbd == sc->kbd))) 123 return sc; 124 units = devclass_get_maxunit(sc_devclass); 125 for (i = 0; i < units; ++i) { 126 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i)); 127 if (sc == NULL) 128 continue; 129 if (((adp == NULL) || (adp == sc->adp)) 130 && ((kbd == NULL) || (kbd == sc->kbd))) 131 return sc; 132 } 133 return NULL; 134} 135 136int 137sc_get_cons_priority(int *unit, int *flags) 138{ 139 int disabled; 140 char *at; 141 int u, f; 142 143 *unit = -1; 144 for (u = 0; u < 16; u++) { 145 if ((resource_int_value(SC_DRIVER_NAME, u, "disabled", 146 &disabled) == 0) && disabled) 147 continue; 148 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0) 149 continue; 150 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0) 151 f = 0; 152 if (f & SC_KERNEL_CONSOLE) { 153 /* the user designates this unit to be the console */ 154 *unit = u; 155 *flags = f; 156 break; 157 } 158 if (*unit < 0) { 159 /* ...otherwise remember the first found unit */ 160 *unit = u; 161 *flags = f; 162 } 163 } 164 if (*unit < 0) 165 return CN_DEAD; 166 return CN_INTERNAL; 167} 168 169void 170sc_get_bios_values(bios_values_t *values) 171{ 172 values->cursor_start = 15; 173 values->cursor_end = 16; 174 values->shift_state = 0; 175 if (pc98_machine_type & M_8M) 176 values->bell_pitch = BELL_PITCH_8M; 177 else 178 values->bell_pitch = BELL_PITCH_5M; 179} 180 181int 182sc_tone(int herz) 183{ 184 int pitch; 185 186 if (herz) { 187 /* enable counter 1 */ 188 outb(0x35, inb(0x35) & 0xf7); 189 /* set command for counter 1, 2 byte write */ 190 if (acquire_timer1(TIMER_16BIT | TIMER_SQWAVE)) 191 return EBUSY; 192 /* set pitch */ 193 pitch = timer_freq/herz; 194 outb(TIMER_CNTR1, pitch); 195 outb(TIMER_CNTR1, pitch >> 8); 196 } else { 197 /* disable counter 1 */ 198 outb(0x35, inb(0x35) | 0x08); 199 release_timer1(); 200 } 201 return 0; 202} 203 204static device_method_t sc_methods[] = { 205 DEVMETHOD(device_identify, scidentify), 206 DEVMETHOD(device_probe, scprobe), 207 DEVMETHOD(device_attach, scattach), 208 DEVMETHOD(device_resume, scresume), 209 { 0, 0 } 210}; 211 212static driver_t sc_driver = { 213 SC_DRIVER_NAME, 214 sc_methods, 215 sizeof(sc_softc_t), 216}; 217 218DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); 219