Deleted Added
full compact
cfe_console.c (183374) cfe_console.c (183376)
1/*-
2 * Copyright (c) 2007 Bruce M. Simpson.
3 * 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

--- 11 unchanged lines hidden (view full) ---

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
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Bruce M. Simpson.
3 * 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

--- 11 unchanged lines hidden (view full) ---

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
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/cfe/cfe_console.c 183374 2008-09-26 05:10:57Z imp $");
28__FBSDID("$FreeBSD: head/sys/dev/cfe/cfe_console.c 183376 2008-09-26 05:37:54Z imp $");
29
30#include "opt_comconsole.h"
31
32#include <sys/param.h>
33#include <sys/kdb.h>
34#include <sys/kernel.h>
35#include <sys/priv.h>
36#include <sys/systm.h>

--- 8 unchanged lines hidden (view full) ---

45
46#include <ddb/ddb.h>
47
48#ifndef CFECONS_POLL_HZ
49#define CFECONS_POLL_HZ 4
50#endif
51#define CFEBURSTLEN 128 /* max number of bytes to write in one chunk */
52
29
30#include "opt_comconsole.h"
31
32#include <sys/param.h>
33#include <sys/kdb.h>
34#include <sys/kernel.h>
35#include <sys/priv.h>
36#include <sys/systm.h>

--- 8 unchanged lines hidden (view full) ---

