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

Cache object: 5ef1fa9a3f9e21596de7e548f8d7b531


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