sio.c (46792) | sio.c (46871) |
---|---|
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 --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * | 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 --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * |
33 * $Id: sio.c,v 1.92 1999/05/09 05:00:54 kato Exp $ | 33 * $Id: sio.c,v 1.93 1999/05/09 13:00:48 phk Exp $ |
34 * from: @(#)com.c 7.5 (Berkeley) 5/16/91 35 * from: i386/isa sio.c,v 1.234 36 */ 37 38#include "opt_comconsole.h" 39#include "opt_compat.h" 40#include "opt_ddb.h" 41#include "opt_devfs.h" | 34 * from: @(#)com.c 7.5 (Berkeley) 5/16/91 35 * from: i386/isa sio.c,v 1.234 36 */ 37 38#include "opt_comconsole.h" 39#include "opt_compat.h" 40#include "opt_ddb.h" 41#include "opt_devfs.h" |
42/* #include "opt_sio.h" */ | 42#include "opt_sio.h" |
43#include "sio.h" 44/* #include "pnp.h" */ 45#define NPNP 0 46 47/* 48 * Serial driver, based on 386BSD-0.1 com driver. 49 * Mostly rewritten to use pseudo-DMA. 50 * Works for National Semiconductor NS8250-NS16550AF UARTs. --- 373 unchanged lines hidden (view full) --- 424 void *devfs_token_ttyi; 425 void *devfs_token_cuaa; 426 void *devfs_token_cual; 427 void *devfs_token_cuai; 428#endif 429}; 430 431#ifdef COM_ESP | 43#include "sio.h" 44/* #include "pnp.h" */ 45#define NPNP 0 46 47/* 48 * Serial driver, based on 386BSD-0.1 com driver. 49 * Mostly rewritten to use pseudo-DMA. 50 * Works for National Semiconductor NS8250-NS16550AF UARTs. --- 373 unchanged lines hidden (view full) --- 424 void *devfs_token_ttyi; 425 void *devfs_token_cuaa; 426 void *devfs_token_cual; 427 void *devfs_token_cuai; 428#endif 429}; 430 431#ifdef COM_ESP |
432static int espattach __P((struct isa_device *isdp, struct com_s *com, 433 Port_t esp_port)); | 432static int espattach __P((struct com_s *com, Port_t esp_port)); |
434#endif 435static int sioattach __P((device_t dev)); 436 437static timeout_t siobusycheck; 438static timeout_t siodtrwakeup; 439static void comhardclose __P((struct com_s *com)); 440static void sioinput __P((struct com_s *com)); 441static void siointr1 __P((struct com_s *com)); --- 498 unchanged lines hidden (view full) --- 940 if (com->tp && (com->tp->t_state & TS_ISOPEN)) { 941 com->gone = 1; 942 printf("sio%d: unload\n", devi->isahd.id_unit); 943 com->tp->t_gen++; 944 ttyclose(com->tp); 945 ttwakeup(com->tp); 946 ttwwakeup(com->tp); 947 } else { | 433#endif 434static int sioattach __P((device_t dev)); 435 436static timeout_t siobusycheck; 437static timeout_t siodtrwakeup; 438static void comhardclose __P((struct com_s *com)); 439static void sioinput __P((struct com_s *com)); 440static void siointr1 __P((struct com_s *com)); --- 498 unchanged lines hidden (view full) --- 939 if (com->tp && (com->tp->t_state & TS_ISOPEN)) { 940 com->gone = 1; 941 printf("sio%d: unload\n", devi->isahd.id_unit); 942 com->tp->t_gen++; 943 ttyclose(com->tp); 944 ttwakeup(com->tp); 945 ttwwakeup(com->tp); 946 } else { |
948 com_addr(com->unit) = NULL; | |
949 if (com->ibuf != NULL) 950 free(com->ibuf, M_DEVBUF); 951 free(com, M_DEVBUF); 952 printf("sio%d: unload,gone\n", devi->isahd.id_unit); 953 } 954} 955 956/* --- 467 unchanged lines hidden (view full) --- 1424 } 1425 break; 1426 } 1427 return (iobase == siocniobase ? 0 : result); 1428} 1429 1430#ifdef COM_ESP 1431static int | 947 if (com->ibuf != NULL) 948 free(com->ibuf, M_DEVBUF); 949 free(com, M_DEVBUF); 950 printf("sio%d: unload,gone\n", devi->isahd.id_unit); 951 } 952} 953 954/* --- 467 unchanged lines hidden (view full) --- 1422 } 1423 break; 1424 } 1425 return (iobase == siocniobase ? 0 : result); 1426} 1427 1428#ifdef COM_ESP 1429static int |
1432espattach(isdp, com, esp_port) 1433 struct isa_device *isdp; | 1430espattach(com, esp_port) |
1434 struct com_s *com; 1435 Port_t esp_port; 1436{ 1437 u_char dips; 1438 u_char val; 1439 1440 /* 1441 * Check the ESP-specific I/O port to see if we're an ESP --- 70 unchanged lines hidden (view full) --- 1512sioattach(dev) 1513 device_t dev; 1514{ 1515 struct com_s *com; 1516#ifdef COM_ESP 1517 Port_t *espp; 1518#endif 1519 Port_t iobase; | 1431 struct com_s *com; 1432 Port_t esp_port; 1433{ 1434 u_char dips; 1435 u_char val; 1436 1437 /* 1438 * Check the ESP-specific I/O port to see if we're an ESP --- 70 unchanged lines hidden (view full) --- 1509sioattach(dev) 1510 device_t dev; 1511{ 1512 struct com_s *com; 1513#ifdef COM_ESP 1514 Port_t *espp; 1515#endif 1516 Port_t iobase; |
1520#if 0 1521 int s; 1522#endif | |
1523 int unit; 1524 void *ih; 1525 struct resource *res; 1526 int zero = 0; 1527 u_int flags = isa_get_flags(dev); 1528#ifdef PC98 1529 int port_shift = 0; 1530 u_char *obuf; 1531 u_long obufsize; 1532#endif 1533 | 1517 int unit; 1518 void *ih; 1519 struct resource *res; 1520 int zero = 0; 1521 u_int flags = isa_get_flags(dev); 1522#ifdef PC98 1523 int port_shift = 0; 1524 u_char *obuf; 1525 u_long obufsize; 1526#endif 1527 |
1534#if 0 1535 isdp->id_ri_flags |= RI_FAST; 1536#endif | |
1537 iobase = isa_get_port(dev); 1538#ifdef PC98 1539 if (((flags >> 24) & 0xff) == COM_IF_RSA98III) 1540 iobase += 8; 1541#endif 1542 unit = device_get_unit(dev); 1543 com = device_get_softc(dev); 1544#ifdef PC98 --- 168 unchanged lines hidden (view full) --- 1713 } 1714#endif 1715 1716#ifdef COM_ESP 1717#ifdef PC98 1718 if (com->pc98_if_type == COM_IF_ESP98) 1719#endif 1720 for (espp = likely_esp_ports; *espp != 0; espp++) | 1528 iobase = isa_get_port(dev); 1529#ifdef PC98 1530 if (((flags >> 24) & 0xff) == COM_IF_RSA98III) 1531 iobase += 8; 1532#endif 1533 unit = device_get_unit(dev); 1534 com = device_get_softc(dev); 1535#ifdef PC98 --- 168 unchanged lines hidden (view full) --- 1704 } 1705#endif 1706 1707#ifdef COM_ESP 1708#ifdef PC98 1709 if (com->pc98_if_type == COM_IF_ESP98) 1710#endif 1711 for (espp = likely_esp_ports; *espp != 0; espp++) |
1721 if (espattach(dev, com, *espp)) { | 1712 if (espattach(com, *espp)) { |
1722 com->tx_fifo_size = 1024; 1723 break; 1724 } 1725#endif 1726 if (!com->st16650a) { 1727 if (!com->tx_fifo_size) 1728 com->tx_fifo_size = 16; 1729 else --- 89 unchanged lines hidden (view full) --- 1819 } 1820#endif 1821 if (unit == comconsole) 1822 printf(", console"); 1823 if ( COM_IIR_TXRDYBUG(flags) ) 1824 printf(" with a bogus IIR_TXRDY register"); 1825 printf("\n"); 1826 | 1713 com->tx_fifo_size = 1024; 1714 break; 1715 } 1716#endif 1717 if (!com->st16650a) { 1718 if (!com->tx_fifo_size) 1719 com->tx_fifo_size = 16; 1720 else --- 89 unchanged lines hidden (view full) --- 1810 } 1811#endif 1812 if (unit == comconsole) 1813 printf(", console"); 1814 if ( COM_IIR_TXRDYBUG(flags) ) 1815 printf(" with a bogus IIR_TXRDY register"); 1816 printf("\n"); 1817 |
1827#if 0 1828 s = spltty(); 1829 com_addr(unit) = com; 1830 splx(s); 1831#endif 1832 | |
1833 if (!sio_registered) { 1834 register_swi(SWI_TTY, siopoll); 1835 sio_registered = TRUE; 1836 } 1837#ifdef DEVFS 1838 com->devfs_token_ttyd = devfs_add_devswf(&sio_cdevsw, 1839 unit, DV_CHR, 1840 UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit); --- 297 unchanged lines hidden (view full) --- 2138 siostop(tp, FREAD | FWRITE); 2139 comhardclose(com); 2140 ttyclose(tp); 2141 siosettimeout(); 2142 splx(s); 2143 if (com->gone) { 2144 printf("sio%d: gone\n", com->unit); 2145 s = spltty(); | 1818 if (!sio_registered) { 1819 register_swi(SWI_TTY, siopoll); 1820 sio_registered = TRUE; 1821 } 1822#ifdef DEVFS 1823 com->devfs_token_ttyd = devfs_add_devswf(&sio_cdevsw, 1824 unit, DV_CHR, 1825 UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit); --- 297 unchanged lines hidden (view full) --- 2123 siostop(tp, FREAD | FWRITE); 2124 comhardclose(com); 2125 ttyclose(tp); 2126 siosettimeout(); 2127 splx(s); 2128 if (com->gone) { 2129 printf("sio%d: gone\n", com->unit); 2130 s = spltty(); |
2146#if 0 2147 com_addr(com->unit) = NULL; 2148#endif | |
2149 if (com->ibuf != NULL) 2150 free(com->ibuf, M_DEVBUF); 2151 bzero(tp, sizeof *tp); 2152 free(com, M_DEVBUF); 2153 splx(s); 2154 } 2155 return (0); 2156} --- 103 unchanged lines hidden (view full) --- 2260 2261static int 2262sioread(dev, uio, flag) 2263 dev_t dev; 2264 struct uio *uio; 2265 int flag; 2266{ 2267 int mynor; | 2131 if (com->ibuf != NULL) 2132 free(com->ibuf, M_DEVBUF); 2133 bzero(tp, sizeof *tp); 2134 free(com, M_DEVBUF); 2135 splx(s); 2136 } 2137 return (0); 2138} --- 103 unchanged lines hidden (view full) --- 2242 2243static int 2244sioread(dev, uio, flag) 2245 dev_t dev; 2246 struct uio *uio; 2247 int flag; 2248{ 2249 int mynor; |
2268 int unit; 2269 struct tty *tp; | 2250 struct com_s *com; |
2270 2271 mynor = minor(dev); 2272 if (mynor & CONTROL_MASK) 2273 return (ENODEV); | 2251 2252 mynor = minor(dev); 2253 if (mynor & CONTROL_MASK) 2254 return (ENODEV); |
2274 unit = MINOR_TO_UNIT(mynor); 2275 if (com_addr(unit)->gone) | 2255 com = com_addr(MINOR_TO_UNIT(mynor)); 2256 if (com->gone) |
2276 return (ENODEV); | 2257 return (ENODEV); |
2277 tp = com_addr(unit)->tp; 2278 return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); | 2258 return ((*linesw[com->tp->t_line].l_read)(com->tp, uio, flag)); |
2279} 2280 2281static int 2282siowrite(dev, uio, flag) 2283 dev_t dev; 2284 struct uio *uio; 2285 int flag; 2286{ 2287 int mynor; | 2259} 2260 2261static int 2262siowrite(dev, uio, flag) 2263 dev_t dev; 2264 struct uio *uio; 2265 int flag; 2266{ 2267 int mynor; |
2288 struct tty *tp; | 2268 struct com_s *com; |
2289 int unit; 2290 2291 mynor = minor(dev); 2292 if (mynor & CONTROL_MASK) 2293 return (ENODEV); 2294 2295 unit = MINOR_TO_UNIT(mynor); | 2269 int unit; 2270 2271 mynor = minor(dev); 2272 if (mynor & CONTROL_MASK) 2273 return (ENODEV); 2274 2275 unit = MINOR_TO_UNIT(mynor); |
2296 if (com_addr(unit)->gone) | 2276 com = com_addr(unit); 2277 if (com->gone) |
2297 return (ENODEV); | 2278 return (ENODEV); |
2298 tp = com_addr(unit)->tp; | |
2299 /* 2300 * (XXX) We disallow virtual consoles if the physical console is 2301 * a serial port. This is in case there is a display attached that 2302 * is not the console. In that situation we don't need/want the X 2303 * server taking over the console. 2304 */ 2305 if (constty != NULL && unit == comconsole) 2306 constty = NULL; | 2279 /* 2280 * (XXX) We disallow virtual consoles if the physical console is 2281 * a serial port. This is in case there is a display attached that 2282 * is not the console. In that situation we don't need/want the X 2283 * server taking over the console. 2284 */ 2285 if (constty != NULL && unit == comconsole) 2286 constty = NULL; |
2307 return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); | 2287 return ((*linesw[com->tp->t_line].l_write)(com->tp, uio, flag)); |
2308} 2309 2310static void 2311siobusycheck(chan) 2312 void *chan; 2313{ 2314 struct com_s *com; 2315 int s; --- 143 unchanged lines hidden (view full) --- 2459 void *arg; 2460{ 2461#ifndef COM_MULTIPORT 2462 COM_LOCK(); 2463 siointr1((struct com_s *) arg); 2464 COM_UNLOCK(); 2465#else /* COM_MULTIPORT */ 2466 bool_t possibly_more_intrs; | 2288} 2289 2290static void 2291siobusycheck(chan) 2292 void *chan; 2293{ 2294 struct com_s *com; 2295 int s; --- 143 unchanged lines hidden (view full) --- 2439 void *arg; 2440{ 2441#ifndef COM_MULTIPORT 2442 COM_LOCK(); 2443 siointr1((struct com_s *) arg); 2444 COM_UNLOCK(); 2445#else /* COM_MULTIPORT */ 2446 bool_t possibly_more_intrs; |
2447 int unit; 2448 struct com_s *com; |
|
2467#ifdef PC98 2468 u_char rsa_buf_status; 2469#endif 2470 2471 /* 2472 * Loop until there is no activity on any port. This is necessary 2473 * to get an interrupt edge more than to avoid another interrupt. 2474 * If the IRQ signal is just an OR of the IRQ signals from several --- 1449 unchanged lines hidden (view full) --- 3924}; 3925 3926static speed_t siocngetspeed __P((Port_t, struct speedtab *)); 3927static void siocnclose __P((struct siocnstate *sp, Port_t iobase)); 3928static void siocnopen __P((struct siocnstate *sp, Port_t iobase, int speed)); 3929static void siocntxwait __P((Port_t iobase)); 3930 3931#ifdef __i386__ | 2449#ifdef PC98 2450 u_char rsa_buf_status; 2451#endif 2452 2453 /* 2454 * Loop until there is no activity on any port. This is necessary 2455 * to get an interrupt edge more than to avoid another interrupt. 2456 * If the IRQ signal is just an OR of the IRQ signals from several --- 1449 unchanged lines hidden (view full) --- 3906}; 3907 3908static speed_t siocngetspeed __P((Port_t, struct speedtab *)); 3909static void siocnclose __P((struct siocnstate *sp, Port_t iobase)); 3910static void siocnopen __P((struct siocnstate *sp, Port_t iobase, int speed)); 3911static void siocntxwait __P((Port_t iobase)); 3912 3913#ifdef __i386__ |
3932/* 3933 * XXX: sciocnget() and sciocnputc() are not declared static, as they are 3934 * referred to from i386/i386/i386-gdbstub.c. 3935 */ | |
3936static cn_probe_t siocnprobe; 3937static cn_init_t siocninit; 3938static cn_checkc_t siocncheckc; | 3914static cn_probe_t siocnprobe; 3915static cn_init_t siocninit; 3916static cn_checkc_t siocncheckc; |
3939 cn_getc_t siocngetc; 3940 cn_putc_t siocnputc; | 3917static cn_getc_t siocngetc; 3918static cn_putc_t siocnputc; |
3941 3942CONS_DRIVER(sio, siocnprobe, siocninit, siocngetc, siocncheckc, siocnputc); 3943 | 3919 3920CONS_DRIVER(sio, siocnprobe, siocninit, siocngetc, siocncheckc, siocnputc); 3921 |
3944/* 3945 * Routines to support GDB on an sio port. 3946 */ 3947dev_t gdbdev; 3948cn_getc_t *gdb_getc; 3949cn_putc_t *gdb_putc; 3950 | 3922/* To get the GDB related variables */ 3923#if DDB > 0 3924#include <ddb/ddb.h> |
3951#endif | 3925#endif |
3926#endif |
|
3952 3953static void 3954siocntxwait(iobase) 3955 Port_t iobase; 3956{ 3957 int timo; 3958 3959 /* --- 185 unchanged lines hidden (view full) --- 4145 siocniobase = iobase; 4146 siocnunit = unit; 4147 } 4148 if (COM_DEBUGGER(flags) && !COM_LLCONSOLE(flags)) { 4149 printf("sio%d: gdb debugging port\n", unit); 4150 siogdbiobase = iobase; 4151 siogdbunit = unit; 4152#ifdef __i386__ | 3927 3928static void 3929siocntxwait(iobase) 3930 Port_t iobase; 3931{ 3932 int timo; 3933 3934 /* --- 185 unchanged lines hidden (view full) --- 4120 siocniobase = iobase; 4121 siocnunit = unit; 4122 } 4123 if (COM_DEBUGGER(flags) && !COM_LLCONSOLE(flags)) { 4124 printf("sio%d: gdb debugging port\n", unit); 4125 siogdbiobase = iobase; 4126 siogdbunit = unit; 4127#ifdef __i386__ |
4128#if DDB > 0 |
|
4153 gdbdev = makedev(CDEV_MAJOR, unit); 4154 gdb_getc = siocngetc; 4155 gdb_putc = siocnputc; 4156#endif | 4129 gdbdev = makedev(CDEV_MAJOR, unit); 4130 gdb_getc = siocngetc; 4131 gdb_putc = siocnputc; 4132#endif |
4133#endif |
|
4157 } 4158 } 4159 } 4160#ifdef __i386__ | 4134 } 4135 } 4136 } 4137#ifdef __i386__ |
4138#if DDB > 0 |
|
4161 /* 4162 * XXX Ugly Compatability. 4163 * If no gdb port has been specified, set it to be the console 4164 * as some configuration files don't specify the gdb port. 4165 */ | 4139 /* 4140 * XXX Ugly Compatability. 4141 * If no gdb port has been specified, set it to be the console 4142 * as some configuration files don't specify the gdb port. 4143 */ |
4166 if (gdbdev == -1 && (boothowto & RB_GDB)) { | 4144 if (gdbdev == NODEV && (boothowto & RB_GDB)) { |
4167 printf("Warning: no GDB port specified. Defaulting to sio%d.\n", 4168 siocnunit); 4169 printf("Set flag 0x80 on desired GDB port in your\n"); 4170 printf("configuration file (currently sio only).\n"); 4171 siogdbiobase = siocniobase; 4172 siogdbunit = siocnunit; 4173 gdbdev = makedev(CDEV_MAJOR, siocnunit); 4174 gdb_getc = siocngetc; 4175 gdb_putc = siocnputc; 4176 } 4177#endif | 4145 printf("Warning: no GDB port specified. Defaulting to sio%d.\n", 4146 siocnunit); 4147 printf("Set flag 0x80 on desired GDB port in your\n"); 4148 printf("configuration file (currently sio only).\n"); 4149 siogdbiobase = siocniobase; 4150 siogdbunit = siocnunit; 4151 gdbdev = makedev(CDEV_MAJOR, siocnunit); 4152 gdb_getc = siocngetc; 4153 gdb_putc = siocnputc; 4154 } 4155#endif |
4156#endif |
|
4178} 4179 4180#ifdef __alpha__ 4181 4182struct consdev siocons = { 4183 NULL, NULL, siocngetc, siocncheckc, siocnputc, 4184 NULL, makedev(CDEV_MAJOR, 0), CN_NORMAL, 4185}; --- 846 unchanged lines hidden --- | 4157} 4158 4159#ifdef __alpha__ 4160 4161struct consdev siocons = { 4162 NULL, NULL, siocngetc, siocncheckc, siocnputc, 4163 NULL, makedev(CDEV_MAJOR, 0), CN_NORMAL, 4164}; --- 846 unchanged lines hidden --- |