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 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 |
53static tsw_open_t cfe_tty_open; 54static tsw_close_t cfe_tty_close; 55static tsw_outwakeup_t cfe_tty_outwakeup; |
56 |
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 |
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]; |
89 struct tty *tp; |
90 91 if (cfe_consdev.cn_pri != CN_DEAD && 92 cfe_consdev.cn_name[0] != '\0') { |
93 tp = tty_alloc(&cfe_ttydevsw, NULL, NULL); 94 tty_makedev(tp, NULL, "%s", output); 95 tty_makealias(tp, "cfecons"); |
96 } 97} 98 99static int |
100cfe_tty_open(struct tty *tp) |
101{ |
102 polltime = hz / CFECONS_POLL_HZ; 103 if (polltime < 1) 104 polltime = 1; 105 cfe_timeouthandle = timeout(cfe_timeout, tp, polltime); |
106 |
107 return (0); |
108} 109 |
110static void 111cfe_tty_close(struct tty *tp) |
112{ |
113 |
114 /* XXX Should be replaced with callout_stop(9) */ 115 untimeout(cfe_timeout, tp, cfe_timeouthandle); |
116} 117 |
118static void |
119cfe_tty_outwakeup(struct tty *tp) |
120{ |
121 int len; 122 u_char buf[CFEBURSTLEN]; 123 |
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 ; |
130 } 131} 132 133static void 134cfe_timeout(void *v) 135{ 136 struct tty *tp; 137 int c; 138 139 tp = (struct tty *)v; 140 |
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); |
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) |
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 } |
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 |
234SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL); |