2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2008 by Nathan Whitehorn. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
32 #include <sys/kernel.h>
34 #include <sys/systm.h>
35 #include <sys/types.h>
38 #include <sys/consio.h>
41 #include <dev/ofw/openfirm.h>
45 #include "mambocall.h"
47 #define MAMBOBURSTLEN 128 /* max number of bytes to write in one chunk */
49 #define MAMBO_CONSOLE_WRITE 0
50 #define MAMBO_CONSOLE_READ 60
52 static tsw_outwakeup_t mambotty_outwakeup;
54 static struct ttydevsw mambo_ttydevsw = {
55 .tsw_flags = TF_NOPREFIX,
56 .tsw_outwakeup = mambotty_outwakeup,
60 static struct callout mambo_callout;
61 static struct tty *tp = NULL;
64 static int alt_break_state;
67 static void mambo_timeout(void *);
69 static cn_probe_t mambo_cnprobe;
70 static cn_init_t mambo_cninit;
71 static cn_term_t mambo_cnterm;
72 static cn_getc_t mambo_cngetc;
73 static cn_putc_t mambo_cnputc;
74 static cn_grab_t mambo_cngrab;
75 static cn_ungrab_t mambo_cnungrab;
77 CONSOLE_DRIVER(mambo);
80 cn_drvinit(void *unused)
83 if (mambo_consdev.cn_pri != CN_DEAD &&
84 mambo_consdev.cn_name[0] != '\0') {
85 if (OF_finddevice("/mambo") == -1)
88 tp = tty_alloc(&mambo_ttydevsw, NULL);
89 tty_init_console(tp, 0);
90 tty_makedev(tp, NULL, "%s", "mambocons");
94 callout_init(&mambo_callout, 1);
95 callout_reset(&mambo_callout, polltime, mambo_timeout, NULL);
99 SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);
102 mambotty_outwakeup(struct tty *tp)
105 u_char buf[MAMBOBURSTLEN];
108 len = ttydisc_getc(tp, buf, sizeof buf);
111 mambocall(MAMBO_CONSOLE_WRITE, buf, (register_t)len, 1UL);
116 mambo_timeout(void *v)
121 while ((c = mambo_cngetc(NULL)) != -1)
122 ttydisc_rint(tp, c, 0);
123 ttydisc_rint_done(tp);
126 callout_reset(&mambo_callout, polltime, mambo_timeout, NULL);
130 mambo_cnprobe(struct consdev *cp)
132 if (OF_finddevice("/mambo") == -1) {
133 cp->cn_pri = CN_DEAD;
137 cp->cn_pri = CN_NORMAL;
141 mambo_cninit(struct consdev *cp)
144 /* XXX: This is the alias, but that should be good enough */
145 strcpy(cp->cn_name, "mambocons");
149 mambo_cnterm(struct consdev *cp)
154 mambo_cngrab(struct consdev *cp)
159 mambo_cnungrab(struct consdev *cp)
164 mambo_cngetc(struct consdev *cp)
168 ch = mambocall(MAMBO_CONSOLE_READ);
170 if (ch > 0 && ch < 0xff) {
172 kdb_alt_break(ch, &alt_break_state);
181 mambo_cnputc(struct consdev *cp, int c)
186 mambocall(MAMBO_CONSOLE_WRITE, &cbuf, 1UL, 1UL);