syscons_isa.c revision 105312
1/*- 2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 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/isa/syscons_isa.c 105312 2002-10-17 07:04:31Z iwasaki $ 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/kbio.h> 38#include <sys/consio.h> 39 40 41#ifdef __i386__ 42 43#include <machine/clock.h> 44#include <machine/md_var.h> 45#include <machine/pc/bios.h> 46 47#include <vm/vm.h> 48#include <vm/pmap.h> 49 50#include <i386/isa/timerreg.h> 51 52#define BIOS_CLKED (1 << 6) 53#define BIOS_NLKED (1 << 5) 54#define BIOS_SLKED (1 << 4) 55#define BIOS_ALKED 0 56 57#endif /* __i386__ */ 58 59#include <dev/syscons/syscons.h> 60 61#include <isa/isareg.h> 62#include <isa/isavar.h> 63 64static devclass_t sc_devclass; 65 66static sc_softc_t main_softc; 67 68static void 69scidentify (driver_t *driver, device_t parent) 70{ 71 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0); 72} 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 sc_cur_scr; 92 93static int 94scsuspend(device_t dev) 95{ 96#ifndef SC_NO_SUSPEND_VTYSWITCH 97 int retry = 10; 98 static int dummy; 99 sc_softc_t *sc; 100 101 sc = &main_softc; 102 sc_cur_scr = sc->cur_scp->index; 103 do { 104 sc_switch_scr(sc, 0); 105 if (!sc->switch_in_progress) { 106 break; 107 } 108 tsleep(&dummy, 0, "scsuspend", 100); 109 } while (retry--); 110 111#endif 112 return (0); 113} 114 115static int 116scresume(device_t dev) 117{ 118#ifndef SC_NO_SUSPEND_VTYSWITCH 119 sc_softc_t *sc; 120 121 sc = &main_softc; 122 sc_switch_scr(sc, sc_cur_scr); 123 124#endif 125 return (0); 126} 127 128int 129sc_max_unit(void) 130{ 131 return devclass_get_maxunit(sc_devclass); 132} 133 134sc_softc_t 135*sc_get_softc(int unit, int flags) 136{ 137 sc_softc_t *sc; 138 139 if (unit < 0) 140 return NULL; 141 if (flags & SC_KERNEL_CONSOLE) { 142 /* FIXME: clear if it is wired to another unit! */ 143 sc = &main_softc; 144 } else { 145 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit)); 146 if (sc == NULL) 147 return NULL; 148 } 149 sc->unit = unit; 150 if (!(sc->flags & SC_INIT_DONE)) { 151 sc->keyboard = -1; 152 sc->adapter = -1; 153 sc->cursor_char = SC_CURSOR_CHAR; 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 int disabled; 186 const char *at; 187 int u, f; 188 189 *unit = -1; 190 for (u = 0; u < 16; u++) { 191 if ((resource_int_value(SC_DRIVER_NAME, u, "disabled", 192 &disabled) == 0) && disabled) 193 continue; 194 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0) 195 continue; 196 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0) 197 f = 0; 198 if (f & SC_KERNEL_CONSOLE) { 199 /* the user designates this unit to be the console */ 200 *unit = u; 201 *flags = f; 202 break; 203 } 204 if (*unit < 0) { 205 /* ...otherwise remember the first found unit */ 206 *unit = u; 207 *flags = f; 208 } 209 } 210 if (*unit < 0) 211 return CN_DEAD; 212#if 0 213 return ((*flags & SC_KERNEL_CONSOLE) ? CN_INTERNAL : CN_NORMAL); 214#endif 215 return CN_INTERNAL; 216} 217 218void 219sc_get_bios_values(bios_values_t *values) 220{ 221#ifdef __i386__ 222 u_int8_t shift; 223 224 values->cursor_start = *(u_int8_t *)BIOS_PADDRTOVADDR(0x461); 225 values->cursor_end = *(u_int8_t *)BIOS_PADDRTOVADDR(0x460); 226 shift = *(u_int8_t *)BIOS_PADDRTOVADDR(0x417); 227 values->shift_state = ((shift & BIOS_CLKED) ? CLKED : 0) 228 | ((shift & BIOS_NLKED) ? NLKED : 0) 229 | ((shift & BIOS_SLKED) ? SLKED : 0) 230 | ((shift & BIOS_ALKED) ? ALKED : 0); 231 values->bell_pitch = BELL_PITCH; 232#else /* !__i386__ */ 233 values->cursor_start = 0; 234 values->cursor_end = 32; 235 values->shift_state = 0; 236 values->bell_pitch = BELL_PITCH; 237#endif /* __i386__ */ 238} 239 240int 241sc_tone(int herz) 242{ 243#ifdef __i386__ 244 int pitch; 245 246 if (herz) { 247 /* set command for counter 2, 2 byte write */ 248 if (acquire_timer2(TIMER_16BIT | TIMER_SQWAVE)) 249 return EBUSY; 250 /* set pitch */ 251 pitch = timer_freq/herz; 252 outb(TIMER_CNTR2, pitch); 253 outb(TIMER_CNTR2, pitch >> 8); 254 /* enable counter 2 output to speaker */ 255 outb(IO_PPI, inb(IO_PPI) | 3); 256 } else { 257 /* disable counter 2 output to speaker */ 258 outb(IO_PPI, inb(IO_PPI) & 0xFC); 259 release_timer2(); 260 } 261#endif /* __i386__ */ 262 263 return 0; 264} 265 266static device_method_t sc_methods[] = { 267 DEVMETHOD(device_identify, scidentify), 268 DEVMETHOD(device_probe, scprobe), 269 DEVMETHOD(device_attach, scattach), 270 DEVMETHOD(device_suspend, scsuspend), 271 DEVMETHOD(device_resume, scresume), 272 { 0, 0 } 273}; 274 275static driver_t sc_driver = { 276 SC_DRIVER_NAME, 277 sc_methods, 278 sizeof(sc_softc_t), 279}; 280 281DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); 282