dcons.c (132226) | dcons.c (135733) |
---|---|
1/* 2 * Copyright (C) 2003 3 * Hidetoshi Shimokawa. 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 --- 18 unchanged lines hidden (view full) --- 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * $Id: dcons.c,v 1.65 2003/10/24 03:24:55 simokawa Exp $ | 1/* 2 * Copyright (C) 2003 3 * Hidetoshi Shimokawa. 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 --- 18 unchanged lines hidden (view full) --- 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * $Id: dcons.c,v 1.65 2003/10/24 03:24:55 simokawa Exp $ |
35 * $FreeBSD: head/sys/dev/dcons/dcons.c 132226 2004-07-15 20:47:41Z phk $ | 35 * $FreeBSD: head/sys/dev/dcons/dcons.c 135733 2004-09-24 12:43:57Z simokawa $ |
36 */ 37 38#include <sys/param.h> 39#if __FreeBSD_version >= 502122 40#include <sys/kdb.h> 41#include <gdb/gdb.h> 42#endif 43#include <sys/kernel.h> --- 5 unchanged lines hidden (view full) --- 49#include <sys/consio.h> 50#include <sys/tty.h> 51#include <sys/malloc.h> 52#include <sys/proc.h> 53#include <sys/ucred.h> 54 55#include <machine/bus.h> 56 | 36 */ 37 38#include <sys/param.h> 39#if __FreeBSD_version >= 502122 40#include <sys/kdb.h> 41#include <gdb/gdb.h> 42#endif 43#include <sys/kernel.h> --- 5 unchanged lines hidden (view full) --- 49#include <sys/consio.h> 50#include <sys/tty.h> 51#include <sys/malloc.h> 52#include <sys/proc.h> 53#include <sys/ucred.h> 54 55#include <machine/bus.h> 56 |
57#ifdef __DragonFly__ 58#include "dcons.h" 59#else |
|
57#include <dev/dcons/dcons.h> | 60#include <dev/dcons/dcons.h> |
61#endif |
|
58 59#include <ddb/ddb.h> 60#include <sys/reboot.h> 61 62#include <sys/sysctl.h> 63 64#include "opt_ddb.h" 65#include "opt_comconsole.h" 66#include "opt_dcons.h" 67 68#ifndef DCONS_POLL_HZ 69#define DCONS_POLL_HZ 100 70#endif 71 72#ifndef DCONS_BUF_SIZE 73#define DCONS_BUF_SIZE (16*1024) 74#endif 75 76#ifndef DCONS_FORCE_CONSOLE | 62 63#include <ddb/ddb.h> 64#include <sys/reboot.h> 65 66#include <sys/sysctl.h> 67 68#include "opt_ddb.h" 69#include "opt_comconsole.h" 70#include "opt_dcons.h" 71 72#ifndef DCONS_POLL_HZ 73#define DCONS_POLL_HZ 100 74#endif 75 76#ifndef DCONS_BUF_SIZE 77#define DCONS_BUF_SIZE (16*1024) 78#endif 79 80#ifndef DCONS_FORCE_CONSOLE |
77#define DCONS_FORCE_CONSOLE 0 /* mostly for FreeBSD-4 */ | 81#define DCONS_FORCE_CONSOLE 0 /* Mostly for FreeBSD-4/DragonFly */ |
78#endif 79 80#ifndef DCONS_FORCE_GDB 81#define DCONS_FORCE_GDB 1 82#endif 83 84#if __FreeBSD_version >= 500101 85#define CONS_NODEV 1 86#if __FreeBSD_version < 502122 87static struct consdev gdbconsdev; 88#endif 89#endif 90 | 82#endif 83 84#ifndef DCONS_FORCE_GDB 85#define DCONS_FORCE_GDB 1 86#endif 87 88#if __FreeBSD_version >= 500101 89#define CONS_NODEV 1 90#if __FreeBSD_version < 502122 91static struct consdev gdbconsdev; 92#endif 93#endif 94 |
91 | |
92static d_open_t dcons_open; 93static d_close_t dcons_close; | 95static d_open_t dcons_open; 96static d_close_t dcons_close; |
97#if defined(__DragonFly__) || __FreeBSD_version < 500104 98static d_ioctl_t dcons_ioctl; 99#endif |
|
94 95static struct cdevsw dcons_cdevsw = { | 100 101static struct cdevsw dcons_cdevsw = { |
96#if __FreeBSD_version >= 500104 | 102#ifdef __DragonFly__ 103#define CDEV_MAJOR 184 104 "dcons", CDEV_MAJOR, D_TTY, NULL, 0, 105 dcons_open, dcons_close, ttyread, ttywrite, dcons_ioctl, 106 ttypoll, nommap, nostrategy, nodump, nopsize, 107#elif __FreeBSD_version >= 500104 |
97 .d_version = D_VERSION, 98 .d_open = dcons_open, 99 .d_close = dcons_close, 100 .d_name = "dcons", 101 .d_flags = D_TTY | D_NEEDGIANT, 102#else | 108 .d_version = D_VERSION, 109 .d_open = dcons_open, 110 .d_close = dcons_close, 111 .d_name = "dcons", 112 .d_flags = D_TTY | D_NEEDGIANT, 113#else |
114#define CDEV_MAJOR 184 |
|
103 /* open */ dcons_open, 104 /* close */ dcons_close, 105 /* read */ ttyread, 106 /* write */ ttywrite, 107 /* ioctl */ dcons_ioctl, 108 /* poll */ ttypoll, 109 /* mmap */ nommap, 110 /* strategy */ nostrategy, 111 /* name */ "dcons", 112 /* major */ CDEV_MAJOR, 113 /* dump */ nodump, 114 /* psize */ nopsize, | 115 /* open */ dcons_open, 116 /* close */ dcons_close, 117 /* read */ ttyread, 118 /* write */ ttywrite, 119 /* ioctl */ dcons_ioctl, 120 /* poll */ ttypoll, 121 /* mmap */ nommap, 122 /* strategy */ nostrategy, 123 /* name */ "dcons", 124 /* major */ CDEV_MAJOR, 125 /* dump */ nodump, 126 /* psize */ nopsize, |
115 /* flags */ 0, | 127 /* flags */ D_TTY, |
116#endif 117}; 118 119#ifndef KLD_MODULE 120static char bssbuf[DCONS_BUF_SIZE]; /* buf in bss */ 121#endif 122 123/* global data */ --- 4 unchanged lines hidden (view full) --- 128SYSCTL_NODE(_kern, OID_AUTO, dcons, CTLFLAG_RD, 0, "Dumb Console"); 129SYSCTL_INT(_kern_dcons, OID_AUTO, poll_hz, CTLFLAG_RW, &poll_hz, 0, 130 "dcons polling rate"); 131 132static int drv_init = 0; 133static struct callout dcons_callout; 134struct dcons_buf *dcons_buf; /* for local dconschat */ 135 | 128#endif 129}; 130 131#ifndef KLD_MODULE 132static char bssbuf[DCONS_BUF_SIZE]; /* buf in bss */ 133#endif 134 135/* global data */ --- 4 unchanged lines hidden (view full) --- 140SYSCTL_NODE(_kern, OID_AUTO, dcons, CTLFLAG_RD, 0, "Dumb Console"); 141SYSCTL_INT(_kern_dcons, OID_AUTO, poll_hz, CTLFLAG_RW, &poll_hz, 0, 142 "dcons polling rate"); 143 144static int drv_init = 0; 145static struct callout dcons_callout; 146struct dcons_buf *dcons_buf; /* for local dconschat */ 147 |
148#ifdef __DragonFly__ 149#define DEV dev_t 150#define THREAD d_thread_t 151#elif __FreeBSD_version < 500000 152#define DEV dev_t 153#define THREAD struct proc 154#else 155#define DEV struct cdev * 156#define THREAD struct thread 157#endif 158 |
|
136/* per device data */ 137static struct dcons_softc { | 159/* per device data */ 160static struct dcons_softc { |
138 struct cdev *dev; | 161 DEV dev; |
139 struct dcons_ch o, i; 140 int brk_state; 141#define DC_GDB 1 142 int flags; 143} sc[DCONS_NPORT]; 144static void dcons_tty_start(struct tty *); 145static int dcons_tty_param(struct tty *, struct termios *); 146static void dcons_timeout(void *); --- 20 unchanged lines hidden (view full) --- 167static gdb_putc_f dcons_dbg_putc; 168 169GDB_DBGPORT(dcons, dcons_dbg_probe, dcons_dbg_init, dcons_dbg_term, 170 dcons_dbg_checkc, dcons_dbg_getc, dcons_dbg_putc); 171 172extern struct gdb_dbgport *gdb_cur; 173#endif 174 | 162 struct dcons_ch o, i; 163 int brk_state; 164#define DC_GDB 1 165 int flags; 166} sc[DCONS_NPORT]; 167static void dcons_tty_start(struct tty *); 168static int dcons_tty_param(struct tty *, struct termios *); 169static void dcons_timeout(void *); --- 20 unchanged lines hidden (view full) --- 190static gdb_putc_f dcons_dbg_putc; 191 192GDB_DBGPORT(dcons, dcons_dbg_probe, dcons_dbg_init, dcons_dbg_term, 193 dcons_dbg_checkc, dcons_dbg_getc, dcons_dbg_putc); 194 195extern struct gdb_dbgport *gdb_cur; 196#endif 197 |
175#if __FreeBSD_version < 500000 176#define THREAD proc 177#else 178#define THREAD thread 179#endif 180 | |
181static int | 198static int |
182dcons_open(struct cdev *dev, int flag, int mode, struct THREAD *td) | 199dcons_open(DEV dev, int flag, int mode, THREAD *td) |
183{ 184 struct tty *tp; 185 int unit, error, s; 186 187 unit = minor(dev); 188 if (unit != 0) 189 return (ENXIO); 190 --- 16 unchanged lines hidden (view full) --- 207 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 208 ttsetwater(tp); 209 } else if ((tp->t_state & TS_XCLUDE) && suser(td)) { 210 splx(s); 211 return (EBUSY); 212 } 213 splx(s); 214 | 200{ 201 struct tty *tp; 202 int unit, error, s; 203 204 unit = minor(dev); 205 if (unit != 0) 206 return (ENXIO); 207 --- 16 unchanged lines hidden (view full) --- 224 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 225 ttsetwater(tp); 226 } else if ((tp->t_state & TS_XCLUDE) && suser(td)) { 227 splx(s); 228 return (EBUSY); 229 } 230 splx(s); 231 |
232#if __FreeBSD_version < 502113 233 error = (*linesw[tp->t_line].l_open)(dev, tp); 234#else |
|
215 error = ttyld_open(tp, dev); | 235 error = ttyld_open(tp, dev); |
236#endif |
|
216 217 return (error); 218} 219 220static int | 237 238 return (error); 239} 240 241static int |
221dcons_close(struct cdev *dev, int flag, int mode, struct THREAD *td) | 242dcons_close(DEV dev, int flag, int mode, THREAD *td) |
222{ 223 int unit; 224 struct tty *tp; 225 226 unit = minor(dev); 227 if (unit != 0) 228 return (ENXIO); 229 230 tp = dev->si_tty; 231 if (tp->t_state & TS_ISOPEN) { | 243{ 244 int unit; 245 struct tty *tp; 246 247 unit = minor(dev); 248 if (unit != 0) 249 return (ENXIO); 250 251 tp = dev->si_tty; 252 if (tp->t_state & TS_ISOPEN) { |
253#if __FreeBSD_version < 502113 254 (*linesw[tp->t_line].l_close)(tp, flag); 255 ttyclose(tp); 256#else |
|
232 ttyld_close(tp, flag); 233 tty_close(tp); | 257 ttyld_close(tp, flag); 258 tty_close(tp); |
259#endif |
|
234 } 235 236 return (0); 237} 238 | 260 } 261 262 return (0); 263} 264 |
265#if defined(__DragonFly__) || __FreeBSD_version < 500104 |
|
239static int | 266static int |
267dcons_ioctl(DEV dev, u_long cmd, caddr_t data, int flag, THREAD *td) 268{ 269 int unit; 270 struct tty *tp; 271 int error; 272 273 unit = minor(dev); 274 if (unit != 0) 275 return (ENXIO); 276 277 tp = dev->si_tty; 278 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td); 279 if (error != ENOIOCTL) 280 return (error); 281 282 error = ttioctl(tp, cmd, data, flag); 283 if (error != ENOIOCTL) 284 return (error); 285 286 return (ENOTTY); 287} 288#endif 289 290static int |
|
240dcons_tty_param(struct tty *tp, struct termios *t) 241{ 242 tp->t_ispeed = t->c_ispeed; 243 tp->t_ospeed = t->c_ospeed; 244 tp->t_cflag = t->c_cflag; 245 return 0; 246} 247 --- 26 unchanged lines hidden (view full) --- 274 struct dcons_softc *dc; 275 int i, c, polltime; 276 277 for (i = 0; i < DCONS_NPORT; i ++) { 278 dc = &sc[i]; 279 tp = dc->dev->si_tty; 280 while ((c = dcons_checkc(dc)) != -1) 281 if (tp->t_state & TS_ISOPEN) | 291dcons_tty_param(struct tty *tp, struct termios *t) 292{ 293 tp->t_ispeed = t->c_ispeed; 294 tp->t_ospeed = t->c_ospeed; 295 tp->t_cflag = t->c_cflag; 296 return 0; 297} 298 --- 26 unchanged lines hidden (view full) --- 325 struct dcons_softc *dc; 326 int i, c, polltime; 327 328 for (i = 0; i < DCONS_NPORT; i ++) { 329 dc = &sc[i]; 330 tp = dc->dev->si_tty; 331 while ((c = dcons_checkc(dc)) != -1) 332 if (tp->t_state & TS_ISOPEN) |
333#if __FreeBSD_version < 502113 334 (*linesw[tp->t_line].l_rint)(c, tp); 335#else |
|
282 ttyld_rint(tp, c); | 336 ttyld_rint(tp, c); |
337#endif |
|
283 } 284 polltime = hz / poll_hz; 285 if (polltime < 1) 286 polltime = 1; 287 callout_reset(&dcons_callout, polltime, dcons_timeout, tp); 288} 289 290static void 291dcons_cnprobe(struct consdev *cp) 292{ | 338 } 339 polltime = hz / poll_hz; 340 if (polltime < 1) 341 polltime = 1; 342 callout_reset(&dcons_callout, polltime, dcons_timeout, tp); 343} 344 345static void 346dcons_cnprobe(struct consdev *cp) 347{ |
293#if __FreeBSD_version >= 501109 | 348#ifdef __DragonFly__ 349 cp->cn_dev = make_dev(&dcons_cdevsw, DCONS_CON, 350 UID_ROOT, GID_WHEEL, 0600, "dcons"); 351#elif __FreeBSD_version >= 501109 |
294 sprintf(cp->cn_name, "dcons"); 295#else 296 cp->cn_dev = makedev(CDEV_MAJOR, DCONS_CON); 297#endif 298#if DCONS_FORCE_CONSOLE 299 cp->cn_pri = CN_REMOTE; 300#else 301 cp->cn_pri = CN_NORMAL; --- 25 unchanged lines hidden (view full) --- 327} 328static void 329dcons_cnputc(struct consdev *cp, int c) 330{ 331 dcons_putc((struct dcons_softc *)cp->cn_arg, c); 332} 333#else 334static int | 352 sprintf(cp->cn_name, "dcons"); 353#else 354 cp->cn_dev = makedev(CDEV_MAJOR, DCONS_CON); 355#endif 356#if DCONS_FORCE_CONSOLE 357 cp->cn_pri = CN_REMOTE; 358#else 359 cp->cn_pri = CN_NORMAL; --- 25 unchanged lines hidden (view full) --- 385} 386static void 387dcons_cnputc(struct consdev *cp, int c) 388{ 389 dcons_putc((struct dcons_softc *)cp->cn_arg, c); 390} 391#else 392static int |
335dcons_cngetc(struct cdev *dev) | 393dcons_cngetc(DEV dev) |
336{ 337 return(dcons_getc((struct dcons_softc *)dev->si_drv1)); 338} 339static int | 394{ 395 return(dcons_getc((struct dcons_softc *)dev->si_drv1)); 396} 397static int |
340dcons_cncheckc(struct cdev *dev) | 398dcons_cncheckc(DEV dev) |
341{ 342 return(dcons_checkc((struct dcons_softc *)dev->si_drv1)); 343} 344static void | 399{ 400 return(dcons_checkc((struct dcons_softc *)dev->si_drv1)); 401} 402static void |
345dcons_cnputc(struct cdev *dev, int c) | 403dcons_cnputc(DEV dev, int c) |
346{ 347 dcons_putc((struct dcons_softc *)dev->si_drv1, c); 348} 349#endif 350 351static int 352dcons_getc(struct dcons_softc *dc) 353{ --- 170 unchanged lines hidden (view full) --- 524#if __FreeBSD_version < 502122 525#if DDB && DCONS_FORCE_GDB 526#if CONS_NODEV 527 gdbconsdev.cn_arg = (void *)&sc[DCONS_GDB]; 528#if __FreeBSD_version >= 501109 529 sprintf(gdbconsdev.cn_name, "dgdb"); 530#endif 531 gdb_arg = &gdbconsdev; | 404{ 405 dcons_putc((struct dcons_softc *)dev->si_drv1, c); 406} 407#endif 408 409static int 410dcons_getc(struct dcons_softc *dc) 411{ --- 170 unchanged lines hidden (view full) --- 582#if __FreeBSD_version < 502122 583#if DDB && DCONS_FORCE_GDB 584#if CONS_NODEV 585 gdbconsdev.cn_arg = (void *)&sc[DCONS_GDB]; 586#if __FreeBSD_version >= 501109 587 sprintf(gdbconsdev.cn_name, "dgdb"); 588#endif 589 gdb_arg = &gdbconsdev; |
590#elif defined(__DragonFly__) 591 gdbdev = make_dev(&dcons_cdevsw, DCONS_GDB, 592 UID_ROOT, GID_WHEEL, 0600, "dgdb"); |
|
532#else 533 gdbdev = makedev(CDEV_MAJOR, DCONS_GDB); 534#endif 535 gdb_getc = dcons_cngetc; 536 gdb_putc = dcons_cnputc; 537#endif 538#endif 539 drv_init = 1; --- 25 unchanged lines hidden (view full) --- 565 return(0); 566} 567 568static int 569dcons_attach(void) 570{ 571 int polltime; 572 | 593#else 594 gdbdev = makedev(CDEV_MAJOR, DCONS_GDB); 595#endif 596 gdb_getc = dcons_cngetc; 597 gdb_putc = dcons_cnputc; 598#endif 599#endif 600 drv_init = 1; --- 25 unchanged lines hidden (view full) --- 626 return(0); 627} 628 629static int 630dcons_attach(void) 631{ 632 int polltime; 633 |
634#ifdef __DragonFly__ 635 cdevsw_add(&dcons_cdevsw, -1, 0); 636#endif |
|
573 dcons_attach_port(DCONS_CON, "dcons", 0); 574 dcons_attach_port(DCONS_GDB, "dgdb", DC_GDB); 575#if __FreeBSD_version < 500000 576 callout_init(&dcons_callout); 577#else 578 callout_init(&dcons_callout, 0); 579#endif 580 polltime = hz / poll_hz; --- 10 unchanged lines hidden (view full) --- 591 struct dcons_softc *dc; 592 593 dc = &sc[port]; 594 595 tp = dc->dev->si_tty; 596 597 if (tp->t_state & TS_ISOPEN) { 598 printf("dcons: still opened\n"); | 637 dcons_attach_port(DCONS_CON, "dcons", 0); 638 dcons_attach_port(DCONS_GDB, "dgdb", DC_GDB); 639#if __FreeBSD_version < 500000 640 callout_init(&dcons_callout); 641#else 642 callout_init(&dcons_callout, 0); 643#endif 644 polltime = hz / poll_hz; --- 10 unchanged lines hidden (view full) --- 655 struct dcons_softc *dc; 656 657 dc = &sc[port]; 658 659 tp = dc->dev->si_tty; 660 661 if (tp->t_state & TS_ISOPEN) { 662 printf("dcons: still opened\n"); |
663#if __FreeBSD_version < 502113 664 (*linesw[tp->t_line].l_close)(tp, 0); 665 tp->t_gen++; 666 ttyclose(tp); 667 ttwakeup(tp); 668 ttwwakeup(tp); 669#else |
|
599 ttyld_close(tp, 0); 600 tty_close(tp); | 670 ttyld_close(tp, 0); 671 tty_close(tp); |
672#endif |
|
601 } 602 /* XXX 603 * must wait until all device are closed. 604 */ | 673 } 674 /* XXX 675 * must wait until all device are closed. 676 */ |
677#ifdef __DragonFly__ 678 tsleep((void *)dc, 0, "dcodtc", hz/4); 679#else |
|
605 tsleep((void *)dc, PWAIT, "dcodtc", hz/4); | 680 tsleep((void *)dc, PWAIT, "dcodtc", hz/4); |
681#endif |
|
606 destroy_dev(dc->dev); 607 608 return(0); 609} 610 611 612/* cnXXX works only for FreeBSD-5 */ 613static int --- 87 unchanged lines hidden --- | 682 destroy_dev(dc->dev); 683 684 return(0); 685} 686 687 688/* cnXXX works only for FreeBSD-5 */ 689static int --- 87 unchanged lines hidden --- |