45
46#include <ddb/ddb.h>
47
48#ifndef CFECONS_POLL_HZ
49#define CFECONS_POLL_HZ 4
50#endif
51#define CFEBURSTLEN 128 /* max number of bytes to write in one chunk */
52
53static d_open_t cfe_dev_open;
54static d_close_t cfe_dev_close;
53static tsw_open_t cfe_tty_open;
54static tsw_close_t cfe_tty_close;
55static tsw_outwakeup_t cfe_tty_outwakeup;
55
56
56static struct cdevsw cfe_cdevsw = {
57 .d_version = D_VERSION,
58 .d_open = cfe_dev_open,
59 .d_close = cfe_dev_close,
60 .d_name = "cfe",
61 .d_flags = D_TTY | D_NEEDGIANT,
57static struct ttydevsw cfe_ttydevsw = {
58 .tsw_flags = TF_NOPREFIX,
59 .tsw_open = cfe_tty_open,
60 .tsw_close = cfe_tty_close,
61 .tsw_outwakeup = cfe_tty_outwakeup,
62};
63
64static int conhandle = -1;
65static struct tty *cfe_tp = NULL;
66/* XXX does cfe have to poll? */
67static int polltime;
68static struct callout_handle cfe_timeouthandle
69 = CALLOUT_HANDLE_INITIALIZER(&cfe_timeouthandle);
70
71#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
72static int alt_break_state;
73#endif
74
62};
63
64static int conhandle = -1;
65static struct tty *cfe_tp = NULL;
66/* XXX does cfe have to poll? */
67static int polltime;
68static struct callout_handle cfe_timeouthandle
69 = CALLOUT_HANDLE_INITIALIZER(&cfe_timeouthandle);
70
71#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
72static int alt_break_state;
73#endif
74
75static void cfe_tty_start(struct tty *);
76static int cfe_tty_param(struct tty *, struct termios *);
77static void cfe_tty_stop(struct tty *, int);
78static void cfe_timeout(void *);
79
80static cn_probe_t cfe_cnprobe;
81static cn_init_t cfe_cninit;
82static cn_term_t cfe_cnterm;
83static cn_getc_t cfe_cngetc;
84static cn_putc_t cfe_cnputc;
85
86CONSOLE_DRIVER(cfe);
87
88static void
89cn_drvinit(void *unused)
90{
91 char output[32];
75static void cfe_timeout(void *);
76
77static cn_probe_t cfe_cnprobe;
78static cn_init_t cfe_cninit;
79static cn_term_t cfe_cnterm;
80static cn_getc_t cfe_cngetc;
81static cn_putc_t cfe_cnputc;
82
83CONSOLE_DRIVER(cfe);
84
85static void
86cn_drvinit(void *unused)
87{
88 char output[32];
92 struct cdev *dev;
89 struct tty *tp;
93
94 if (cfe_consdev.cn_pri != CN_DEAD &&
95 cfe_consdev.cn_name[0] != '\0') {
90
91 if (cfe_consdev.cn_pri != CN_DEAD &&
92 cfe_consdev.cn_name[0] != '\0') {
96 dev = make_dev(&cfe_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "%s",
97 output);
98 make_dev_alias(dev, "cfecons");
93 tp = tty_alloc(&cfe_ttydevsw, NULL, NULL);
94 tty_makedev(tp, NULL, "%s", output);
95 tty_makealias(tp, "cfecons");
99 }
100}
101
102static int
96 }
97}
98
99static int
103cfe_dev_open(struct cdev *dev, int flag, int mode, struct thread *td)
100cfe_tty_open(struct tty *tp)
104{
101{
105 struct tty *tp;
106 int unit;
107 int error, setuptimeout;
102 polltime = hz / CFECONS_POLL_HZ;
103 if (polltime < 1)
104 polltime = 1;
105 cfe_timeouthandle = timeout(cfe_timeout, tp, polltime);
108
106
109 error = 0;
110 setuptimeout = 0;
111 unit = minor(dev);
112
113 /*
114 * XXX: BAD, should happen at attach time
115 */
116 if (dev->si_tty == NULL) {
117 cfe_tp = ttyalloc();
118 dev->si_tty = cfe_tp;
119 cfe_tp->t_dev = dev;
120 }
121 tp = dev->si_tty;
122
123 tp->t_oproc = cfe_tty_start;
124 tp->t_param = cfe_tty_param;
125 tp->t_stop = cfe_tty_stop;
126 tp->t_dev = dev;
127
128 if ((tp->t_state & TS_ISOPEN) == 0) {
129 tp->t_state |= TS_CARR_ON;
130 ttyconsolemode(tp, 0);
131
132 setuptimeout = 1;
133 } else if ((tp->t_state & TS_XCLUDE) &&
134 priv_check(td, PRIV_TTY_EXCLUSIVE)) {
135 return (EBUSY);
136 }
137
138 error = ttyld_open(tp, dev);
139
140 if (error == 0 && setuptimeout) {
141 polltime = hz / CFECONS_POLL_HZ;
142 if (polltime < 1) {
143 polltime = 1;
144 }
145
146 cfe_timeouthandle = timeout(cfe_timeout, tp, polltime);
147 }
148
149 return (error);
107 return (0);
150}
151
108}
109
152static int
153cfe_dev_close(struct cdev *dev, int flag, int mode, struct thread *td)
110static void
111cfe_tty_close(struct tty *tp)
154{
112{
155 int unit;
156 struct tty *tp;
157
113
158 unit = minor(dev);
159 tp = dev->si_tty;
160
161 if (unit != 0) {
162 return (ENXIO);
163 }
164
165 /* XXX Should be replaced with callout_stop(9) */
166 untimeout(cfe_timeout, tp, cfe_timeouthandle);
114 /* XXX Should be replaced with callout_stop(9) */
115 untimeout(cfe_timeout, tp, cfe_timeouthandle);
167 ttyld_close(tp, flag);
168 tty_close(tp);
169
170 return (0);
171}
172
116}
117
173
174static int
175cfe_tty_param(struct tty *tp, struct termios *t)
176{
177
178 return (0);
179}
180
181static void
118static void
182cfe_tty_start(struct tty *tp)
119cfe_tty_outwakeup(struct tty *tp)
183{
120{
184 struct clist *cl;
185 int len;
186 u_char buf[CFEBURSTLEN];
187
121 int len;
122 u_char buf[CFEBURSTLEN];
123
188 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
189 return;
190
191 tp->t_state |= TS_BUSY;
192 cl = &tp->t_outq;
193 len = q_to_b(cl, buf, CFEBURSTLEN);
194 while (cfe_write(conhandle, buf, len) == 0)
195 ;
196 tp->t_state &= ~TS_BUSY;
197
198 ttwwakeup(tp);
199}
200
201static void
202cfe_tty_stop(struct tty *tp, int flag)
203{
204
205 if (tp->t_state & TS_BUSY) {
206 if ((tp->t_state & TS_TTSTOP) == 0) {
207 tp->t_state |= TS_FLUSH;
208 }
124 for (;;) {
125 len = ttydisc_getc(tp, buf, sizeof buf);
126 if (len == 0)
127 break;
128 while (cfe_write(conhandle, buf, len) == 0)
129 ;
209 }
210}
211
212static void
213cfe_timeout(void *v)
214{
215 struct tty *tp;
216 int c;
217
218 tp = (struct tty *)v;
219
130 }
131}
132
133static void
134cfe_timeout(void *v)
135{
136 struct tty *tp;
137 int c;
138
139 tp = (struct tty *)v;
140
220 while ((c = cfe_cngetc(NULL)) != -1) {
221 if (tp->t_state & TS_ISOPEN) {
222 ttyld_rint(tp, c);
223 }
224 }
141 tty_lock(tp);
142 while ((c = cfe_cngetc(NULL)) != -1)
143 ttydisc_rint(tp, c, 0);
144 ttydisc_rint_done(tp);
145 tty_unlock(tp);
225
226 cfe_timeouthandle = timeout(cfe_timeout, tp, polltime);
227}
228
229static void
230cfe_cnprobe(struct consdev *cp)
231{
232

--- 35 unchanged lines hidden (view full) ---

268 int result;
269 unsigned char ch;
270
271 while ((result = cfe_read(conhandle, &ch, 1)) == 0)
272 ;
273
274 if (result > 0) {
275#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
146
147 cfe_timeouthandle = timeout(cfe_timeout, tp, polltime);
148}
149
150static void
151cfe_cnprobe(struct consdev *cp)
152{
153

--- 35 unchanged lines hidden (view full) ---

189 int result;
190 unsigned char ch;
191
192 while ((result = cfe_read(conhandle, &ch, 1)) == 0)
193 ;
194
195 if (result > 0) {
196#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
276 if (kdb_alt_break(ch, &alt_break_state))
277 kdb_enter(KDB_WHY_BREAK, "Break sequence on console");
197 int kdb_brk;
198
199 if ((kdb_brk = kdb_alt_break(ch, &alt_break_state)) != 0) {
200 switch (kdb_brk) {
201 case KDB_REQ_DEBUGGER:
202 kdb_enter(KDB_WHY_BREAK,
203 "Break sequence on console");
204 break;
205 case KDB_REQ_PANIC:
206 kdb_panic("Panic sequence on console");
207 break;
208 case KDB_REQ_REBOOT:
209 kdb_reboot();
210 break;
211
212 }
213 }
278#endif
279 return (ch);
280 }
281
282 return (-1);
283}
284
285static void

--- 4 unchanged lines hidden (view full) ---

290 if (c == '\n')
291 cfe_cnputc(cp, '\r');
292
293 cbuf = c;
294 while (cfe_write(conhandle, &cbuf, 1) == 0)
295 ;
296}
297
214#endif
215 return (ch);
216 }
217
218 return (-1);
219}
220
221static void

--- 4 unchanged lines hidden (view full) ---

226 if (c == '\n')
227 cfe_cnputc(cp, '\r');
228
229 cbuf = c;
230 while (cfe_write(conhandle, &cbuf, 1) == 0)
231 ;
232}
233
298SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL)
234SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);