Deleted Added
full compact
sio.c (130585) sio.c (130872)
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
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

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

26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
30 * from: i386/isa sio.c,v 1.234
31 */
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
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

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

26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
30 * from: i386/isa sio.c,v 1.234
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/dev/sio/sio.c 130585 2004-06-16 09:47:26Z phk $");
34__FBSDID("$FreeBSD: head/sys/dev/sio/sio.c 130872 2004-06-21 20:09:23Z phk $");
35
36#include "opt_comconsole.h"
37#include "opt_compat.h"
38#include "opt_ddb.h"
39#include "opt_sio.h"
40
41/*
42 * Serial driver, based on 386BSD-0.1 com driver.

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

322 .d_close = sioclose,
323 .d_read = sioread,
324 .d_write = siowrite,
325 .d_ioctl = sioioctl,
326 .d_name = sio_driver_name,
327 .d_flags = D_TTY | D_NEEDGIANT,
328};
329
35
36#include "opt_comconsole.h"
37#include "opt_compat.h"
38#include "opt_ddb.h"
39#include "opt_sio.h"
40
41/*
42 * Serial driver, based on 386BSD-0.1 com driver.

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

322 .d_close = sioclose,
323 .d_read = sioread,
324 .d_write = siowrite,
325 .d_ioctl = sioioctl,
326 .d_name = sio_driver_name,
327 .d_flags = D_TTY | D_NEEDGIANT,
328};
329
330static d_open_t siocopen;
331static d_close_t siocclose;
332static d_read_t siocrdwr;
333static d_ioctl_t siocioctl;
334
335static struct cdevsw sioc_cdevsw = {
336 .d_version = D_VERSION,
337 .d_open = siocopen,
338 .d_close = siocclose,
339 .d_read = siocrdwr,
340 .d_write = siocrdwr,
341 .d_ioctl = siocioctl,
342 .d_name = sio_driver_name,
343 .d_flags = D_TTY | D_NEEDGIANT,
344};
345
330int comconsole = -1;
331static volatile speed_t comdefaultrate = CONSPEED;
332static u_long comdefaultrclk = DEFAULT_RCLK;
333SYSCTL_ULONG(_machdep, OID_AUTO, conrclk, CTLFLAG_RW, &comdefaultrclk, 0, "");
334static speed_t gdbdefaultrate = GDBSPEED;
335SYSCTL_UINT(_machdep, OID_AUTO, gdbspeed, CTLFLAG_RW,
336 &gdbdefaultrate, GDBSPEED, "");
337static u_int com_events; /* input chars + weighted output completions */

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

