2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011 NetApp, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
37 #include <sys/types.h>
40 #include <sys/reboot.h>
46 #ifndef BVMCONS_POLL_HZ
47 #define BVMCONS_POLL_HZ 4
49 #define BVMBURSTLEN 16 /* max number of bytes to write in one chunk */
51 static tsw_open_t bvm_tty_open;
52 static tsw_close_t bvm_tty_close;
53 static tsw_outwakeup_t bvm_tty_outwakeup;
55 static struct ttydevsw bvm_ttydevsw = {
56 .tsw_flags = TF_NOPREFIX,
57 .tsw_open = bvm_tty_open,
58 .tsw_close = bvm_tty_close,
59 .tsw_outwakeup = bvm_tty_outwakeup,
63 static struct callout bvm_timer;
66 static int alt_break_state;
69 #define BVM_CONS_PORT 0x220
70 static int bvm_cons_port = BVM_CONS_PORT;
72 #define BVM_CONS_SIG ('b' << 8 | 'v')
74 static void bvm_timeout(void *);
76 static cn_probe_t bvm_cnprobe;
77 static cn_init_t bvm_cninit;
78 static cn_term_t bvm_cnterm;
79 static cn_getc_t bvm_cngetc;
80 static cn_putc_t bvm_cnputc;
81 static cn_grab_t bvm_cngrab;
82 static cn_ungrab_t bvm_cnungrab;
91 c = inl(bvm_cons_port);
103 outl(bvm_cons_port, ch);
107 cn_drvinit(void *unused)
111 gone_in(13, "bvmconsole");
113 if (bvm_consdev.cn_pri != CN_DEAD) {
114 tp = tty_alloc(&bvm_ttydevsw, NULL);
115 callout_init_mtx(&bvm_timer, tty_getlock(tp), 0);
116 tty_makedev(tp, NULL, "bvmcons");
121 bvm_tty_open(struct tty *tp)
123 polltime = hz / BVMCONS_POLL_HZ;
126 callout_reset(&bvm_timer, polltime, bvm_timeout, tp);
132 bvm_tty_close(struct tty *tp)
135 tty_assert_locked(tp);
136 callout_stop(&bvm_timer);
140 bvm_tty_outwakeup(struct tty *tp)
143 u_char buf[BVMBURSTLEN];
146 len = ttydisc_getc(tp, buf, sizeof(buf));
151 while (written < len)
152 bvm_wcons(buf[written++]);
162 tp = (struct tty *)v;
164 tty_assert_locked(tp);
165 while ((c = bvm_cngetc(NULL)) != -1)
166 ttydisc_rint(tp, c, 0);
167 ttydisc_rint_done(tp);
169 callout_reset(&bvm_timer, polltime, bvm_timeout, tp);
173 bvm_cnprobe(struct consdev *cp)
178 cp->cn_pri = CN_DEAD;
179 strcpy(cp->cn_name, "bvmcons");
181 resource_int_value("bvmconsole", 0, "disabled", &disabled);
183 if (resource_int_value("bvmconsole", 0, "port", &port) == 0)
184 bvm_cons_port = port;
186 if (inw(bvm_cons_port) == BVM_CONS_SIG)
187 cp->cn_pri = CN_REMOTE;
192 bvm_cninit(struct consdev *cp)
195 const char *bootmsg = "Using bvm console.\n";
197 if (boothowto & RB_VERBOSE) {
198 for (i = 0; i < strlen(bootmsg); i++)
199 bvm_cnputc(cp, bootmsg[i]);
204 bvm_cnterm(struct consdev *cp)
210 bvm_cngetc(struct consdev *cp)
214 if (bvm_rcons(&ch) == 0) {
216 kdb_alt_break(ch, &alt_break_state);
225 bvm_cnputc(struct consdev *cp, int c)
232 bvm_cngrab(struct consdev *cp)
237 bvm_cnungrab(struct consdev *cp)
241 SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);