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/dev/dcons/dcons_os.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (C) 2003,2004
    3  *      Hidetoshi Shimokawa. 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.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *
   16  *      This product includes software developed by Hidetoshi Shimokawa.
   17  *
   18  * 4. Neither the name of the author nor the names of its contributors
   19  *    may be used to endorse or promote products derived from this software
   20  *    without specific prior written permission.
   21  * 
   22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   32  * SUCH DAMAGE.
   33  * 
   34  * $FreeBSD$
   35  */
   36 
   37 #include <sys/param.h>
   38 #if __FreeBSD_version >= 502122
   39 #include <sys/kdb.h>
   40 #include <gdb/gdb.h>
   41 #endif
   42 #include <sys/kernel.h>
   43 #include <sys/module.h>
   44 #include <sys/systm.h>
   45 #include <sys/types.h>
   46 #include <sys/conf.h>
   47 #include <sys/cons.h>
   48 #include <sys/consio.h>
   49 #include <sys/tty.h>
   50 #include <sys/malloc.h>
   51 #include <sys/priv.h>
   52 #include <sys/proc.h>
   53 #include <sys/ucred.h>
   54 
   55 #include <machine/bus.h>
   56 
   57 #ifdef __DragonFly__
   58 #include "dcons.h"
   59 #include "dcons_os.h"
   60 #else
   61 #include <dev/dcons/dcons.h>
   62 #include <dev/dcons/dcons_os.h>
   63 #endif
   64 
   65 #include <ddb/ddb.h>
   66 #include <sys/reboot.h>
   67 
   68 #include <sys/sysctl.h>
   69 
   70 #include <vm/vm.h>
   71 #include <vm/vm_param.h>
   72 #include <vm/pmap.h>
   73 
   74 #include "opt_comconsole.h"
   75 #include "opt_dcons.h"
   76 #include "opt_kdb.h"
   77 #include "opt_gdb.h"
   78 #include "opt_ddb.h"
   79 
   80 
   81 #ifndef DCONS_POLL_HZ
   82 #define DCONS_POLL_HZ   100
   83 #endif
   84 
   85 #ifndef DCONS_BUF_SIZE
   86 #define DCONS_BUF_SIZE (16*1024)
   87 #endif
   88 
   89 #ifndef DCONS_FORCE_CONSOLE
   90 #define DCONS_FORCE_CONSOLE     0       /* Mostly for FreeBSD-4/DragonFly */
   91 #endif
   92 
   93 #ifndef DCONS_FORCE_GDB
   94 #define DCONS_FORCE_GDB 1
   95 #endif
   96 
   97 #if __FreeBSD_version >= 500101
   98 #define CONS_NODEV      1
   99 #if __FreeBSD_version < 502122
  100 static struct consdev gdbconsdev;
  101 #endif
  102 #endif
  103 
  104 static d_open_t         dcons_open;
  105 static d_close_t        dcons_close;
  106 #if defined(__DragonFly__) || __FreeBSD_version < 500104
  107 static d_ioctl_t        dcons_ioctl;
  108 #endif
  109 
  110 static struct cdevsw dcons_cdevsw = {
  111 #ifdef __DragonFly__
  112 #define CDEV_MAJOR      184
  113         "dcons", CDEV_MAJOR, D_TTY, NULL, 0,
  114         dcons_open, dcons_close, ttyread, ttywrite, dcons_ioctl,
  115         ttypoll, nommap, nostrategy, nodump, nopsize,
  116 #elif __FreeBSD_version >= 500104
  117         .d_version =    D_VERSION,
  118         .d_open =       dcons_open,
  119         .d_close =      dcons_close,
  120         .d_name =       "dcons",
  121         .d_flags =      D_TTY | D_NEEDGIANT,
  122 #else
  123 #define CDEV_MAJOR      184
  124         /* open */      dcons_open,
  125         /* close */     dcons_close,
  126         /* read */      ttyread,
  127         /* write */     ttywrite,
  128         /* ioctl */     dcons_ioctl,
  129         /* poll */      ttypoll,
  130         /* mmap */      nommap,
  131         /* strategy */  nostrategy,
  132         /* name */      "dcons",
  133         /* major */     CDEV_MAJOR,
  134         /* dump */      nodump,
  135         /* psize */     nopsize,
  136         /* flags */     D_TTY,
  137 #endif
  138 };
  139 
  140 #ifndef KLD_MODULE
  141 static char bssbuf[DCONS_BUF_SIZE];     /* buf in bss */
  142 #endif
  143 
  144 /* global data */
  145 static struct dcons_global dg;
  146 struct dcons_global *dcons_conf;
  147 static int poll_hz = DCONS_POLL_HZ;
  148 
  149 static struct dcons_softc sc[DCONS_NPORT];
  150 
  151 SYSCTL_NODE(_kern, OID_AUTO, dcons, CTLFLAG_RD, 0, "Dumb Console");
  152 SYSCTL_INT(_kern_dcons, OID_AUTO, poll_hz, CTLFLAG_RW, &poll_hz, 0,
  153                                 "dcons polling rate");
  154 
  155 static int drv_init = 0;
  156 static struct callout dcons_callout;
  157 struct dcons_buf *dcons_buf;            /* for local dconschat */
  158 
  159 #ifdef __DragonFly__
  160 #define DEV     dev_t
  161 #define THREAD  d_thread_t
  162 #elif __FreeBSD_version < 500000
  163 #define DEV     dev_t
  164 #define THREAD  struct proc
  165 #else
  166 #define DEV     struct cdev *
  167 #define THREAD  struct thread
  168 #endif
  169 
  170 
  171 static void     dcons_tty_start(struct tty *);
  172 static int      dcons_tty_param(struct tty *, struct termios *);
  173 static void     dcons_timeout(void *);
  174 static int      dcons_drv_init(int);
  175 
  176 static cn_probe_t       dcons_cnprobe;
  177 static cn_init_t        dcons_cninit;
  178 static cn_term_t        dcons_cnterm;
  179 static cn_getc_t        dcons_cngetc;
  180 static cn_putc_t        dcons_cnputc;
  181 
  182 CONSOLE_DRIVER(dcons);
  183 
  184 #if defined(GDB) && (__FreeBSD_version >= 502122)
  185 static gdb_probe_f dcons_dbg_probe;
  186 static gdb_init_f dcons_dbg_init;
  187 static gdb_term_f dcons_dbg_term;
  188 static gdb_getc_f dcons_dbg_getc;
  189 static gdb_putc_f dcons_dbg_putc;
  190 
  191 GDB_DBGPORT(dcons, dcons_dbg_probe, dcons_dbg_init, dcons_dbg_term,
  192     dcons_dbg_getc, dcons_dbg_putc);
  193 
  194 extern struct gdb_dbgport *gdb_cur;
  195 #endif
  196 
  197 #if (defined(GDB) || defined(DDB)) && defined(ALT_BREAK_TO_DEBUGGER)
  198 static int
  199 dcons_check_break(struct dcons_softc *dc, int c)
  200 {
  201         if (c < 0)
  202                 return (c);
  203 
  204 #if __FreeBSD_version >= 502122
  205         if (kdb_alt_break(c, &dc->brk_state)) {
  206                 if ((dc->flags & DC_GDB) != 0) {
  207 #ifdef GDB
  208                         if (gdb_cur == &dcons_gdb_dbgport) {
  209                                 kdb_dbbe_select("gdb");
  210                                 kdb_enter("Break sequence on dcons gdb port");
  211                         }
  212 #endif
  213                 } else
  214                         kdb_enter("Break sequence on dcons console port");
  215         }
  216 #else
  217         switch (dc->brk_state) {
  218         case STATE1:
  219                 if (c == KEY_TILDE)
  220                         dc->brk_state = STATE2;
  221                 else
  222                         dc->brk_state = STATE0;
  223                 break;
  224         case STATE2:
  225                 dc->brk_state = STATE0;
  226                 if (c == KEY_CTRLB) {
  227 #if DCONS_FORCE_GDB
  228                         if (dc->flags & DC_GDB)
  229                                 boothowto |= RB_GDB;
  230 #endif
  231                         breakpoint();
  232                 }
  233         }
  234         if (c == KEY_CR)
  235                 dc->brk_state = STATE1;
  236 #endif
  237         return (c);
  238 }
  239 #else
  240 #define dcons_check_break(dc, c)        (c)
  241 #endif
  242 
  243 static int
  244 dcons_os_checkc_nopoll(struct dcons_softc *dc)
  245 {
  246         int c;
  247 
  248         if (dg.dma_tag != NULL)
  249                 bus_dmamap_sync(dg.dma_tag, dg.dma_map, BUS_DMASYNC_POSTREAD);
  250   
  251         c = dcons_check_break(dc, dcons_checkc(dc));
  252 
  253         if (dg.dma_tag != NULL)
  254                 bus_dmamap_sync(dg.dma_tag, dg.dma_map, BUS_DMASYNC_PREREAD);
  255 
  256         return (c);
  257 }
  258 
  259 static int
  260 dcons_os_checkc(struct dcons_softc *dc)
  261 {
  262         EVENTHANDLER_INVOKE(dcons_poll, 0);
  263         return (dcons_os_checkc_nopoll(dc));
  264 }
  265 
  266 #if defined(GDB) || !defined(CONS_NODEV)
  267 static int
  268 dcons_os_getc(struct dcons_softc *dc)
  269 {
  270         int c;
  271 
  272         while ((c = dcons_os_checkc(dc)) == -1);
  273 
  274         return (c & 0xff);
  275 } 
  276 #endif
  277 
  278 static void
  279 dcons_os_putc(struct dcons_softc *dc, int c)
  280 {
  281         if (dg.dma_tag != NULL)
  282                 bus_dmamap_sync(dg.dma_tag, dg.dma_map, BUS_DMASYNC_POSTWRITE);
  283 
  284         dcons_putc(dc, c);
  285 
  286         if (dg.dma_tag != NULL)
  287                 bus_dmamap_sync(dg.dma_tag, dg.dma_map, BUS_DMASYNC_PREWRITE);
  288 }
  289 static int
  290 dcons_open(DEV dev, int flag, int mode, THREAD *td)
  291 {
  292         struct tty *tp;
  293         int unit, error, s;
  294 
  295         unit = minor(dev);
  296         if (unit != 0)
  297                 return (ENXIO);
  298 
  299         tp = dev->si_tty;
  300         tp->t_oproc = dcons_tty_start;
  301         tp->t_param = dcons_tty_param;
  302         tp->t_stop = nottystop;
  303         tp->t_dev = dev;
  304 
  305         error = 0;
  306 
  307         s = spltty();
  308         if ((tp->t_state & TS_ISOPEN) == 0) {
  309                 tp->t_state |= TS_CARR_ON;
  310                 ttyconsolemode(tp, 0);
  311         } else if ((tp->t_state & TS_XCLUDE) &&
  312             priv_check(td, PRIV_TTY_EXCLUSIVE)) {
  313                 splx(s);
  314                 return (EBUSY);
  315         }
  316         splx(s);
  317 
  318 #if __FreeBSD_version < 502113
  319         error = (*linesw[tp->t_line].l_open)(dev, tp);
  320 #else
  321         error = ttyld_open(tp, dev);
  322 #endif
  323 
  324         return (error);
  325 }
  326 
  327 static int
  328 dcons_close(DEV dev, int flag, int mode, THREAD *td)
  329 {
  330         int     unit;
  331         struct  tty *tp;
  332 
  333         unit = minor(dev);
  334         if (unit != 0)
  335                 return (ENXIO);
  336 
  337         tp = dev->si_tty;
  338         if (tp->t_state & TS_ISOPEN) {
  339 #if __FreeBSD_version < 502113
  340                 (*linesw[tp->t_line].l_close)(tp, flag);
  341                 ttyclose(tp);
  342 #else
  343                 ttyld_close(tp, flag);
  344                 tty_close(tp);
  345 #endif
  346         }
  347 
  348         return (0);
  349 }
  350 
  351 #if defined(__DragonFly__) || __FreeBSD_version < 500104
  352 static int
  353 dcons_ioctl(DEV dev, u_long cmd, caddr_t data, int flag, THREAD *td)
  354 {
  355         int     unit;
  356         struct  tty *tp;
  357         int     error;
  358 
  359         unit = minor(dev);
  360         if (unit != 0)
  361                 return (ENXIO);
  362 
  363         tp = dev->si_tty;
  364         error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
  365         if (error != ENOIOCTL)
  366                 return (error);
  367 
  368         error = ttioctl(tp, cmd, data, flag);
  369         if (error != ENOIOCTL)
  370                 return (error);
  371 
  372         return (ENOTTY);
  373 }
  374 #endif
  375 
  376 static int
  377 dcons_tty_param(struct tty *tp, struct termios *t)
  378 {
  379         tp->t_ispeed = t->c_ispeed;
  380         tp->t_ospeed = t->c_ospeed;
  381         tp->t_cflag = t->c_cflag;
  382         return 0;
  383 }
  384 
  385 static void
  386 dcons_tty_start(struct tty *tp)
  387 {
  388         struct dcons_softc *dc;
  389         int s;
  390 
  391         dc = (struct dcons_softc *)tp->t_dev->si_drv1;
  392         s = spltty();
  393         if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
  394                 ttwwakeup(tp);
  395                 return;
  396         }
  397 
  398         tp->t_state |= TS_BUSY;
  399         while (tp->t_outq.c_cc != 0)
  400                 dcons_os_putc(dc, getc(&tp->t_outq));
  401         tp->t_state &= ~TS_BUSY;
  402 
  403         ttwwakeup(tp);
  404         splx(s);
  405 }
  406 
  407 static void
  408 dcons_timeout(void *v)
  409 {
  410         struct  tty *tp;
  411         struct dcons_softc *dc;
  412         int i, c, polltime;
  413 
  414         for (i = 0; i < DCONS_NPORT; i ++) {
  415                 dc = &sc[i];
  416                 tp = ((DEV)dc->dev)->si_tty;
  417                 while ((c = dcons_os_checkc_nopoll(dc)) != -1)
  418                         if (tp->t_state & TS_ISOPEN)
  419 #if __FreeBSD_version < 502113
  420                                 (*linesw[tp->t_line].l_rint)(c, tp);
  421 #else
  422                                 ttyld_rint(tp, c);
  423 #endif
  424         }
  425         polltime = hz / poll_hz;
  426         if (polltime < 1)
  427                 polltime = 1;
  428         callout_reset(&dcons_callout, polltime, dcons_timeout, tp);
  429 }
  430 
  431 static void
  432 dcons_cnprobe(struct consdev *cp)
  433 {
  434 #ifdef __DragonFly__
  435         cp->cn_dev = make_dev(&dcons_cdevsw, DCONS_CON,
  436             UID_ROOT, GID_WHEEL, 0600, "dcons");
  437 #elif __FreeBSD_version >= 501109
  438         sprintf(cp->cn_name, "dcons");
  439 #else
  440         cp->cn_dev = makedev(CDEV_MAJOR, DCONS_CON);
  441 #endif
  442 #if DCONS_FORCE_CONSOLE
  443         cp->cn_pri = CN_REMOTE;
  444 #else
  445         cp->cn_pri = CN_NORMAL;
  446 #endif
  447 }
  448 
  449 static void
  450 dcons_cninit(struct consdev *cp)
  451 {
  452         dcons_drv_init(0);
  453 #if CONS_NODEV
  454         cp->cn_arg
  455 #else
  456         cp->cn_dev->si_drv1
  457 #endif
  458                 = (void *)&sc[DCONS_CON]; /* share port0 with unit0 */
  459 }
  460 
  461 static void
  462 dcons_cnterm(struct consdev *cp)
  463 {
  464 }
  465 
  466 #if CONS_NODEV
  467 static int
  468 dcons_cngetc(struct consdev *cp)
  469 {
  470         struct dcons_softc *dc = (struct dcons_softc *)cp->cn_arg;
  471         return (dcons_os_checkc(dc));
  472 }
  473 static void
  474 dcons_cnputc(struct consdev *cp, int c)
  475 {
  476         struct dcons_softc *dc = (struct dcons_softc *)cp->cn_arg;
  477         dcons_os_putc(dc, c);
  478 }
  479 #else
  480 static int
  481 dcons_cngetc(DEV dev)
  482 {
  483         struct dcons_softc *dc = (struct dcons_softc *)dev->si_drv1;
  484         return (dcons_os_getc(dc));
  485 }
  486 static int
  487 dcons_cncheckc(DEV dev)
  488 {
  489         struct dcons_softc *dc = (struct dcons_softc *)dev->si_drv1;
  490         return (dcons_os_checkc(dc));
  491 }
  492 static void
  493 dcons_cnputc(DEV dev, int c)
  494 {
  495         struct dcons_softc *dc = (struct dcons_softc *)dev->si_drv1;
  496         dcons_os_putc(dc, c);
  497 }
  498 #endif
  499 
  500 static int
  501 dcons_drv_init(int stage)
  502 {
  503 #if defined(__i386__) || defined(__amd64__)
  504         quad_t addr, size;
  505 #endif
  506 
  507         if (drv_init)
  508                 return(drv_init);
  509 
  510         drv_init = -1;
  511 
  512         bzero(&dg, sizeof(dg));
  513         dcons_conf = &dg;
  514         dg.cdev = &dcons_consdev;
  515         dg.buf = NULL;
  516         dg.size = DCONS_BUF_SIZE;
  517 
  518 #if defined(__i386__) || defined(__amd64__)
  519         if (getenv_quad("dcons.addr", &addr) > 0 &&
  520             getenv_quad("dcons.size", &size) > 0) {
  521 #ifdef __i386__
  522                 vm_paddr_t pa;
  523                 /*
  524                  * Allow read/write access to dcons buffer.
  525                  */
  526                 for (pa = trunc_page(addr); pa < addr + size; pa += PAGE_SIZE)
  527                         *vtopte(KERNBASE + pa) |= PG_RW;
  528                 invltlb();
  529 #endif
  530                 /* XXX P to V */
  531                 dg.buf = (struct dcons_buf *)(vm_offset_t)(KERNBASE + addr);
  532                 dg.size = size;
  533                 if (dcons_load_buffer(dg.buf, dg.size, sc) < 0)
  534                         dg.buf = NULL;
  535         }
  536 #endif
  537         if (dg.buf != NULL)
  538                 goto ok;
  539 
  540 #ifndef KLD_MODULE
  541         if (stage == 0) { /* XXX or cold */
  542                 /*
  543                  * DCONS_FORCE_CONSOLE == 1 and statically linked.
  544                  * called from cninit(). can't use contigmalloc yet .
  545                  */
  546                 dg.buf = (struct dcons_buf *) bssbuf;
  547                 dcons_init(dg.buf, dg.size, sc);
  548         } else
  549 #endif
  550         {
  551                 /*
  552                  * DCONS_FORCE_CONSOLE == 0 or kernel module case.
  553                  * if the module is loaded after boot,
  554                  * bssbuf could be non-continuous.
  555                  */ 
  556                 dg.buf = (struct dcons_buf *) contigmalloc(dg.size,
  557                         M_DEVBUF, 0, 0x10000, 0xffffffff, PAGE_SIZE, 0ul);
  558                 dcons_init(dg.buf, dg.size, sc);
  559         }
  560 
  561 ok:
  562         dcons_buf = dg.buf;
  563 
  564 #if __FreeBSD_version < 502122
  565 #if defined(DDB) && DCONS_FORCE_GDB
  566 #if CONS_NODEV
  567         gdbconsdev.cn_arg = (void *)&sc[DCONS_GDB];
  568 #if __FreeBSD_version >= 501109
  569         sprintf(gdbconsdev.cn_name, "dgdb");
  570 #endif
  571         gdb_arg = &gdbconsdev;
  572 #elif defined(__DragonFly__)
  573         gdbdev = make_dev(&dcons_cdevsw, DCONS_GDB,
  574             UID_ROOT, GID_WHEEL, 0600, "dgdb");
  575 #else
  576         gdbdev = makedev(CDEV_MAJOR, DCONS_GDB);
  577 #endif
  578         gdb_getc = dcons_cngetc;
  579         gdb_putc = dcons_cnputc;
  580 #endif
  581 #endif
  582         drv_init = 1;
  583 
  584         return 0;
  585 }
  586 
  587 
  588 static int
  589 dcons_attach_port(int port, char *name, int flags)
  590 {
  591         struct dcons_softc *dc;
  592         struct tty *tp;
  593         DEV dev;
  594 
  595         dc = &sc[port];
  596         dc->flags = flags;
  597         dev = make_dev(&dcons_cdevsw, port,
  598                         UID_ROOT, GID_WHEEL, 0600, name);
  599         dc->dev = (void *)dev;
  600         tp = ttyalloc();
  601 
  602         dev->si_drv1 = (void *)dc;
  603         dev->si_tty = tp;
  604 
  605         tp->t_oproc = dcons_tty_start;
  606         tp->t_param = dcons_tty_param;
  607         tp->t_stop = nottystop;
  608         tp->t_dev = dc->dev;
  609 
  610         return(0);
  611 }
  612 
  613 static int
  614 dcons_attach(void)
  615 {
  616         int polltime;
  617 
  618 #ifdef __DragonFly__
  619         cdevsw_add(&dcons_cdevsw, -1, 0);
  620 #endif
  621         dcons_attach_port(DCONS_CON, "dcons", 0);
  622         dcons_attach_port(DCONS_GDB, "dgdb", DC_GDB);
  623 #if __FreeBSD_version < 500000
  624         callout_init(&dcons_callout);
  625 #else
  626         callout_init(&dcons_callout, 0);
  627 #endif
  628         polltime = hz / poll_hz;
  629         if (polltime < 1)
  630                 polltime = 1;
  631         callout_reset(&dcons_callout, polltime, dcons_timeout, NULL);
  632         return(0);
  633 }
  634 
  635 static int
  636 dcons_detach(int port)
  637 {
  638         struct  tty *tp;
  639         struct dcons_softc *dc;
  640 
  641         dc = &sc[port];
  642 
  643         tp = ((DEV)dc->dev)->si_tty;
  644 
  645         if (tp->t_state & TS_ISOPEN) {
  646                 printf("dcons: still opened\n");
  647 #if __FreeBSD_version < 502113
  648                 (*linesw[tp->t_line].l_close)(tp, 0);
  649                 tp->t_gen++;
  650                 ttyclose(tp);
  651                 ttwakeup(tp);
  652                 ttwwakeup(tp);
  653 #else
  654                 ttyld_close(tp, 0);
  655                 tty_close(tp);
  656 #endif
  657         }
  658         /* XXX
  659          * must wait until all device are closed.
  660          */
  661 #ifdef __DragonFly__
  662         tsleep((void *)dc, 0, "dcodtc", hz/4);
  663 #else
  664         tsleep((void *)dc, PWAIT, "dcodtc", hz/4);
  665 #endif
  666         destroy_dev(dc->dev);
  667 
  668         return(0);
  669 }
  670 
  671 
  672 /* cnXXX works only for FreeBSD-5 */
  673 static int
  674 dcons_modevent(module_t mode, int type, void *data)
  675 {
  676         int err = 0, ret;
  677 
  678         switch (type) {
  679         case MOD_LOAD:
  680                 ret = dcons_drv_init(1);
  681                 dcons_attach();
  682 #if __FreeBSD_version >= 500000
  683                 if (ret == 0) {
  684                         dcons_cnprobe(&dcons_consdev);
  685                         dcons_cninit(&dcons_consdev);
  686                         cnadd(&dcons_consdev);
  687                 }
  688 #endif
  689                 break;
  690         case MOD_UNLOAD:
  691                 printf("dcons: unload\n");
  692                 callout_stop(&dcons_callout);
  693 #if __FreeBSD_version < 502122
  694 #if defined(DDB) && DCONS_FORCE_GDB
  695 #if CONS_NODEV
  696                 gdb_arg = NULL;
  697 #else
  698                 gdbdev = NULL;
  699 #endif
  700 #endif
  701 #endif
  702 #if __FreeBSD_version >= 500000
  703                 cnremove(&dcons_consdev);
  704 #endif
  705                 dcons_detach(DCONS_CON);
  706                 dcons_detach(DCONS_GDB);
  707                 dg.buf->magic = 0;
  708 
  709                 contigfree(dg.buf, DCONS_BUF_SIZE, M_DEVBUF);
  710 
  711                 break;
  712         case MOD_SHUTDOWN:
  713 #if 0           /* Keep connection after halt */
  714                 dg.buf->magic = 0;
  715 #endif
  716                 break;
  717         default:
  718                 err = EOPNOTSUPP;
  719                 break;
  720         }
  721         return(err);
  722 }
  723 
  724 #if defined(GDB) && (__FreeBSD_version >= 502122)
  725 /* Debugger interface */
  726 
  727 static int
  728 dcons_dbg_probe(void)
  729 {
  730         int dcons_gdb;
  731 
  732         if (getenv_int("dcons_gdb", &dcons_gdb) == 0)
  733                 return (-1);
  734         return (dcons_gdb);
  735 }
  736 
  737 static void
  738 dcons_dbg_init(void)
  739 {
  740 }
  741 
  742 static void
  743 dcons_dbg_term(void)
  744 {
  745 }
  746 
  747 static void
  748 dcons_dbg_putc(int c)
  749 {
  750         struct dcons_softc *dc = &sc[DCONS_GDB];
  751         dcons_os_putc(dc, c);
  752 }
  753 
  754 static int
  755 dcons_dbg_getc(void)
  756 {
  757         struct dcons_softc *dc = &sc[DCONS_GDB];
  758         return (dcons_os_getc(dc));
  759 }
  760 #endif
  761 
  762 DEV_MODULE(dcons, dcons_modevent, NULL);
  763 MODULE_VERSION(dcons, DCONS_VERSION);

Cache object: 36faaa135ea024df808808337cafb371


[ 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.