2 * Copyright (c) 2011 NetApp, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/systm.h>
35 #include <sys/types.h>
38 #include <sys/reboot.h>
44 #ifndef BVMCONS_POLL_HZ
45 #define BVMCONS_POLL_HZ 4
47 #define BVMBURSTLEN 16 /* max number of bytes to write in one chunk */
49 static tsw_open_t bvm_tty_open;
50 static tsw_close_t bvm_tty_close;
51 static tsw_outwakeup_t bvm_tty_outwakeup;
53 static struct ttydevsw bvm_ttydevsw = {
54 .tsw_flags = TF_NOPREFIX,
55 .tsw_open = bvm_tty_open,
56 .tsw_close = bvm_tty_close,
57 .tsw_outwakeup = bvm_tty_outwakeup,
61 static struct callout_handle bvm_timeouthandle
62 = CALLOUT_HANDLE_INITIALIZER(&bvm_timeouthandle);
65 static int alt_break_state;
68 #define BVM_CONS_PORT 0x220
69 static int bvm_cons_port = BVM_CONS_PORT;
71 #define BVM_CONS_SIG ('b' << 8 | 'v')
73 static void bvm_timeout(void *);
75 static cn_probe_t bvm_cnprobe;
76 static cn_init_t bvm_cninit;
77 static cn_term_t bvm_cnterm;
78 static cn_getc_t bvm_cngetc;
79 static cn_putc_t bvm_cnputc;
80 static cn_grab_t bvm_cngrab;
81 static cn_ungrab_t bvm_cnungrab;
90 c = inl(bvm_cons_port);
102 outl(bvm_cons_port, ch);
106 cn_drvinit(void *unused)
110 if (bvm_consdev.cn_pri != CN_DEAD &&
111 bvm_consdev.cn_name[0] != '\0') {
112 tp = tty_alloc(&bvm_ttydevsw, NULL);
113 tty_makedev(tp, NULL, "bvmcons");
118 bvm_tty_open(struct tty *tp)
120 polltime = hz / BVMCONS_POLL_HZ;
123 bvm_timeouthandle = timeout(bvm_timeout, tp, polltime);
129 bvm_tty_close(struct tty *tp)
132 /* XXX Should be replaced with callout_stop(9) */
133 untimeout(bvm_timeout, tp, bvm_timeouthandle);
137 bvm_tty_outwakeup(struct tty *tp)
140 u_char buf[BVMBURSTLEN];
143 len = ttydisc_getc(tp, buf, sizeof(buf));
148 while (written < len)
149 bvm_wcons(buf[written++]);
159 tp = (struct tty *)v;
162 while ((c = bvm_cngetc(NULL)) != -1)
163 ttydisc_rint(tp, c, 0);
164 ttydisc_rint_done(tp);
167 bvm_timeouthandle = timeout(bvm_timeout, tp, polltime);
171 bvm_cnprobe(struct consdev *cp)
176 cp->cn_pri = CN_DEAD;
178 resource_int_value("bvmconsole", 0, "disabled", &disabled);
180 if (resource_int_value("bvmconsole", 0, "port", &port) == 0)
181 bvm_cons_port = port;
183 if (inw(bvm_cons_port) == BVM_CONS_SIG)
184 cp->cn_pri = CN_REMOTE;
189 bvm_cninit(struct consdev *cp)
192 const char *bootmsg = "Using bvm console.\n";
194 if (boothowto & RB_VERBOSE) {
195 for (i = 0; i < strlen(bootmsg); i++)
196 bvm_cnputc(cp, bootmsg[i]);
199 strcpy(cp->cn_name, "bvmcons");
203 bvm_cnterm(struct consdev *cp)
209 bvm_cngetc(struct consdev *cp)
213 if (bvm_rcons(&ch) == 0) {
215 kdb_alt_break(ch, &alt_break_state);
224 bvm_cnputc(struct consdev *cp, int c)
231 bvm_cngrab(struct consdev *cp)
236 bvm_cnungrab(struct consdev *cp)
240 SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);