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

Cache object: 16180167d9899a93d3e5a02ad8830947


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