1120 swi_add(&tty_ithd, "tty:sio", siopoll, NULL, SWI_TTY, 0,
1121 &sio_fast_ih);
1122 swi_add(&clk_ithd, "tty:sio", siopoll, NULL, SWI_TTY, 0,
1123 &sio_slow_ih);
1124 }
1125 minorbase = UNIT_TO_MINOR(unit);
1126 com->devs[0] = make_dev(&sio_cdevsw, minorbase,
1127 UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
346int comconsole = -1;
347static volatile speed_t comdefaultrate = CONSPEED;
348static u_long comdefaultrclk = DEFAULT_RCLK;
349SYSCTL_ULONG(_machdep, OID_AUTO, conrclk, CTLFLAG_RW, &comdefaultrclk, 0, "");
350static speed_t gdbdefaultrate = GDBSPEED;
351SYSCTL_UINT(_machdep, OID_AUTO, gdbspeed, CTLFLAG_RW,
352 &gdbdefaultrate, GDBSPEED, "");
353static u_int com_events; /* input chars + weighted output completions */

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

1136 swi_add(&tty_ithd, "tty:sio", siopoll, NULL, SWI_TTY, 0,
1137 &sio_fast_ih);
1138 swi_add(&clk_ithd, "tty:sio", siopoll, NULL, SWI_TTY, 0,
1139 &sio_slow_ih);
1140 }
1141 minorbase = UNIT_TO_MINOR(unit);
1142 com->devs[0] = make_dev(&sio_cdevsw, minorbase,
1143 UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
1128 com->devs[1] = make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
1144 com->devs[1] = make_dev(&sioc_cdevsw, minorbase | CONTROL_INIT_STATE,
1129 UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
1145 UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
1130 com->devs[2] = make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
1146 com->devs[2] = make_dev(&sioc_cdevsw, minorbase | CONTROL_LOCK_STATE,
1131 UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
1132 com->devs[3] = make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
1133 UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
1147 UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
1148 com->devs[3] = make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
1149 UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
1134 com->devs[4] = make_dev(&sio_cdevsw,
1150 com->devs[4] = make_dev(&sioc_cdevsw,
1135 minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
1136 UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
1151 minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
1152 UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
1137 com->devs[5] = make_dev(&sio_cdevsw,
1153 com->devs[5] = make_dev(&sioc_cdevsw,
1138 minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
1139 UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
1140 for (rid = 0; rid < 6; rid++)
1141 com->devs[rid]->si_drv1 = com;
1142 com->flags = flags;
1143 com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
1144
1145 if (COM_PPSCTS(flags))

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

1174 IER_EMSC);
1175#endif
1176 }
1177
1178 return (0);
1179}
1180
1181static int
1154 minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
1155 UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
1156 for (rid = 0; rid < 6; rid++)
1157 com->devs[rid]->si_drv1 = com;
1158 com->flags = flags;
1159 com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
1160
1161 if (COM_PPSCTS(flags))

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

1190 IER_EMSC);
1191#endif
1192 }
1193
1194 return (0);
1195}
1196
1197static int
1198siocopen(dev, flag, mode, td)
1199 struct cdev *dev;
1200 int flag;
1201 int mode;
1202 struct thread *td;
1203{
1204 struct com_s *com;
1205
1206 com = dev->si_drv1;
1207 if (com == NULL)
1208 return (ENXIO);
1209 if (com->gone)
1210 return (ENXIO);
1211 return (0);
1212}
1213
1214static int
1182sioopen(dev, flag, mode, td)
1183 struct cdev *dev;
1184 int flag;
1185 int mode;
1186 struct thread *td;
1187{
1188 struct com_s *com;
1189 int error;
1190 int mynor;
1191 int s;
1192 struct tty *tp;
1193 int unit;
1194
1195 mynor = minor(dev);
1196 unit = MINOR_TO_UNIT(mynor);
1215sioopen(dev, flag, mode, td)
1216 struct cdev *dev;
1217 int flag;
1218 int mode;
1219 struct thread *td;
1220{
1221 struct com_s *com;
1222 int error;
1223 int mynor;
1224 int s;
1225 struct tty *tp;
1226 int unit;
1227
1228 mynor = minor(dev);
1229 unit = MINOR_TO_UNIT(mynor);
1197 com = com_addr(unit);
1230 com = dev->si_drv1;
1198 if (com == NULL)
1199 return (ENXIO);
1200 if (com->gone)
1201 return (ENXIO);
1231 if (com == NULL)
1232 return (ENXIO);
1233 if (com->gone)
1234 return (ENXIO);
1202 if (mynor & CONTROL_MASK)
1203 return (0);
1204 tp = dev->si_tty = com->tp = ttymalloc(com->tp);
1205 s = spltty();
1206 /*
1207 * We jump to this label after all non-interrupted sleeps to pick
1208 * up any changes of the device state.
1209 */
1210open_top:
1211 while (com->state & CS_DTR_OFF) {

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

1357out:
1358 splx(s);
1359 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
1360 comhardclose(com);
1361 return (error);
1362}
1363
1364static int
1235 tp = dev->si_tty = com->tp = ttymalloc(com->tp);
1236 s = spltty();
1237 /*
1238 * We jump to this label after all non-interrupted sleeps to pick
1239 * up any changes of the device state.
1240 */
1241open_top:
1242 while (com->state & CS_DTR_OFF) {

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

1388out:
1389 splx(s);
1390 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
1391 comhardclose(com);
1392 return (error);
1393}
1394
1395static int
1396siocclose(dev, flag, mode, td)
1397 struct cdev *dev;
1398 int flag;
1399 int mode;
1400 struct thread *td;
1401{
1402
1403 return (0);
1404}
1405
1406static int
1365sioclose(dev, flag, mode, td)
1366 struct cdev *dev;
1367 int flag;
1368 int mode;
1369 struct thread *td;
1370{
1371 struct com_s *com;
1372 int mynor;
1373 int s;
1374 struct tty *tp;
1375
1376 mynor = minor(dev);
1407sioclose(dev, flag, mode, td)
1408 struct cdev *dev;
1409 int flag;
1410 int mode;
1411 struct thread *td;
1412{
1413 struct com_s *com;
1414 int mynor;
1415 int s;
1416 struct tty *tp;
1417
1418 mynor = minor(dev);
1377 if (mynor & CONTROL_MASK)
1378 return (0);
1379 com = com_addr(MINOR_TO_UNIT(mynor));
1419 com = dev->si_drv1;
1380 if (com == NULL)
1381 return (ENODEV);
1382 tp = com->tp;
1383 s = spltty();
1384 ttyld_close(tp, flag);
1385 com->hotchar = ttyldoptim(tp);
1386 comhardclose(com);
1387 ttyclose(tp);

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

1454 }
1455 com->active_out = FALSE;
1456 wakeup(&com->active_out);
1457 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
1458 splx(s);
1459}
1460
1461static int
1420 if (com == NULL)
1421 return (ENODEV);
1422 tp = com->tp;
1423 s = spltty();
1424 ttyld_close(tp, flag);
1425 com->hotchar = ttyldoptim(tp);
1426 comhardclose(com);
1427 ttyclose(tp);

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

1494 }
1495 com->active_out = FALSE;
1496 wakeup(&com->active_out);
1497 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
1498 splx(s);
1499}
1500
1501static int
1502siocrdwr(dev, uio, flag)
1503 struct cdev *dev;
1504 struct uio *uio;
1505 int flag;
1506{
1507
1508 return (ENODEV);
1509}
1510
1511static int
1462sioread(dev, uio, flag)
1463 struct cdev *dev;
1464 struct uio *uio;
1465 int flag;
1466{
1512sioread(dev, uio, flag)
1513 struct cdev *dev;
1514 struct uio *uio;
1515 int flag;
1516{
1467 int mynor;
1468 struct com_s *com;
1469
1517 struct com_s *com;
1518
1470 mynor = minor(dev);
1471 if (mynor & CONTROL_MASK)
1472 return (ENODEV);
1473 com = com_addr(MINOR_TO_UNIT(mynor));
1519 com = dev->si_drv1;
1474 if (com == NULL || com->gone)
1475 return (ENODEV);
1476 return (ttyld_read(com->tp, uio, flag));
1477}
1478
1479static int
1480siowrite(dev, uio, flag)
1481 struct cdev *dev;
1482 struct uio *uio;
1483 int flag;
1484{
1485 int mynor;
1486 struct com_s *com;
1487 int unit;
1488
1489 mynor = minor(dev);
1520 if (com == NULL || com->gone)
1521 return (ENODEV);
1522 return (ttyld_read(com->tp, uio, flag));
1523}
1524
1525static int
1526siowrite(dev, uio, flag)
1527 struct cdev *dev;
1528 struct uio *uio;
1529 int flag;
1530{
1531 int mynor;
1532 struct com_s *com;
1533 int unit;
1534
1535 mynor = minor(dev);
1490 if (mynor & CONTROL_MASK)
1491 return (ENODEV);
1492
1493 unit = MINOR_TO_UNIT(mynor);
1494 com = com_addr(unit);
1495 if (com == NULL || com->gone)
1496 return (ENODEV);
1497 /*
1498 * (XXX) We disallow virtual consoles if the physical console is
1499 * a serial port. This is in case there is a display attached that

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

1955#ifndef COM_MULTIPORT
1956 if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND)
1957#endif /* COM_MULTIPORT */
1958 return;
1959 }
1960}
1961
1962static int
1536
1537 unit = MINOR_TO_UNIT(mynor);
1538 com = com_addr(unit);
1539 if (com == NULL || com->gone)
1540 return (ENODEV);
1541 /*
1542 * (XXX) We disallow virtual consoles if the physical console is
1543 * a serial port. This is in case there is a display attached that

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

1999#ifndef COM_MULTIPORT
2000 if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND)
2001#endif /* COM_MULTIPORT */
2002 return;
2003 }
2004}
2005
2006static int
2007siocioctl(dev, cmd, data, flag, td)
2008 struct cdev *dev;
2009 u_long cmd;
2010 caddr_t data;
2011 int flag;
2012 struct thread *td;
2013{
2014 struct com_s *com;
2015 int error;
2016 int mynor;
2017 struct termios *ct;
2018
2019 mynor = minor(dev);
2020 com = com_addr(MINOR_TO_UNIT(mynor));
2021 if (com == NULL || com->gone)
2022 return (ENODEV);
2023
2024 switch (mynor & CONTROL_MASK) {
2025 case CONTROL_INIT_STATE:
2026 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
2027 break;
2028 case CONTROL_LOCK_STATE:
2029 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
2030 break;
2031 default:
2032 return (ENODEV); /* /dev/nodev */
2033 }
2034 switch (cmd) {
2035 case TIOCSETA:
2036 error = suser(td);
2037 if (error != 0)
2038 return (error);
2039 *ct = *(struct termios *)data;
2040 return (0);
2041 case TIOCGETA:
2042 *(struct termios *)data = *ct;
2043 return (0);
2044 case TIOCGETD:
2045 *(int *)data = TTYDISC;
2046 return (0);
2047 case TIOCGWINSZ:
2048 bzero(data, sizeof(struct winsize));
2049 return (0);
2050 default:
2051 return (ENOTTY);
2052 }
2053}
2054
2055static int
1963sioioctl(dev, cmd, data, flag, td)
1964 struct cdev *dev;
1965 u_long cmd;
1966 caddr_t data;
1967 int flag;
1968 struct thread *td;
1969{
1970 struct com_s *com;
1971 int error;
1972 int mynor;
1973 int s;
1974 struct tty *tp;
1975#if defined(COMPAT_43)
1976 u_long oldcmd;
1977 struct termios term;
1978#endif
1979
1980 mynor = minor(dev);
2056sioioctl(dev, cmd, data, flag, td)
2057 struct cdev *dev;
2058 u_long cmd;
2059 caddr_t data;
2060 int flag;
2061 struct thread *td;
2062{
2063 struct com_s *com;
2064 int error;
2065 int mynor;
2066 int s;
2067 struct tty *tp;
2068#if defined(COMPAT_43)
2069 u_long oldcmd;
2070 struct termios term;
2071#endif
2072
2073 mynor = minor(dev);
1981 com = com_addr(MINOR_TO_UNIT(mynor));
2074 com = dev->si_drv1;
1982 if (com == NULL || com->gone)
1983 return (ENODEV);
2075 if (com == NULL || com->gone)
2076 return (ENODEV);
1984 if (mynor & CONTROL_MASK) {
1985 struct termios *ct;
1986
1987 switch (mynor & CONTROL_MASK) {
1988 case CONTROL_INIT_STATE:
1989 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
1990 break;
1991 case CONTROL_LOCK_STATE:
1992 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
1993 break;
1994 default:
1995 return (ENODEV); /* /dev/nodev */
1996 }
1997 switch (cmd) {
1998 case TIOCSETA:
1999 error = suser(td);
2000 if (error != 0)
2001 return (error);
2002 *ct = *(struct termios *)data;
2003 return (0);
2004 case TIOCGETA:
2005 *(struct termios *)data = *ct;
2006 return (0);
2007 case TIOCGETD:
2008 *(int *)data = TTYDISC;
2009 return (0);
2010 case TIOCGWINSZ:
2011 bzero(data, sizeof(struct winsize));
2012 return (0);
2013 default:
2014 return (ENOTTY);
2015 }
2016 }
2017 tp = com->tp;
2018#if defined(COMPAT_43)
2019 term = tp->t_termios;
2020 oldcmd = cmd;
2021 error = ttsetcompat(tp, &cmd, data, &term);
2022 if (error != 0)
2023 return (error);
2024 if (cmd != oldcmd)

--- 1208 unchanged lines hidden ---
2077 tp = com->tp;
2078#if defined(COMPAT_43)
2079 term = tp->t_termios;
2080 oldcmd = cmd;
2081 error = ttsetcompat(tp, &cmd, data, &term);
2082 if (error != 0)
2083 return (error);
2084 if (cmd != oldcmd)

--- 1208 unchanged lines hidden ---