syscons_isa.c (47618) | syscons_isa.c (48104) |
---|---|
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 unchanged lines hidden (view full) --- 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 * | 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 unchanged lines hidden (view full) --- 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 * $Id: syscons_isa.c,v 1.3 1999/05/08 21:59:31 dfr Exp $ | 26 * $Id: syscons_isa.c,v 1.4 1999/05/30 11:12:29 dfr Exp $ |
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 | 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 <machine/cons.h> |
|
40#include <machine/console.h> | 41#include <machine/console.h> |
42 |
|
41#ifdef __i386__ | 43#ifdef __i386__ |
42#include <machine/apm_bios.h> 43#endif | |
44 | 44 |
45#include <machine/clock.h> 46#include <machine/md_var.h> 47#include <machine/pc/bios.h> 48 49#include <vm/vm.h> 50#include <vm/pmap.h> 51 52#include <i386/isa/timerreg.h> 53 54#define BIOS_CLKED (1 << 6) 55#define BIOS_NLKED (1 << 5) 56#define BIOS_SLKED (1 << 4) 57#define BIOS_ALKED 0 58 59#endif /* __i386__ */ 60 |
|
45#include <dev/syscons/syscons.h> 46 47#include <isa/isareg.h> 48#include <isa/isavar.h> 49 | 61#include <dev/syscons/syscons.h> 62 63#include <isa/isareg.h> 64#include <isa/isavar.h> 65 |
50devclass_t sc_devclass; | 66static devclass_t sc_devclass; |
51 52static int scprobe(device_t dev); 53static int scattach(device_t dev); | 67 68static int scprobe(device_t dev); 69static int scattach(device_t dev); |
70static int scresume(device_t dev); |
|
54 55static device_method_t sc_methods[] = { 56 DEVMETHOD(device_probe, scprobe), 57 DEVMETHOD(device_attach, scattach), | 71 72static device_method_t sc_methods[] = { 73 DEVMETHOD(device_probe, scprobe), 74 DEVMETHOD(device_attach, scattach), |
75 DEVMETHOD(device_resume, scresume), |
|
58 { 0, 0 } 59}; 60 61static driver_t sc_driver = { | 76 { 0, 0 } 77}; 78 79static driver_t sc_driver = { |
62 "sc", | 80 SC_DRIVER_NAME, |
63 sc_methods, 64 1, /* XXX */ 65}; 66 | 81 sc_methods, 82 1, /* XXX */ 83}; 84 |
85static sc_softc_t main_softc = { 0, 0, 0, -1, NULL, -1, NULL, }; 86 |
|
67static int 68scprobe(device_t dev) 69{ 70 /* No pnp support */ 71 if (isa_get_vendorid(dev)) 72 return (ENXIO); 73 74 device_set_desc(dev, "System console"); 75 return sc_probe_unit(device_get_unit(dev), isa_get_flags(dev)); 76} 77 78static int 79scattach(device_t dev) 80{ 81 return sc_attach_unit(device_get_unit(dev), isa_get_flags(dev)); 82} 83 | 87static int 88scprobe(device_t dev) 89{ 90 /* No pnp support */ 91 if (isa_get_vendorid(dev)) 92 return (ENXIO); 93 94 device_set_desc(dev, "System console"); 95 return sc_probe_unit(device_get_unit(dev), isa_get_flags(dev)); 96} 97 98static int 99scattach(device_t dev) 100{ 101 return sc_attach_unit(device_get_unit(dev), isa_get_flags(dev)); 102} 103 |
104static int 105scresume(device_t dev) 106{ 107 return sc_resume_unit(device_get_unit(dev)); 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) || (unit >= NSC)) 122 return NULL; 123 if (flags & SC_KERNEL_CONSOLE) { 124 /* FIXME: clear if it is wired to another unit! */ 125 main_softc.unit = unit; 126 return &main_softc; 127 } else { 128 sc = (sc_softc_t *)devclass_get_softc(sc_devclass, unit); 129 if (!(sc->flags & SC_INIT_DONE)) { 130 sc->unit = unit; 131 sc->keyboard = -1; 132 sc->adapter = -1; 133 } 134 return sc; 135 } 136} 137 138sc_softc_t 139*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd) 140{ 141 sc_softc_t *sc; 142 int units; 143 int i; 144 145 sc = &main_softc; 146 if (((adp == NULL) || (adp == sc->adp)) 147 && ((kbd == NULL) || (kbd == sc->kbd))) 148 return sc; 149 units = devclass_get_maxunit(sc_devclass); 150 for (i = 0; i < units; ++i) { 151 sc = (sc_softc_t *)devclass_get_softc(sc_devclass, i); 152 if (sc == NULL) 153 continue; 154 if (((adp == NULL) || (adp == sc->adp)) 155 && ((kbd == NULL) || (kbd == sc->kbd))) 156 return sc; 157 } 158 return NULL; 159} 160 161int 162sc_get_cons_priority(int *unit, int *flags) 163{ 164 int disabled; 165 int u, f; 166 int i; 167 168 *unit = -1; 169 for (i = -1; (i = resource_locate(i, SC_DRIVER_NAME)) >= 0;) { 170 u = resource_query_unit(i); 171 if ((resource_int_value(SC_DRIVER_NAME, u, "disabled", 172 &disabled) == 0) && disabled) 173 continue; 174 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0) 175 f = 0; 176 if (f & SC_KERNEL_CONSOLE) { 177 /* the user designates this unit to be the console */ 178 *unit = u; 179 *flags = f; 180 break; 181 } 182 if (*unit < 0) { 183 /* ...otherwise remember the first found unit */ 184 *unit = u; 185 *flags = f; 186 } 187 } 188 if ((i < 0) && (*unit < 0)) 189 return CN_DEAD; 190#if 0 191 return ((*flags & SC_KERNEL_CONSOLE) ? CN_INTERNAL : CN_NORMAL); 192#endif 193 return CN_INTERNAL; 194} 195 196void 197sc_get_bios_values(bios_values_t *values) 198{ 199#ifdef __i386__ 200 u_int8_t shift; 201 202 values->cursor_start = *(u_int8_t *)BIOS_PADDRTOVADDR(0x461); 203 values->cursor_end = *(u_int8_t *)BIOS_PADDRTOVADDR(0x460); 204 shift = *(u_int8_t *)BIOS_PADDRTOVADDR(0x417); 205 values->shift_state = ((shift & BIOS_CLKED) ? CLKED : 0) 206 | ((shift & BIOS_NLKED) ? NLKED : 0) 207 | ((shift & BIOS_SLKED) ? SLKED : 0) 208 | ((shift & BIOS_ALKED) ? ALKED : 0); 209 values->bell_pitch = BELL_PITCH; 210#else /* !__i386__ */ 211 values->cursor_start = 0; 212 values->cursor_end = 32; 213 values->shift_state = 0; 214 values->bell_pitch = BELL_PITCH; 215#endif /* __i386__ */ 216} 217 218int 219sc_tone(int herz) 220{ 221#ifdef __i386__ 222 int pitch; 223 224 if (herz) { 225 /* set command for counter 2, 2 byte write */ 226 if (acquire_timer2(TIMER_16BIT | TIMER_SQWAVE)) 227 return EBUSY; 228 /* set pitch */ 229 pitch = timer_freq/herz; 230 outb(TIMER_CNTR2, pitch); 231 outb(TIMER_CNTR2, pitch >> 8); 232 /* enable counter 2 output to speaker */ 233 outb(IO_PPI, inb(IO_PPI) | 3); 234 } else { 235 /* disable counter 2 output to speaker */ 236 outb(IO_PPI, inb(IO_PPI) & 0xFC); 237 release_timer2(); 238 } 239#endif /* __i386__ */ 240 241 return 0; 242} 243 |
|
84DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); 85 86#endif /* NSC > 0 */ | 244DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); 245 246#endif /* NSC > 0 */ |