The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/isa/syscons_isa.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/6.3/sys/isa/syscons_isa.c 161534 2006-08-22 16:52:42Z rink $");
   29 
   30 #include "opt_syscons.h"
   31 #include "opt_xbox.h"
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/kernel.h>
   36 #include <sys/module.h>
   37 #include <sys/bus.h>
   38 #include <sys/cons.h>
   39 #include <sys/kbio.h>
   40 #include <sys/consio.h>
   41 #include <sys/sysctl.h>
   42 
   43 #if defined(__i386__) || defined(__amd64__)
   44 
   45 #include <machine/clock.h>
   46 #include <machine/md_var.h>
   47 #include <machine/ppireg.h>
   48 #include <machine/timerreg.h>
   49 #include <machine/pc/bios.h>
   50 
   51 #ifdef XBOX
   52 #include <machine/xbox.h>
   53 #endif
   54 
   55 #include <vm/vm.h>
   56 #include <vm/pmap.h>
   57 #include <vm/vm_param.h>
   58 
   59 #define BIOS_CLKED      (1 << 6)
   60 #define BIOS_NLKED      (1 << 5)
   61 #define BIOS_SLKED      (1 << 4)
   62 #define BIOS_ALKED      0
   63 
   64 #endif
   65 
   66 #include <dev/syscons/syscons.h>
   67 
   68 #include <isa/isavar.h>
   69 
   70 static devclass_t       sc_devclass;
   71 
   72 static sc_softc_t main_softc;
   73 #ifdef SC_NO_SUSPEND_VTYSWITCH
   74 static int sc_no_suspend_vtswitch = 1;
   75 #else
   76 static int sc_no_suspend_vtswitch = 0;
   77 #endif
   78 static int sc_cur_scr;
   79 
   80 TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch);
   81 SYSCTL_DECL(_hw_syscons);
   82 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW,
   83         &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
   84 
   85 static void
   86 scidentify (driver_t *driver, device_t parent)
   87 {
   88         BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
   89 }
   90 
   91 static int
   92 scprobe(device_t dev)
   93 {
   94         /* No pnp support */
   95         if (isa_get_vendorid(dev))
   96                 return (ENXIO);
   97 
   98         device_set_desc(dev, "System console");
   99         return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
  100 }
  101 
  102 static int
  103 scattach(device_t dev)
  104 {
  105         return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
  106 }
  107 
  108 static int
  109 scsuspend(device_t dev)
  110 {
  111         int             retry = 10;
  112         static int      dummy;
  113         sc_softc_t      *sc;
  114 
  115         sc = &main_softc;
  116 
  117         if (sc->cur_scp == NULL)
  118                 return (0);
  119 
  120         sc_cur_scr = sc->cur_scp->index;
  121 
  122         if (sc_no_suspend_vtswitch)
  123                 return (0);
  124 
  125         do {
  126                 sc_switch_scr(sc, 0);
  127                 if (!sc->switch_in_progress) {
  128                         break;
  129                 }
  130                 tsleep(&dummy, 0, "scsuspend", 100);
  131         } while (retry--);
  132 
  133         return (0);
  134 }
  135 
  136 static int
  137 scresume(device_t dev)
  138 {
  139         sc_softc_t      *sc;
  140 
  141         if (sc_no_suspend_vtswitch)
  142                 return (0);
  143 
  144         sc = &main_softc;
  145         sc_switch_scr(sc, sc_cur_scr);
  146 
  147         return (0);
  148 }
  149 
  150 int
  151 sc_max_unit(void)
  152 {
  153         return devclass_get_maxunit(sc_devclass);
  154 }
  155 
  156 sc_softc_t
  157 *sc_get_softc(int unit, int flags)
  158 {
  159         sc_softc_t *sc;
  160 
  161         if (unit < 0)
  162                 return NULL;
  163         if (flags & SC_KERNEL_CONSOLE) {
  164                 /* FIXME: clear if it is wired to another unit! */
  165                 sc = &main_softc;
  166         } else {
  167                 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
  168                 if (sc == NULL)
  169                         return NULL;
  170         }
  171         sc->unit = unit;
  172         if (!(sc->flags & SC_INIT_DONE)) {
  173                 sc->keyboard = -1;
  174                 sc->adapter = -1;
  175                 sc->cursor_char = SC_CURSOR_CHAR;
  176                 sc->mouse_char = SC_MOUSE_CHAR;
  177         }
  178         return sc;
  179 }
  180 
  181 sc_softc_t
  182 *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
  183 {
  184         sc_softc_t *sc;
  185         int units;
  186         int i;
  187 
  188         sc = &main_softc;
  189         if (((adp == NULL) || (adp == sc->adp))
  190             && ((kbd == NULL) || (kbd == sc->kbd)))
  191                 return sc;
  192         units = devclass_get_maxunit(sc_devclass);
  193         for (i = 0; i < units; ++i) {
  194                 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
  195                 if (sc == NULL)
  196                         continue;
  197                 if (((adp == NULL) || (adp == sc->adp))
  198                     && ((kbd == NULL) || (kbd == sc->kbd)))
  199                         return sc;
  200         }
  201         return NULL;
  202 }
  203 
  204 int
  205 sc_get_cons_priority(int *unit, int *flags)
  206 {
  207         const char *at;
  208         int u, f;
  209 
  210 #ifdef XBOX
  211         /*
  212          * The XBox Loader does not support hints, which makes our initial
  213          * console probe fail. Therefore, if an XBox is found, we hardcode the
  214          * existence of the console, as it is always there anyway.
  215          */
  216         if (arch_i386_is_xbox) {
  217                 *unit = 0;
  218                 *flags = SC_KERNEL_CONSOLE;
  219                 return CN_INTERNAL;
  220         }
  221 #endif
  222 
  223         *unit = -1;
  224         for (u = 0; u < 16; u++) {
  225                 if (resource_disabled(SC_DRIVER_NAME, u))
  226                         continue;
  227                 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
  228                         continue;
  229                 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
  230                         f = 0;
  231                 if (f & SC_KERNEL_CONSOLE) {
  232                         /* the user designates this unit to be the console */
  233                         *unit = u;
  234                         *flags = f;
  235                         break;
  236                 }
  237                 if (*unit < 0) {
  238                         /* ...otherwise remember the first found unit */
  239                         *unit = u;
  240                         *flags = f;
  241                 }
  242         }
  243         if (*unit < 0)
  244                 return CN_DEAD;
  245 #if 0
  246         return ((*flags & SC_KERNEL_CONSOLE) ? CN_INTERNAL : CN_NORMAL);
  247 #endif
  248         return CN_INTERNAL;
  249 }
  250 
  251 void
  252 sc_get_bios_values(bios_values_t *values)
  253 {
  254 #if defined(__i386__) || defined(__amd64__)
  255         u_int8_t shift;
  256 
  257         values->cursor_start = *(u_int8_t *)BIOS_PADDRTOVADDR(0x461);
  258         values->cursor_end = *(u_int8_t *)BIOS_PADDRTOVADDR(0x460);
  259         shift = *(u_int8_t *)BIOS_PADDRTOVADDR(0x417);
  260         values->shift_state = ((shift & BIOS_CLKED) ? CLKED : 0)
  261                                | ((shift & BIOS_NLKED) ? NLKED : 0)
  262                                | ((shift & BIOS_SLKED) ? SLKED : 0)
  263                                | ((shift & BIOS_ALKED) ? ALKED : 0);
  264 #else
  265         values->cursor_start = 0;
  266         values->cursor_end = 32;
  267         values->shift_state = 0;
  268 #endif
  269         values->bell_pitch = BELL_PITCH;
  270 }
  271 
  272 int
  273 sc_tone(int herz)
  274 {
  275 #if defined(__i386__) || defined(__amd64__)
  276         if (herz) {
  277                 /* set command for counter 2, 2 byte write */
  278                 if (timer_spkr_acquire())
  279                         return EBUSY;
  280                 /* set pitch */
  281                 spkr_set_pitch(timer_freq / herz);
  282                 /* enable counter 2 output to speaker */
  283                 ppi_spkr_on();
  284         } else {
  285                 /* disable counter 2 output to speaker */
  286                 ppi_spkr_off();
  287                 timer_spkr_release();
  288         }
  289 #endif
  290 
  291         return 0;
  292 }
  293 
  294 static device_method_t sc_methods[] = {
  295         DEVMETHOD(device_identify,      scidentify),
  296         DEVMETHOD(device_probe,         scprobe),
  297         DEVMETHOD(device_attach,        scattach),
  298         DEVMETHOD(device_suspend,       scsuspend),
  299         DEVMETHOD(device_resume,        scresume),
  300         { 0, 0 }
  301 };
  302 
  303 static driver_t sc_driver = {
  304         SC_DRIVER_NAME,
  305         sc_methods,
  306         sizeof(sc_softc_t),
  307 };
  308 
  309 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);

Cache object: 005759b455d164c7b9f5b4e9d50aade1


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.