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/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                 ttychars(tp);
  298                 tp->t_iflag = TTYDEF_IFLAG;
  299                 tp->t_oflag = TTYDEF_OFLAG;
  300                 tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
  301                 tp->t_lflag = TTYDEF_LFLAG;
  302                 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
  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                 dcons_init(dg.buf, dg.size, sc);
  552         }
  553 
  554 ok:
  555         dcons_buf = dg.buf;
  556 
  557 #if __FreeBSD_version < 502122
  558 #if DDB && DCONS_FORCE_GDB
  559 #if CONS_NODEV
  560         gdbconsdev.cn_arg = (void *)&sc[DCONS_GDB];
  561 #if __FreeBSD_version >= 501109
  562         sprintf(gdbconsdev.cn_name, "dgdb");
  563 #endif
  564         gdb_arg = &gdbconsdev;
  565 #elif defined(__DragonFly__)
  566         gdbdev = make_dev(&dcons_cdevsw, DCONS_GDB,
  567             UID_ROOT, GID_WHEEL, 0600, "dgdb");
  568 #else
  569         gdbdev = makedev(CDEV_MAJOR, DCONS_GDB);
  570 #endif
  571         gdb_getc = dcons_cngetc;
  572         gdb_putc = dcons_cnputc;
  573 #endif
  574 #endif
  575         drv_init = 1;
  576 
  577         return 0;
  578 }
  579 
  580 
  581 static int
  582 dcons_attach_port(int port, char *name, int flags)
  583 {
  584         struct dcons_softc *dc;
  585         struct tty *tp;
  586         DEV dev;
  587 
  588         dc = &sc[port];
  589         dc->flags = flags;
  590         dev = make_dev(&dcons_cdevsw, port,
  591                         UID_ROOT, GID_WHEEL, 0600, name);
  592         dc->dev = (void *)dev;
  593         tp = ttymalloc(NULL);
  594 
  595         dev->si_drv1 = (void *)dc;
  596         dev->si_tty = tp;
  597 
  598         tp->t_oproc = dcons_tty_start;
  599         tp->t_param = dcons_tty_param;
  600         tp->t_stop = nottystop;
  601         tp->t_dev = dc->dev;
  602 
  603         return(0);
  604 }
  605 
  606 static int
  607 dcons_attach(void)
  608 {
  609         int polltime;
  610 
  611 #ifdef __DragonFly__
  612         cdevsw_add(&dcons_cdevsw, -1, 0);
  613 #endif
  614         dcons_attach_port(DCONS_CON, "dcons", 0);
  615         dcons_attach_port(DCONS_GDB, "dgdb", DC_GDB);
  616 #if __FreeBSD_version < 500000
  617         callout_init(&dcons_callout);
  618 #else
  619         callout_init(&dcons_callout, 0);
  620 #endif
  621         polltime = hz / poll_hz;
  622         if (polltime < 1)
  623                 polltime = 1;
  624         callout_reset(&dcons_callout, polltime, dcons_timeout, NULL);
  625         return(0);
  626 }
  627 
  628 static int
  629 dcons_detach(int port)
  630 {
  631         struct  tty *tp;
  632         struct dcons_softc *dc;
  633 
  634         dc = &sc[port];
  635 
  636         tp = ((DEV)dc->dev)->si_tty;
  637 
  638         if (tp->t_state & TS_ISOPEN) {
  639                 printf("dcons: still opened\n");
  640 #if __FreeBSD_version < 502113
  641                 (*linesw[tp->t_line].l_close)(tp, 0);
  642                 tp->t_gen++;
  643                 ttyclose(tp);
  644                 ttwakeup(tp);
  645                 ttwwakeup(tp);
  646 #else
  647                 ttyld_close(tp, 0);
  648                 tty_close(tp);
  649 #endif
  650         }
  651         /* XXX
  652          * must wait until all device are closed.
  653          */
  654 #ifdef __DragonFly__
  655         tsleep((void *)dc, 0, "dcodtc", hz/4);
  656 #else
  657         tsleep((void *)dc, PWAIT, "dcodtc", hz/4);
  658 #endif
  659         destroy_dev(dc->dev);
  660 
  661         return(0);
  662 }
  663 
  664 
  665 /* cnXXX works only for FreeBSD-5 */
  666 static int
  667 dcons_modevent(module_t mode, int type, void *data)
  668 {
  669         int err = 0, ret;
  670 
  671         switch (type) {
  672         case MOD_LOAD:
  673                 ret = dcons_drv_init(1);
  674                 dcons_attach();
  675 #if __FreeBSD_version >= 500000
  676                 if (ret == 0) {
  677                         dcons_cnprobe(&dcons_consdev);
  678                         dcons_cninit(&dcons_consdev);
  679                         cnadd(&dcons_consdev);
  680                 }
  681 #endif
  682                 break;
  683         case MOD_UNLOAD:
  684                 printf("dcons: unload\n");
  685                 callout_stop(&dcons_callout);
  686 #if __FreeBSD_version < 502122
  687 #if DDB && DCONS_FORCE_GDB
  688 #if CONS_NODEV
  689                 gdb_arg = NULL;
  690 #else
  691                 gdbdev = NULL;
  692 #endif
  693 #endif
  694 #endif
  695 #if __FreeBSD_version >= 500000
  696                 cnremove(&dcons_consdev);
  697 #endif
  698                 dcons_detach(DCONS_CON);
  699                 dcons_detach(DCONS_GDB);
  700                 dg.buf->magic = 0;
  701 
  702                 contigfree(dg.buf, DCONS_BUF_SIZE, M_DEVBUF);
  703 
  704                 break;
  705         case MOD_SHUTDOWN:
  706                 dg.buf->magic = 0;
  707                 break;
  708         default:
  709                 err = EOPNOTSUPP;
  710                 break;
  711         }
  712         return(err);
  713 }
  714 
  715 #if __FreeBSD_version >= 502122
  716 /* Debugger interface */
  717 
  718 static int
  719 dcons_dbg_probe(void)
  720 {
  721         return(DCONS_FORCE_GDB);
  722 }
  723 
  724 static void
  725 dcons_dbg_init(void)
  726 {
  727 }
  728 
  729 static void
  730 dcons_dbg_term(void)
  731 {
  732 }
  733 
  734 static void
  735 dcons_dbg_putc(int c)
  736 {
  737         struct dcons_softc *dc = &sc[DCONS_GDB];
  738         dcons_os_putc(dc, c);
  739 }
  740 
  741 static int
  742 dcons_dbg_checkc(void)
  743 {
  744         struct dcons_softc *dc = &sc[DCONS_GDB];
  745         return (dcons_os_checkc(dc));
  746 }
  747 
  748 static int
  749 dcons_dbg_getc(void)
  750 {
  751         struct dcons_softc *dc = &sc[DCONS_GDB];
  752         return (dcons_os_getc(dc));
  753 }
  754 #endif
  755 
  756 DEV_MODULE(dcons, dcons_modevent, NULL);
  757 MODULE_VERSION(dcons, DCONS_VERSION);

Cache object: 9785b80a9f7bbbeaa0749bc793755b80


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