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.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
    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  * $Id: dcons.c,v 1.65 2003/10/24 03:24:55 simokawa Exp $
   35  * $FreeBSD: stable/4/sys/dev/dcons/dcons.c 122663 2003-11-14 12:16:46Z simokawa $
   36  */
   37 
   38 #include <sys/param.h>
   39 #include <sys/kernel.h>
   40 #include <sys/systm.h>
   41 #include <sys/types.h>
   42 #include <sys/conf.h>
   43 #include <sys/cons.h>
   44 #include <sys/consio.h>
   45 #include <sys/tty.h>
   46 #include <sys/malloc.h>
   47 #include <sys/proc.h>
   48 #include <sys/ucred.h>
   49 
   50 #include <machine/bus.h>
   51 
   52 #include <dev/dcons/dcons.h>
   53 
   54 #include <ddb/ddb.h>
   55 #include <sys/reboot.h>
   56 
   57 #include <sys/sysctl.h>
   58 
   59 #include "opt_ddb.h"
   60 #include "opt_comconsole.h"
   61 #include "opt_dcons.h"
   62 
   63 #ifndef DCONS_POLL_HZ
   64 #define DCONS_POLL_HZ   100
   65 #endif
   66 
   67 #ifndef DCONS_BUF_SIZE
   68 #define DCONS_BUF_SIZE (16*1024)
   69 #endif
   70 
   71 #ifndef DCONS_FORCE_CONSOLE
   72 #define DCONS_FORCE_CONSOLE     0       /* mostly for FreeBSD-4 */
   73 #endif
   74 
   75 #ifndef DCONS_FORCE_GDB
   76 #define DCONS_FORCE_GDB 1
   77 #endif
   78 
   79 #if __FreeBSD_version >= 500101
   80 #define CONS_NODEV      1       /* for latest current */
   81 static struct consdev gdbconsdev;
   82 #endif
   83 
   84 #define CDEV_MAJOR      184
   85 
   86 static d_open_t         dcons_open;
   87 static d_close_t        dcons_close;
   88 static d_ioctl_t        dcons_ioctl;
   89 
   90 static struct cdevsw dcons_cdevsw = {
   91 #if __FreeBSD_version >= 500104
   92         .d_open =       dcons_open,
   93         .d_close =      dcons_close,
   94         .d_read =       ttyread,
   95         .d_write =      ttywrite,
   96         .d_ioctl =      dcons_ioctl,
   97         .d_poll =       ttypoll,
   98         .d_name =       "dcons",
   99         .d_maj =        CDEV_MAJOR,
  100 #else
  101         /* open */      dcons_open,
  102         /* close */     dcons_close,
  103         /* read */      ttyread,
  104         /* write */     ttywrite,
  105         /* ioctl */     dcons_ioctl,
  106         /* poll */      ttypoll,
  107         /* mmap */      nommap,
  108         /* strategy */  nostrategy,
  109         /* name */      "dcons",
  110         /* major */     CDEV_MAJOR,
  111         /* dump */      nodump,
  112         /* psize */     nopsize,
  113         /* flags */     0,
  114 #endif
  115 };
  116 
  117 #ifndef KLD_MODULE
  118 static char bssbuf[DCONS_BUF_SIZE];     /* buf in bss */
  119 #endif
  120 struct dcons_buf *dcons_buf;
  121 size_t dcons_bufsize;
  122 bus_dma_tag_t dcons_dma_tag = NULL;
  123 bus_dmamap_t dcons_dma_map = NULL;
  124 
  125 static int poll_hz = DCONS_POLL_HZ;
  126 SYSCTL_NODE(_kern, OID_AUTO, dcons, CTLFLAG_RD, 0, "Dumb Console");
  127 SYSCTL_INT(_kern_dcons, OID_AUTO, poll_hz, CTLFLAG_RW, &poll_hz, 0,
  128                                 "dcons polling rate");
  129 
  130 static int drv_init = 0;
  131 static struct callout dcons_callout;
  132 
  133 /* per device data */
  134 static struct dcons_softc {
  135         dev_t dev;
  136         struct dcons_ch o, i;
  137         int brk_state;
  138 #define DC_GDB  1
  139         int flags;
  140 } sc[DCONS_NPORT];
  141 static void     dcons_tty_start(struct tty *);
  142 static int      dcons_tty_param(struct tty *, struct termios *);
  143 static void     dcons_timeout(void *);
  144 static int      dcons_drv_init(int);
  145 static int      dcons_getc(struct dcons_softc *);
  146 static int      dcons_checkc(struct dcons_softc *);
  147 static void     dcons_putc(struct dcons_softc *, int);
  148 
  149 static cn_probe_t       dcons_cnprobe;
  150 static cn_init_t        dcons_cninit;
  151 static cn_getc_t        dcons_cngetc;
  152 static cn_checkc_t      dcons_cncheckc;
  153 static cn_putc_t        dcons_cnputc;
  154 
  155 CONS_DRIVER(dcons, dcons_cnprobe, dcons_cninit, NULL, dcons_cngetc,
  156     dcons_cncheckc, dcons_cnputc, NULL);
  157 
  158 #if __FreeBSD_version < 500000
  159 #define THREAD  proc
  160 #else
  161 #define THREAD  thread
  162 #endif
  163 
  164 static int
  165 dcons_open(dev_t dev, int flag, int mode, struct THREAD *td)
  166 {
  167         struct tty *tp;
  168         int unit, error, s;
  169 
  170         unit = minor(dev);
  171         if (unit != 0)
  172                 return (ENXIO);
  173 
  174         tp = dev->si_tty = ttymalloc(dev->si_tty);
  175         tp->t_oproc = dcons_tty_start;
  176         tp->t_param = dcons_tty_param;
  177         tp->t_stop = nottystop;
  178         tp->t_dev = dev;
  179 
  180         error = 0;
  181 
  182         s = spltty();
  183         if ((tp->t_state & TS_ISOPEN) == 0) {
  184                 tp->t_state |= TS_CARR_ON;
  185                 ttychars(tp);
  186                 tp->t_iflag = TTYDEF_IFLAG;
  187                 tp->t_oflag = TTYDEF_OFLAG;
  188                 tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
  189                 tp->t_lflag = TTYDEF_LFLAG;
  190                 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
  191                 ttsetwater(tp);
  192         } else if ((tp->t_state & TS_XCLUDE) && suser(td)) {
  193                 splx(s);
  194                 return (EBUSY);
  195         }
  196         splx(s);
  197 
  198         error = (*linesw[tp->t_line].l_open)(dev, tp);
  199 
  200         return (error);
  201 }
  202 
  203 static int
  204 dcons_close(dev_t dev, int flag, int mode, struct THREAD *td)
  205 {
  206         int     unit;
  207         struct  tty *tp;
  208 
  209         unit = minor(dev);
  210         if (unit != 0)
  211                 return (ENXIO);
  212 
  213         tp = dev->si_tty;
  214         if (tp->t_state & TS_ISOPEN) {
  215                 (*linesw[tp->t_line].l_close)(tp, flag);
  216                 ttyclose(tp);
  217         }
  218 
  219         return (0);
  220 }
  221 
  222 static int
  223 dcons_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct THREAD *td)
  224 {
  225         int     unit;
  226         struct  tty *tp;
  227         int     error;
  228 
  229         unit = minor(dev);
  230         if (unit != 0)
  231                 return (ENXIO);
  232 
  233         tp = dev->si_tty;
  234         error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
  235         if (error != ENOIOCTL)
  236                 return (error);
  237 
  238         error = ttioctl(tp, cmd, data, flag);
  239         if (error != ENOIOCTL)
  240                 return (error);
  241 
  242         return (ENOTTY);
  243 }
  244 
  245 static int
  246 dcons_tty_param(struct tty *tp, struct termios *t)
  247 {
  248         tp->t_ispeed = t->c_ispeed;
  249         tp->t_ospeed = t->c_ospeed;
  250         tp->t_cflag = t->c_cflag;
  251         return 0;
  252 }
  253 
  254 static void
  255 dcons_tty_start(struct tty *tp)
  256 {
  257         struct dcons_softc *dc;
  258         int s;
  259 
  260         dc = (struct dcons_softc *)tp->t_dev->si_drv1;
  261         s = spltty();
  262         if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
  263                 ttwwakeup(tp);
  264                 return;
  265         }
  266 
  267         tp->t_state |= TS_BUSY;
  268         while (tp->t_outq.c_cc != 0)
  269                 dcons_putc(dc, getc(&tp->t_outq));
  270         tp->t_state &= ~TS_BUSY;
  271 
  272         ttwwakeup(tp);
  273         splx(s);
  274 }
  275 
  276 static void
  277 dcons_timeout(void *v)
  278 {
  279         struct  tty *tp;
  280         struct dcons_softc *dc;
  281         int i, c, polltime;
  282 
  283         for (i = 0; i < DCONS_NPORT; i ++) {
  284                 dc = &sc[i];
  285                 tp = dc->dev->si_tty;
  286                 while ((c = dcons_checkc(dc)) != -1)
  287                         if (tp->t_state & TS_ISOPEN)
  288                                 (*linesw[tp->t_line].l_rint)(c, tp);
  289         }
  290         polltime = hz / poll_hz;
  291         if (polltime < 1)
  292                 polltime = 1;
  293         callout_reset(&dcons_callout, polltime, dcons_timeout, tp);
  294 }
  295 
  296 static void
  297 dcons_cnprobe(struct consdev *cp)
  298 {
  299 #if __FreeBSD_version >= 501109
  300         sprintf(cp->cn_name, "dcons");
  301 #else
  302         cp->cn_dev = makedev(CDEV_MAJOR, DCONS_CON);
  303 #endif
  304 #if DCONS_FORCE_CONSOLE
  305         cp->cn_pri = CN_REMOTE;
  306 #else
  307         cp->cn_pri = CN_NORMAL;
  308 #endif
  309 }
  310 
  311 static void
  312 dcons_cninit(struct consdev *cp)
  313 {
  314         dcons_drv_init(0);
  315 #if CONS_NODEV
  316         cp->cn_arg
  317 #else
  318         cp->cn_dev->si_drv1
  319 #endif
  320                 = (void *)&sc[DCONS_CON]; /* share port0 with unit0 */
  321 }
  322 
  323 #if CONS_NODEV
  324 static int
  325 dcons_cngetc(struct consdev *cp)
  326 {
  327         return(dcons_getc((struct dcons_softc *)cp->cn_arg));
  328 }
  329 static int
  330 dcons_cncheckc(struct consdev *cp)
  331 {
  332         return(dcons_checkc((struct dcons_softc *)cp->cn_arg)); 
  333 }
  334 static void
  335 dcons_cnputc(struct consdev *cp, int c)
  336 {
  337         dcons_putc((struct dcons_softc *)cp->cn_arg, c);
  338 }
  339 #else
  340 static int
  341 dcons_cngetc(dev_t dev)
  342 {
  343         return(dcons_getc((struct dcons_softc *)dev->si_drv1));
  344 }
  345 static int
  346 dcons_cncheckc(dev_t dev)
  347 {
  348         return(dcons_checkc((struct dcons_softc *)dev->si_drv1));
  349 }
  350 static void
  351 dcons_cnputc(dev_t dev, int c)
  352 {
  353         dcons_putc((struct dcons_softc *)dev->si_drv1, c);
  354 }
  355 #endif
  356 
  357 static int
  358 dcons_getc(struct dcons_softc *dc)
  359 {
  360         int c;
  361 
  362         while ((c = dcons_checkc(dc)) == -1);
  363 
  364         return (c & 0xff);
  365 }
  366 
  367 static int
  368 dcons_checkc(struct dcons_softc *dc)
  369 {
  370         unsigned char c;
  371         u_int32_t ptr, pos, gen, next_gen;
  372         struct dcons_ch *ch;
  373 
  374         ch = &dc->i;
  375 
  376         if (dcons_dma_tag != NULL)
  377                 bus_dmamap_sync(dcons_dma_tag, dcons_dma_map,
  378                                                 BUS_DMASYNC_POSTREAD);
  379         ptr = ntohl(*ch->ptr);
  380         gen = ptr >> DCONS_GEN_SHIFT;
  381         pos = ptr & DCONS_POS_MASK;
  382         if (gen == ch->gen && pos == ch->pos)
  383                 return (-1);
  384 
  385         next_gen = DCONS_NEXT_GEN(ch->gen);
  386         /* XXX sanity check */
  387         if ((gen != ch->gen && gen != next_gen)
  388                         || (gen == ch->gen && pos < ch->pos)) {
  389                 /* generation skipped !! */
  390                 /* XXX discard */
  391                 ch->gen = gen;
  392                 ch->pos = pos;
  393                 return (-1);
  394         }
  395 
  396         c = ch->buf[ch->pos];
  397         ch->pos ++;
  398         if (ch->pos >= ch->size) {
  399                 ch->gen = next_gen;
  400                 ch->pos = 0;
  401         }
  402 
  403 #if DDB && ALT_BREAK_TO_DEBUGGER
  404         switch (dc->brk_state) {
  405         case STATE1:
  406                 if (c == KEY_TILDE)
  407                         dc->brk_state = STATE2;
  408                 else
  409                         dc->brk_state = STATE0;
  410                 break;
  411         case STATE2:
  412                 dc->brk_state = STATE0;
  413                 if (c == KEY_CTRLB) {
  414 #if DCONS_FORCE_GDB
  415                         if (dc->flags & DC_GDB)
  416                                 boothowto |= RB_GDB;
  417 #endif
  418                         breakpoint();
  419                 }
  420         }
  421         if (c == KEY_CR)
  422                 dc->brk_state = STATE1;
  423 #endif
  424         return (c);
  425 }
  426 
  427 static void
  428 dcons_putc(struct dcons_softc *dc, int c)
  429 {
  430         struct dcons_ch *ch;
  431 
  432         ch = &dc->o;
  433 
  434         ch->buf[ch->pos] = c;
  435         ch->pos ++;
  436         if (ch->pos >= ch->size) {
  437                 ch->gen = DCONS_NEXT_GEN(ch->gen);
  438                 ch->pos = 0;
  439         }
  440         *ch->ptr = DCONS_MAKE_PTR(ch);
  441         if (dcons_dma_tag != NULL)
  442                 bus_dmamap_sync(dcons_dma_tag, dcons_dma_map,
  443                                                 BUS_DMASYNC_PREWRITE);
  444 }
  445 
  446 static int
  447 dcons_init_port(int port, int offset, int size)
  448 {
  449         int osize;
  450         struct dcons_softc *dc;
  451 
  452         dc = &sc[port];
  453 
  454         osize = size * 3 / 4;
  455 
  456         dc->o.size = osize;
  457         dc->i.size = size - osize;
  458         dc->o.buf = (char *)dcons_buf + offset;
  459         dc->i.buf = dc->o.buf + osize;
  460         dc->o.gen = dc->i.gen = 0;
  461         dc->o.pos = dc->i.pos = 0;
  462         dc->o.ptr = &dcons_buf->optr[port];
  463         dc->i.ptr = &dcons_buf->iptr[port];
  464         dc->brk_state = STATE0;
  465         dcons_buf->osize[port] = htonl(osize);
  466         dcons_buf->isize[port] = htonl(size - osize);
  467         dcons_buf->ooffset[port] = htonl(offset);
  468         dcons_buf->ioffset[port] = htonl(offset + osize);
  469         dcons_buf->optr[port] = DCONS_MAKE_PTR(&dc->o);
  470         dcons_buf->iptr[port] = DCONS_MAKE_PTR(&dc->i);
  471 
  472         return(0);
  473 }
  474 
  475 static int
  476 dcons_drv_init(int stage)
  477 {
  478         int size, size0, offset;
  479 
  480         if (drv_init)
  481                 return(drv_init);
  482 
  483         drv_init = -1;
  484 
  485         dcons_bufsize = DCONS_BUF_SIZE;
  486 
  487 #ifndef KLD_MODULE
  488         if (stage == 0) /* XXX or cold */
  489                 /*
  490                  * DCONS_FORCE_CONSOLE == 1 and statically linked.
  491                  * called from cninit(). can't use contigmalloc yet .
  492                  */
  493                 dcons_buf = (struct dcons_buf *) bssbuf;
  494         else
  495 #endif
  496                 /*
  497                  * DCONS_FORCE_CONSOLE == 0 or kernel module case.
  498                  * if the module is loaded after boot,
  499                  * dcons_buf could be non-continuous.
  500                  */ 
  501                 dcons_buf = (struct dcons_buf *) contigmalloc(dcons_bufsize,
  502                         M_DEVBUF, 0, 0x10000, 0xffffffff, PAGE_SIZE, 0ul);
  503 
  504         offset = DCONS_HEADER_SIZE;
  505         size = (dcons_bufsize - offset);
  506         size0 = size * 3 / 4;
  507 
  508         dcons_init_port(0, offset, size0);
  509         offset += size0;
  510         dcons_init_port(1, offset, size - size0);
  511         dcons_buf->version = htonl(DCONS_VERSION);
  512         dcons_buf->magic = ntohl(DCONS_MAGIC);
  513 
  514 #if DDB && DCONS_FORCE_GDB
  515 #if CONS_NODEV
  516         gdbconsdev.cn_arg = (void *)&sc[DCONS_GDB];
  517 #if __FreeBSD_version >= 501109
  518         sprintf(gdbconsdev.cn_name, "dgdb");
  519 #endif
  520         gdb_arg = &gdbconsdev;
  521 #else
  522         gdbdev = makedev(CDEV_MAJOR, DCONS_GDB);
  523 #endif
  524         gdb_getc = dcons_cngetc;
  525         gdb_putc = dcons_cnputc;
  526 #endif
  527         drv_init = 1;
  528 
  529         return 0;
  530 }
  531 
  532 
  533 static int
  534 dcons_attach_port(int port, char *name, int flags)
  535 {
  536         struct dcons_softc *dc;
  537         struct tty *tp;
  538 
  539         dc = &sc[port];
  540         dc->flags = flags;
  541         dc->dev = make_dev(&dcons_cdevsw, port,
  542                         UID_ROOT, GID_WHEEL, 0600, name);
  543         tp = ttymalloc(NULL);
  544 
  545         dc->dev->si_drv1 = (void *)dc;
  546         dc->dev->si_tty = tp;
  547 
  548         tp->t_oproc = dcons_tty_start;
  549         tp->t_param = dcons_tty_param;
  550         tp->t_stop = nottystop;
  551         tp->t_dev = dc->dev;
  552 
  553         return(0);
  554 }
  555 
  556 static int
  557 dcons_attach(void)
  558 {
  559         int polltime;
  560 
  561         dcons_attach_port(DCONS_CON, "dcons", 0);
  562         dcons_attach_port(DCONS_GDB, "dgdb", DC_GDB);
  563 #if __FreeBSD_version < 500000
  564         callout_init(&dcons_callout);
  565 #else
  566         callout_init(&dcons_callout, 0);
  567 #endif
  568         polltime = hz / poll_hz;
  569         if (polltime < 1)
  570                 polltime = 1;
  571         callout_reset(&dcons_callout, polltime, dcons_timeout, NULL);
  572         return(0);
  573 }
  574 
  575 static int
  576 dcons_detach(int port)
  577 {
  578         struct  tty *tp;
  579         struct dcons_softc *dc;
  580 
  581         dc = &sc[port];
  582 
  583         tp = dc->dev->si_tty;
  584 
  585         if (tp->t_state & TS_ISOPEN) {
  586                 printf("dcons: still opened\n");
  587                 (*linesw[tp->t_line].l_close)(tp, 0);
  588                 tp->t_gen++;
  589                 ttyclose(tp);
  590                 ttwakeup(tp);
  591                 ttwwakeup(tp);
  592         }
  593         /* XXX
  594          * must wait until all device are closed.
  595          */
  596         tsleep((void *)dc, PWAIT, "dcodtc", hz/4);
  597         destroy_dev(dc->dev);
  598 
  599         return(0);
  600 }
  601 
  602 
  603 /* cnXXX works only for FreeBSD-5 */
  604 static int
  605 dcons_modevent(module_t mode, int type, void *data)
  606 {
  607         int err = 0, ret;
  608 
  609         switch (type) {
  610         case MOD_LOAD:
  611                 ret = dcons_drv_init(1);
  612                 dcons_attach();
  613 #if __FreeBSD_version >= 500000
  614                 if (ret == 0) {
  615                         dcons_cnprobe(&dcons_consdev);
  616                         dcons_cninit(&dcons_consdev);
  617                         cnadd(&dcons_consdev);
  618                 }
  619 #endif
  620                 break;
  621         case MOD_UNLOAD:
  622                 printf("dcons: unload\n");
  623                 callout_stop(&dcons_callout);
  624 #if DDB && DCONS_FORCE_GDB
  625 #if CONS_NODEV
  626                 gdb_arg = NULL;
  627 #else
  628                 gdbdev = NODEV;
  629 #endif
  630 #endif
  631 #if __FreeBSD_version >= 500000
  632                 cnremove(&dcons_consdev);
  633 #endif
  634                 dcons_detach(DCONS_CON);
  635                 dcons_detach(DCONS_GDB);
  636                 dcons_buf->magic = 0;
  637 
  638                 contigfree(dcons_buf, DCONS_BUF_SIZE, M_DEVBUF);
  639 
  640                 break;
  641         case MOD_SHUTDOWN:
  642                 break;
  643         }
  644         return(err);
  645 }
  646 
  647 DEV_MODULE(dcons, dcons_modevent, NULL);
  648 MODULE_VERSION(dcons, DCONS_VERSION);

Cache object: 5dd674591e01fa7cfbe8c5536a148857


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