2 * Copyright (c) 2000 Doug Rabson
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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR 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
28 #include <sys/param.h>
32 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/mutex.h>
38 #include <sys/systm.h>
40 #include <machine/md_var.h>
43 #include <vm/vm_param.h>
44 #include <vm/vm_kern.h>
45 #include <vm/vm_page.h>
46 #include <vm/vm_map.h>
47 #include <vm/vm_object.h>
48 #include <vm/vm_extern.h>
49 #include <vm/vm_pageout.h>
50 #include <vm/vm_pager.h>
52 #define SSC_GETCHAR 21
53 #define SSC_PUTCHAR 31
55 #define SSC_POLL_HZ 50
57 static d_open_t ssc_open;
58 static d_close_t ssc_close;
60 static struct cdevsw ssc_cdevsw = {
61 .d_version = D_VERSION,
65 .d_flags = D_TTY | D_NEEDGIANT,
68 static struct tty *ssc_tp = NULL;
70 static struct callout_handle ssc_timeouthandle
71 = CALLOUT_HANDLE_INITIALIZER(&ssc_timeouthandle);
73 static void ssc_start(struct tty *);
74 static void ssc_timeout(void *);
75 static int ssc_param(struct tty *, struct termios *);
76 static void ssc_stop(struct tty *, int);
79 ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3, int which)
81 register u_int64_t ret0 __asm("r8");
83 __asm __volatile("mov r15=%1\n\t"
86 : "r"(which), "r"(in0), "r"(in1), "r"(in2), "r"(in3));
91 ssc_cnprobe(struct consdev *cp)
93 sprintf(cp->cn_name, "ssccons");
94 cp->cn_pri = CN_INTERNAL;
98 ssc_cninit(struct consdev *cp)
103 ssc_cnterm(struct consdev *cp)
108 ssc_cnattach(void *arg)
110 make_dev(&ssc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "ssccons");
114 SYSINIT(ssc_cnattach, SI_SUB_DRIVERS, SI_ORDER_ANY, ssc_cnattach, 0);
117 ssc_cnputc(struct consdev *cp, int c)
119 ssc(c, 0, 0, 0, SSC_PUTCHAR);
123 ssc_cngetc(struct consdev *cp)
126 c = ssc(0, 0, 0, 0, SSC_GETCHAR);
133 ssc_open(struct cdev *dev, int flag, int mode, struct thread *td)
137 int error = 0, setuptimeout = 0;
139 tp = dev->si_tty = ssc_tp;
142 tp->t_oproc = ssc_start;
143 tp->t_param = ssc_param;
144 tp->t_stop = ssc_stop;
146 if ((tp->t_state & TS_ISOPEN) == 0) {
147 tp->t_state |= TS_CARR_ON;
148 ttyconsolemode(tp, 0);
151 } else if ((tp->t_state & TS_XCLUDE) &&
152 priv_check(td, PRIV_TTY_EXCLUSIVE)) {
159 error = ttyld_open(tp, dev);
161 if (error == 0 && setuptimeout) {
162 polltime = hz / SSC_POLL_HZ;
165 ssc_timeouthandle = timeout(ssc_timeout, tp, polltime);
171 ssc_close(struct cdev *dev, int flag, int mode, struct thread *td)
173 int unit = minor(dev);
174 struct tty *tp = ssc_tp;
179 untimeout(ssc_timeout, tp, ssc_timeouthandle);
180 ttyld_close(tp, flag);
186 ssc_param(struct tty *tp, struct termios *t)
193 ssc_start(struct tty *tp)
199 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
205 tp->t_state |= TS_BUSY;
206 while (tp->t_outq.c_cc != 0)
207 ssc_cnputc(NULL, getc(&tp->t_outq));
208 tp->t_state &= ~TS_BUSY;
215 * Stop output on a line.
218 ssc_stop(struct tty *tp, int flag)
223 if (tp->t_state & TS_BUSY)
224 if ((tp->t_state & TS_TTSTOP) == 0)
225 tp->t_state |= TS_FLUSH;
235 while ((c = ssc_cngetc(NULL)) != -1) {
236 if (tp->t_state & TS_ISOPEN)
239 ssc_timeouthandle = timeout(ssc_timeout, tp, polltime);