syscons_cbus.c revision 56337
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 56337 2000-01-20 15:16:49Z kato $ 27 */ 28 29#include "sc.h" 30#include "opt_syscons.h" 31 32#if NSC > 0 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/module.h> 38#include <sys/bus.h> 39 40#include <sys/cons.h> 41#include <machine/console.h> 42#include <machine/clock.h> 43 44#include <pc98/pc98/pc98.h> 45#include <pc98/pc98/pc98_machdep.h> 46 47#include <dev/syscons/syscons.h> 48 49#include <i386/isa/timerreg.h> 50 51#include <isa/isavar.h> 52 53static devclass_t sc_devclass; 54 55static int scprobe(device_t dev); 56static int scattach(device_t dev); 57static int scresume(device_t dev); 58 59static device_method_t sc_methods[] = { 60 DEVMETHOD(device_probe, scprobe), 61 DEVMETHOD(device_attach, scattach), 62 DEVMETHOD(device_resume, scresume), 63 { 0, 0 } 64}; 65 66static driver_t sc_driver = { 67 SC_DRIVER_NAME, 68 sc_methods, 69 sizeof(sc_softc_t), 70}; 71 72static sc_softc_t main_softc; 73 74static int 75scprobe(device_t dev) 76{ 77 /* No pnp support */ 78 if (isa_get_vendorid(dev)) 79 return (ENXIO); 80 81 device_set_desc(dev, "System console"); 82 return sc_probe_unit(device_get_unit(dev), device_get_flags(dev)); 83} 84 85static int 86scattach(device_t dev) 87{ 88 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev)); 89} 90 91static int 92scresume(device_t dev) 93{ 94 return sc_resume_unit(device_get_unit(dev)); 95} 96 97int 98sc_max_unit(void) 99{ 100 return devclass_get_maxunit(sc_devclass); 101} 102 103sc_softc_t 104*sc_get_softc(int unit, int flags) 105{ 106 sc_softc_t *sc; 107 108 if ((unit < 0) || (unit >= NSC)) 109 return NULL; 110 if (flags & SC_KERNEL_CONSOLE) { 111 /* FIXME: clear if it is wired to another unit! */ 112 sc = &main_softc; 113 } else { 114 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit)); 115 } 116 sc->unit = unit; 117 if (!(sc->flags & SC_INIT_DONE)) { 118 sc->keyboard = -1; 119 sc->adapter = -1; 120 sc->mouse_char = SC_MOUSE_CHAR; 121 } 122 return sc; 123} 124 125sc_softc_t 126*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd) 127{ 128 sc_softc_t *sc; 129 int units; 130 int i; 131 132 sc = &main_softc; 133 if (((adp == NULL) || (adp == sc->adp)) 134 && ((kbd == NULL) || (kbd == sc->kbd))) 135 return sc; 136 units = devclass_get_maxunit(sc_devclass); 137 for (i = 0; i < units; ++i) { 138 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i)); 139 if (sc == NULL) 140 continue; 141 if (((adp == NULL) || (adp == sc->adp)) 142 && ((kbd == NULL) || (kbd == sc->kbd))) 143 return sc; 144 } 145 return NULL; 146} 147 148int 149sc_get_cons_priority(int *unit, int *flags) 150{ 151 int disabled; 152 int u, f; 153 int i; 154 155 *unit = -1; 156 for (i = -1; (i = resource_locate(i, SC_DRIVER_NAME)) >= 0;) { 157 u = resource_query_unit(i); 158 if ((resource_int_value(SC_DRIVER_NAME, u, "disabled", 159 &disabled) == 0) && disabled) 160 continue; 161 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0) 162 f = 0; 163 if (f & SC_KERNEL_CONSOLE) { 164 /* the user designates this unit to be the console */ 165 *unit = u; 166 *flags = f; 167 break; 168 } 169 if (*unit < 0) { 170 /* ...otherwise remember the first found unit */ 171 *unit = u; 172 *flags = f; 173 } 174 } 175 if ((i < 0) && (*unit < 0)) 176 return CN_DEAD; 177 return CN_INTERNAL; 178} 179 180void 181sc_get_bios_values(bios_values_t *values) 182{ 183 values->cursor_start = 0; 184 values->cursor_end = 16; 185 values->shift_state = 0; 186 if (pc98_machine_type & M_8M) 187 values->bell_pitch = BELL_PITCH_8M; 188 else 189 values->bell_pitch = BELL_PITCH_5M; 190} 191 192int 193sc_tone(int herz) 194{ 195 int pitch; 196 197 if (herz) { 198 /* enable counter 1 */ 199 outb(0x35, inb(0x35) & 0xf7); 200 /* set command for counter 1, 2 byte write */ 201 if (acquire_timer1(TIMER_16BIT | TIMER_SQWAVE)) 202 return EBUSY; 203 /* set pitch */ 204 pitch = timer_freq/herz; 205 outb(TIMER_CNTR1, pitch); 206 outb(TIMER_CNTR1, pitch >> 8); 207 } else { 208 /* disable counter 1 */ 209 outb(0x35, inb(0x35) | 0x08); 210 release_timer1(); 211 } 212 return 0; 213} 214 215DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); 216 217#endif /* NSC > 0 */ 218