Deleted Added
full compact
sio.c (131403) sio.c (131939)
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

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

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
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

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

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/sys/pc98/cbus/sio.c 131403 2004-07-01 09:32:32Z nyan $
29 * $FreeBSD: head/sys/pc98/cbus/sio.c 131939 2004-07-10 22:29:41Z marcel $
30 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
31 * from: i386/isa sio.c,v 1.234
32 */
33
34#include "opt_comconsole.h"
35#include "opt_compat.h"
30 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
31 * from: i386/isa sio.c,v 1.234
32 */
33
34#include "opt_comconsole.h"
35#include "opt_compat.h"
36#include "opt_ddb.h"
36#include "opt_gdb.h"
37#include "opt_kdb.h"
37#include "opt_sio.h"
38
39/*
40 * Serial driver, based on 386BSD-0.1 com driver.
41 * Mostly rewritten to use pseudo-DMA.
42 * Works for National Semiconductor NS8250-NS16550AF UARTs.
43 * COM driver, based on HP dca driver.
44 *

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

78 */
79
80#include <sys/param.h>
81#include <sys/systm.h>
82#include <sys/bus.h>
83#include <sys/conf.h>
84#include <sys/fcntl.h>
85#include <sys/interrupt.h>
38#include "opt_sio.h"
39
40/*
41 * Serial driver, based on 386BSD-0.1 com driver.
42 * Mostly rewritten to use pseudo-DMA.
43 * Works for National Semiconductor NS8250-NS16550AF UARTs.
44 * COM driver, based on HP dca driver.
45 *

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

79 */
80
81#include <sys/param.h>
82#include <sys/systm.h>
83#include <sys/bus.h>
84#include <sys/conf.h>
85#include <sys/fcntl.h>
86#include <sys/interrupt.h>
87#include <sys/kdb.h>
86#include <sys/kernel.h>
87#include <sys/limits.h>
88#include <sys/lock.h>
89#include <sys/malloc.h>
90#include <sys/module.h>
91#include <sys/mutex.h>
92#include <sys/proc.h>
93#include <sys/reboot.h>
94#include <sys/serial.h>
95#include <sys/sysctl.h>
96#include <sys/syslog.h>
97#include <sys/tty.h>
98#include <machine/bus.h>
99#include <sys/rman.h>
100#include <sys/timepps.h>
101#include <sys/uio.h>
102#include <sys/cons.h>
88#include <sys/kernel.h>
89#include <sys/limits.h>
90#include <sys/lock.h>
91#include <sys/malloc.h>
92#include <sys/module.h>
93#include <sys/mutex.h>
94#include <sys/proc.h>
95#include <sys/reboot.h>
96#include <sys/serial.h>
97#include <sys/sysctl.h>
98#include <sys/syslog.h>
99#include <sys/tty.h>
100#include <machine/bus.h>
101#include <sys/rman.h>
102#include <sys/timepps.h>
103#include <sys/uio.h>
104#include <sys/cons.h>
103#if DDB > 0
104#include <ddb/ddb.h>
105#endif
106
107#include <isa/isavar.h>
108
109#include <machine/resource.h>
110
111#include <dev/sio/sioreg.h>
112#include <dev/sio/siovar.h>
113

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

433static u_long comdefaultrclk = DEFAULT_RCLK;
434SYSCTL_ULONG(_machdep, OID_AUTO, conrclk, CTLFLAG_RW, &comdefaultrclk, 0, "");
435static speed_t gdbdefaultrate = GDBSPEED;
436SYSCTL_UINT(_machdep, OID_AUTO, gdbspeed, CTLFLAG_RW,
437 &gdbdefaultrate, GDBSPEED, "");
438static u_int com_events; /* input chars + weighted output completions */
439static Port_t siocniobase;
440static int siocnunit = -1;
105
106#include <isa/isavar.h>
107
108#include <machine/resource.h>
109
110#include <dev/sio/sioreg.h>
111#include <dev/sio/siovar.h>
112

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

432static u_long comdefaultrclk = DEFAULT_RCLK;
433SYSCTL_ULONG(_machdep, OID_AUTO, conrclk, CTLFLAG_RW, &comdefaultrclk, 0, "");
434static speed_t gdbdefaultrate = GDBSPEED;
435SYSCTL_UINT(_machdep, OID_AUTO, gdbspeed, CTLFLAG_RW,
436 &gdbdefaultrate, GDBSPEED, "");
437static u_int com_events; /* input chars + weighted output completions */
438static Port_t siocniobase;
439static int siocnunit = -1;
441static Port_t siogdbiobase;
442static int siogdbunit = -1;
443static void *sio_slow_ih;
444static void *sio_fast_ih;
445static int sio_timeout;
446static int sio_timeouts_until_log;
447static struct callout_handle sio_timeout_handle
448 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
449static int sio_numunits;
450

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

677 {"", -1, -1, port_table_0, IO_COMSIZE, DEFAULT_RCLK},
678 /* COM_IF_RSA98III */
679 {" (RSA-98III)", -1, -1, port_table_rsa, 16, DEFAULT_RCLK * 8},
680 /* COM_IF_ESP98 */
681 {" (ESP98)", -1, -1, port_table_1, IO_COMSIZE, DEFAULT_RCLK * 4},
682};
683#endif /* PC98 */
684
440static void *sio_slow_ih;
441static void *sio_fast_ih;
442static int sio_timeout;
443static int sio_timeouts_until_log;
444static struct callout_handle sio_timeout_handle
445 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
446static int sio_numunits;
447

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

674 {"", -1, -1, port_table_0, IO_COMSIZE, DEFAULT_RCLK},
675 /* COM_IF_RSA98III */
676 {" (RSA-98III)", -1, -1, port_table_rsa, 16, DEFAULT_RCLK * 8},
677 /* COM_IF_ESP98 */
678 {" (ESP98)", -1, -1, port_table_1, IO_COMSIZE, DEFAULT_RCLK * 4},
679};
680#endif /* PC98 */
681
682#ifdef GDB
683static Port_t siogdbiobase = 0;
684#endif
685
685#ifdef COM_ESP
686#ifdef PC98
687
688/* XXX configure this properly. */
689/* XXX quite broken for new-bus. */
690static Port_t likely_com_ports[] = { 0, 0xb0, 0xb1, 0 };
691static Port_t likely_esp_ports[] = { 0xc0d0, 0 };
692

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

1843 ret = BUS_SETUP_INTR(device_get_parent(dev), dev,
1844 com->irqres, INTR_TYPE_TTY,
1845 siointr, com, &com->cookie);
1846 if (ret == 0)
1847 device_printf(dev, "unable to activate interrupt in fast mode - using normal mode\n");
1848 }
1849 if (ret)
1850 device_printf(dev, "could not activate interrupt\n");
686#ifdef COM_ESP
687#ifdef PC98
688
689/* XXX configure this properly. */
690/* XXX quite broken for new-bus. */
691static Port_t likely_com_ports[] = { 0, 0xb0, 0xb1, 0 };
692static Port_t likely_esp_ports[] = { 0xc0d0, 0 };
693

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

1844 ret = BUS_SETUP_INTR(device_get_parent(dev), dev,
1845 com->irqres, INTR_TYPE_TTY,
1846 siointr, com, &com->cookie);
1847 if (ret == 0)
1848 device_printf(dev, "unable to activate interrupt in fast mode - using normal mode\n");
1849 }
1850 if (ret)
1851 device_printf(dev, "could not activate interrupt\n");
1851#if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
1852#if defined(KDB) && (defined(BREAK_TO_DEBUGGER) || \
1852 defined(ALT_BREAK_TO_DEBUGGER))
1853 /*
1854 * Enable interrupts for early break-to-debugger support
1855 * on the console.
1856 */
1857 if (ret == 0 && unit == comconsole)
1858 outb(siocniobase + com_ier, IER_ERXRDY | IER_ERLS |
1859 IER_EMSC);

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

2176 com->pps.ppsparam.mode = 0;
2177#ifdef PC98
2178 com_send_break_off(com);
2179#else
2180 sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
2181#endif
2182 tp = com->tp;
2183
1853 defined(ALT_BREAK_TO_DEBUGGER))
1854 /*
1855 * Enable interrupts for early break-to-debugger support
1856 * on the console.
1857 */
1858 if (ret == 0 && unit == comconsole)
1859 outb(siocniobase + com_ier, IER_ERXRDY | IER_ERLS |
1860 IER_EMSC);

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

2177 com->pps.ppsparam.mode = 0;
2178#ifdef PC98
2179 com_send_break_off(com);
2180#else
2181 sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
2182#endif
2183 tp = com->tp;
2184
2184#if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
2185#if defined(KDB) && (defined(BREAK_TO_DEBUGGER) || \
2185 defined(ALT_BREAK_TO_DEBUGGER))
2186 /*
2187 * Leave interrupts enabled and don't clear DTR if this is the
2188 * console. This allows us to detect break-to-debugger events
2189 * while the console device is closed.
2190 */
2191 if (com->unit != comconsole)
2192#endif

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

2708 else
2709 recv_data = inb(com->data_port);
2710 } else
2711#endif
2712 if (!(line_status & LSR_RXRDY))
2713 recv_data = 0;
2714 else
2715 recv_data = inb(com->data_port);
2186 defined(ALT_BREAK_TO_DEBUGGER))
2187 /*
2188 * Leave interrupts enabled and don't clear DTR if this is the
2189 * console. This allows us to detect break-to-debugger events
2190 * while the console device is closed.
2191 */
2192 if (com->unit != comconsole)
2193#endif

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

2709 else
2710 recv_data = inb(com->data_port);
2711 } else
2712#endif
2713 if (!(line_status & LSR_RXRDY))
2714 recv_data = 0;
2715 else
2716 recv_data = inb(com->data_port);
2716#ifdef DDB
2717#ifdef KDB
2717#ifdef ALT_BREAK_TO_DEBUGGER
2718 if (com->unit == comconsole &&
2718#ifdef ALT_BREAK_TO_DEBUGGER
2719 if (com->unit == comconsole &&
2719 db_alt_break(recv_data, &com->alt_brk_state) != 0)
2720 breakpoint();
2720 kdb_alt_break(recv_data, &com->alt_brk_state) != 0)
2721 kdb_enter("Break sequence on console");
2721#endif /* ALT_BREAK_TO_DEBUGGER */
2722#endif /* ALT_BREAK_TO_DEBUGGER */
2722#endif /* DDB */
2723#endif /* KDB */
2723 if (line_status & (LSR_BI | LSR_FE | LSR_PE)) {
2724 /*
2725 * Don't store BI if IGNBRK or FE/PE if IGNPAR.
2726 * Otherwise, push the work to a higher level
2727 * (to handle PARMRK) if we're bypassing.
2728 * Otherwise, convert BI/FE and PE+INPCK to 0.
2729 *
2730 * This makes bypassing work right in the
2731 * usual "raw" case (IGNBRK set, and IGNPAR
2732 * and INPCK clear).
2733 *
2734 * Note: BI together with FE/PE means just BI.
2735 */
2736 if (line_status & LSR_BI) {
2724 if (line_status & (LSR_BI | LSR_FE | LSR_PE)) {
2725 /*
2726 * Don't store BI if IGNBRK or FE/PE if IGNPAR.
2727 * Otherwise, push the work to a higher level
2728 * (to handle PARMRK) if we're bypassing.
2729 * Otherwise, convert BI/FE and PE+INPCK to 0.
2730 *
2731 * This makes bypassing work right in the
2732 * usual "raw" case (IGNBRK set, and IGNPAR
2733 * and INPCK clear).
2734 *
2735 * Note: BI together with FE/PE means just BI.
2736 */
2737 if (line_status & LSR_BI) {
2737#if defined(DDB) && defined(BREAK_TO_DEBUGGER)
2738#if defined(KDB) && defined(BREAK_TO_DEBUGGER)
2738 if (com->unit == comconsole) {
2739 if (com->unit == comconsole) {
2739 breakpoint();
2740 kdb_enter("Line break on console");
2740 goto cont;
2741 }
2742#endif
2743 if (com->tp == NULL
2744 || com->tp->t_iflag & IGNBRK)
2745 goto cont;
2746 } else {
2747 if (com->tp == NULL

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

3941static void
3942siocnset(struct consdev *cd, int unit)
3943{
3944
3945 cd->cn_unit = unit;
3946 sprintf(cd->cn_name, "ttyd%d", unit);
3947}
3948
2741 goto cont;
2742 }
2743#endif
2744 if (com->tp == NULL
2745 || com->tp->t_iflag & IGNBRK)
2746 goto cont;
2747 } else {
2748 if (com->tp == NULL

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

3942static void
3943siocnset(struct consdev *cd, int unit)
3944{
3945
3946 cd->cn_unit = unit;
3947 sprintf(cd->cn_name, "ttyd%d", unit);
3948}
3949
3949#ifndef __alpha__
3950static speed_t siocngetspeed(Port_t, u_long rclk);
3950static speed_t siocngetspeed(Port_t, u_long rclk);
3951#endif
3952static void siocnclose(struct siocnstate *sp, Port_t iobase);
3953static void siocnopen(struct siocnstate *sp, Port_t iobase, int speed);
3954static void siocntxwait(Port_t iobase);
3955
3951static void siocnclose(struct siocnstate *sp, Port_t iobase);
3952static void siocnopen(struct siocnstate *sp, Port_t iobase, int speed);
3953static void siocntxwait(Port_t iobase);
3954
3956#ifdef __alpha__
3957int siocnattach(int port, int speed);
3958int siogdbattach(int port, int speed);
3959int siogdbgetc(void);
3960void siogdbputc(int c);
3961#else
3962static cn_probe_t siocnprobe;
3963static cn_init_t siocninit;
3964static cn_term_t siocnterm;
3955static cn_probe_t siocnprobe;
3956static cn_init_t siocninit;
3957static cn_term_t siocnterm;
3965#endif
3966static cn_checkc_t siocncheckc;
3967static cn_getc_t siocngetc;
3968static cn_putc_t siocnputc;
3969
3958static cn_checkc_t siocncheckc;
3959static cn_getc_t siocngetc;
3960static cn_putc_t siocnputc;
3961
3970#ifndef __alpha__
3971CONS_DRIVER(sio, siocnprobe, siocninit, siocnterm, siocngetc, siocncheckc,
3972 siocnputc, NULL);
3962CONS_DRIVER(sio, siocnprobe, siocninit, siocnterm, siocngetc, siocncheckc,
3963 siocnputc, NULL);
3973#endif
3974
3964
3975#if DDB > 0
3976static struct consdev gdbconsdev;
3977#endif
3978
3979static void
3980siocntxwait(iobase)
3981 Port_t iobase;
3982{
3983 int timo;
3984
3985 /*
3986 * Wait for any pending transmission to finish. Required to avoid
3987 * the UART lockup bug when the speed is changed, and for normal
3988 * transmits.
3989 */
3990 timo = 100000;
3991 while ((inb(iobase + com_lsr) & (LSR_TSRE | LSR_TXRDY))
3992 != (LSR_TSRE | LSR_TXRDY) && --timo != 0)
3993 ;
3994}
3995
3965static void
3966siocntxwait(iobase)
3967 Port_t iobase;
3968{
3969 int timo;
3970
3971 /*
3972 * Wait for any pending transmission to finish. Required to avoid
3973 * the UART lockup bug when the speed is changed, and for normal
3974 * transmits.
3975 */
3976 timo = 100000;
3977 while ((inb(iobase + com_lsr) & (LSR_TSRE | LSR_TXRDY))
3978 != (LSR_TSRE | LSR_TXRDY) && --timo != 0)
3979 ;
3980}
3981
3996#ifndef __alpha__
3997
3998/*
3999 * Read the serial port specified and try to figure out what speed
4000 * it's currently running at. We're assuming the serial port has
4001 * been initialized and is basicly idle. This routine is only intended
4002 * to be run at system startup.
4003 *
4004 * If the value read from the serial port doesn't make sense, return 0.
4005 */

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

4025 divisor = dlbh << 8 | dlbl;
4026
4027 /* XXX there should be more sanity checking. */
4028 if (divisor == 0)
4029 return (CONSPEED);
4030 return (rclk / (16UL * divisor));
4031}
4032
3982/*
3983 * Read the serial port specified and try to figure out what speed
3984 * it's currently running at. We're assuming the serial port has
3985 * been initialized and is basicly idle. This routine is only intended
3986 * to be run at system startup.
3987 *
3988 * If the value read from the serial port doesn't make sense, return 0.
3989 */

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

4009 divisor = dlbh << 8 | dlbl;
4010
4011 /* XXX there should be more sanity checking. */
4012 if (divisor == 0)
4013 return (CONSPEED);
4014 return (rclk / (16UL * divisor));
4015}
4016
4033#endif
4034
4035static void
4036siocnopen(sp, iobase, speed)
4037 struct siocnstate *sp;
4038 Port_t iobase;
4039 int speed;
4040{
4041 u_int divisor;
4042 u_char dlbh;

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

4094 outb(iobase + com_cfcr, sp->cfcr);
4095 /*
4096 * XXX damp oscillations of MCR_DTR and MCR_RTS by not restoring them.
4097 */
4098 outb(iobase + com_mcr, sp->mcr | MCR_DTR | MCR_RTS);
4099 outb(iobase + com_ier, sp->ier);
4100}
4101
4017static void
4018siocnopen(sp, iobase, speed)
4019 struct siocnstate *sp;
4020 Port_t iobase;
4021 int speed;
4022{
4023 u_int divisor;
4024 u_char dlbh;

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

4076 outb(iobase + com_cfcr, sp->cfcr);
4077 /*
4078 * XXX damp oscillations of MCR_DTR and MCR_RTS by not restoring them.
4079 */
4080 outb(iobase + com_mcr, sp->mcr | MCR_DTR | MCR_RTS);
4081 outb(iobase + com_ier, sp->ier);
4082}
4083
4102#ifndef __alpha__
4103
4104static void
4105siocnprobe(cp)
4106 struct consdev *cp;
4107{
4108 speed_t boot_speed;
4109 u_char cfcr;
4110 u_int divisor;
4111 int s, unit;

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

4171 if (COM_CONSOLE(flags) && !COM_LLCONSOLE(flags)) {
4172 siocnset(cp, unit);
4173 cp->cn_pri = COM_FORCECONSOLE(flags)
4174 || boothowto & RB_SERIAL
4175 ? CN_REMOTE : CN_NORMAL;
4176 siocniobase = iobase;
4177 siocnunit = unit;
4178 }
4084static void
4085siocnprobe(cp)
4086 struct consdev *cp;
4087{
4088 speed_t boot_speed;
4089 u_char cfcr;
4090 u_int divisor;
4091 int s, unit;

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

4151 if (COM_CONSOLE(flags) && !COM_LLCONSOLE(flags)) {
4152 siocnset(cp, unit);
4153 cp->cn_pri = COM_FORCECONSOLE(flags)
4154 || boothowto & RB_SERIAL
4155 ? CN_REMOTE : CN_NORMAL;
4156 siocniobase = iobase;
4157 siocnunit = unit;
4158 }
4179 if (COM_DEBUGGER(flags)) {
4180 printf("sio%d: gdb debugging port\n", unit);
4159#ifdef GDB
4160 if (COM_DEBUGGER(flags))
4181 siogdbiobase = iobase;
4161 siogdbiobase = iobase;
4182 siogdbunit = unit;
4183#if DDB > 0
4184 siocnset(&gdbconsdev, unit);
4185 gdb_arg = &gdbconsdev;
4186 gdb_getc = siocngetc;
4187 gdb_putc = siocnputc;
4188#endif
4162#endif
4189 }
4190 }
4191 }
4163 }
4164 }
4192#ifdef __i386__
4193#if DDB > 0
4194 /*
4195 * XXX Ugly Compatability.
4196 * If no gdb port has been specified, set it to be the console
4197 * as some configuration files don't specify the gdb port.
4198 */
4199 if (gdb_arg == NULL && (boothowto & RB_GDB)) {
4200 printf("Warning: no GDB port specified. Defaulting to sio%d.\n",
4201 siocnunit);
4202 printf("Set flag 0x80 on desired GDB port in your\n");
4203 printf("configuration file (currently sio only).\n");
4204 siogdbiobase = siocniobase;
4205 siogdbunit = siocnunit;
4206 siocnset(&gdbconsdev, siocnunit);
4207 gdb_arg = &gdbconsdev;
4208 gdb_getc = siocngetc;
4209 gdb_putc = siocnputc;
4210 }
4211#endif
4212#endif
4213}
4214
4215static void
4216siocninit(cp)
4217 struct consdev *cp;
4218{
4219 comconsole = cp->cn_unit;
4220}
4221
4222static void
4223siocnterm(cp)
4224 struct consdev *cp;
4225{
4226 comconsole = -1;
4227}
4228
4165}
4166
4167static void
4168siocninit(cp)
4169 struct consdev *cp;
4170{
4171 comconsole = cp->cn_unit;
4172}
4173
4174static void
4175siocnterm(cp)
4176 struct consdev *cp;
4177{
4178 comconsole = -1;
4179}
4180
4229#endif
4230
4231#ifdef __alpha__
4232
4233CONS_DRIVER(sio, NULL, NULL, NULL, siocngetc, siocncheckc, siocnputc, NULL);
4234
4235int
4236siocnattach(port, speed)
4237 int port;
4238 int speed;
4239{
4240 int s;
4241 u_char cfcr;
4242 u_int divisor;
4243 struct siocnstate sp;
4244 int unit = 0; /* XXX random value! */
4245
4246 siocniobase = port;
4247 siocnunit = unit;
4248 comdefaultrate = speed;
4249 sio_consdev.cn_pri = CN_NORMAL;
4250 siocnset(&sio_consdev, unit);
4251
4252 s = spltty();
4253
4254 /*
4255 * Initialize the divisor latch. We can't rely on
4256 * siocnopen() to do this the first time, since it
4257 * avoids writing to the latch if the latch appears
4258 * to have the correct value. Also, if we didn't
4259 * just read the speed from the hardware, then we
4260 * need to set the speed in hardware so that
4261 * switching it later is null.
4262 */
4263 cfcr = inb(siocniobase + com_cfcr);
4264 outb(siocniobase + com_cfcr, CFCR_DLAB | cfcr);
4265 divisor = siodivisor(comdefaultrclk, comdefaultrate);
4266 outb(siocniobase + com_dlbl, divisor & 0xff);
4267 outb(siocniobase + com_dlbh, divisor >> 8);
4268 outb(siocniobase + com_cfcr, cfcr);
4269
4270 siocnopen(&sp, siocniobase, comdefaultrate);
4271 splx(s);
4272
4273 cnadd(&sio_consdev);
4274 return (0);
4275}
4276
4277int
4278siogdbattach(port, speed)
4279 int port;
4280 int speed;
4281{
4282 int s;
4283 u_char cfcr;
4284 u_int divisor;
4285 struct siocnstate sp;
4286 int unit = 1; /* XXX random value! */
4287
4288 siogdbiobase = port;
4289 gdbdefaultrate = speed;
4290
4291 printf("sio%d: gdb debugging port\n", unit);
4292 siogdbunit = unit;
4293#if DDB > 0
4294 siocnset(&gdbconsdev, unit);
4295 gdb_arg = &gdbconsdev;
4296 gdb_getc = siocngetc;
4297 gdb_putc = siocnputc;
4298#endif
4299
4300 s = spltty();
4301
4302 /*
4303 * Initialize the divisor latch. We can't rely on
4304 * siocnopen() to do this the first time, since it
4305 * avoids writing to the latch if the latch appears
4306 * to have the correct value. Also, if we didn't
4307 * just read the speed from the hardware, then we
4308 * need to set the speed in hardware so that
4309 * switching it later is null.
4310 */
4311 cfcr = inb(siogdbiobase + com_cfcr);
4312 outb(siogdbiobase + com_cfcr, CFCR_DLAB | cfcr);
4313 divisor = siodivisor(comdefaultrclk, gdbdefaultrate);
4314 outb(siogdbiobase + com_dlbl, divisor & 0xff);
4315 outb(siogdbiobase + com_dlbh, divisor >> 8);
4316 outb(siogdbiobase + com_cfcr, cfcr);
4317
4318 siocnopen(&sp, siogdbiobase, gdbdefaultrate);
4319 splx(s);
4320
4321 return (0);
4322}
4323
4324#endif
4325
4326static int
4327siocncheckc(struct consdev *cd)
4328{
4329 int c;
4330 Port_t iobase;
4331 int s;
4332 struct siocnstate sp;
4333 speed_t speed;
4334
4181static int
4182siocncheckc(struct consdev *cd)
4183{
4184 int c;
4185 Port_t iobase;
4186 int s;
4187 struct siocnstate sp;
4188 speed_t speed;
4189
4335 if (cd->cn_unit == siocnunit) {
4190 if (cd != NULL && cd->cn_unit == siocnunit) {
4336 iobase = siocniobase;
4337 speed = comdefaultrate;
4338 } else {
4191 iobase = siocniobase;
4192 speed = comdefaultrate;
4193 } else {
4194#ifdef GDB
4339 iobase = siogdbiobase;
4340 speed = gdbdefaultrate;
4195 iobase = siogdbiobase;
4196 speed = gdbdefaultrate;
4197#else
4198 return (-1);
4199#endif
4341 }
4342 s = spltty();
4343 siocnopen(&sp, iobase, speed);
4344 if (inb(iobase + com_lsr) & LSR_RXRDY)
4345 c = inb(iobase + com_data);
4346 else
4347 c = -1;
4348 siocnclose(&sp, iobase);

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

4354siocngetc(struct consdev *cd)
4355{
4356 int c;
4357 Port_t iobase;
4358 int s;
4359 struct siocnstate sp;
4360 speed_t speed;
4361
4200 }
4201 s = spltty();
4202 siocnopen(&sp, iobase, speed);
4203 if (inb(iobase + com_lsr) & LSR_RXRDY)
4204 c = inb(iobase + com_data);
4205 else
4206 c = -1;
4207 siocnclose(&sp, iobase);

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

4213siocngetc(struct consdev *cd)
4214{
4215 int c;
4216 Port_t iobase;
4217 int s;
4218 struct siocnstate sp;
4219 speed_t speed;
4220
4362 if (cd->cn_unit == siocnunit) {
4221 if (cd != NULL && cd->cn_unit == siocnunit) {
4363 iobase = siocniobase;
4364 speed = comdefaultrate;
4365 } else {
4222 iobase = siocniobase;
4223 speed = comdefaultrate;
4224 } else {
4225#ifdef GDB
4366 iobase = siogdbiobase;
4367 speed = gdbdefaultrate;
4226 iobase = siogdbiobase;
4227 speed = gdbdefaultrate;
4228#else
4229 return (-1);
4230#endif
4368 }
4369 s = spltty();
4370 siocnopen(&sp, iobase, speed);
4371 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
4372 ;
4373 c = inb(iobase + com_data);
4374 siocnclose(&sp, iobase);
4375 splx(s);

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

4380siocnputc(struct consdev *cd, int c)
4381{
4382 int need_unlock;
4383 int s;
4384 struct siocnstate sp;
4385 Port_t iobase;
4386 speed_t speed;
4387
4231 }
4232 s = spltty();
4233 siocnopen(&sp, iobase, speed);
4234 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
4235 ;
4236 c = inb(iobase + com_data);
4237 siocnclose(&sp, iobase);
4238 splx(s);

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

4243siocnputc(struct consdev *cd, int c)
4244{
4245 int need_unlock;
4246 int s;
4247 struct siocnstate sp;
4248 Port_t iobase;
4249 speed_t speed;
4250
4388 if (cd->cn_unit == siocnunit) {
4251 if (cd != NULL && cd->cn_unit == siocnunit) {
4389 iobase = siocniobase;
4390 speed = comdefaultrate;
4391 } else {
4252 iobase = siocniobase;
4253 speed = comdefaultrate;
4254 } else {
4255#ifdef GDB
4392 iobase = siogdbiobase;
4393 speed = gdbdefaultrate;
4256 iobase = siogdbiobase;
4257 speed = gdbdefaultrate;
4258#else
4259 return;
4260#endif
4394 }
4395 s = spltty();
4396 need_unlock = 0;
4397 if (sio_inited == 2 && !mtx_owned(&sio_lock)) {
4398 mtx_lock_spin(&sio_lock);
4399 need_unlock = 1;
4400 }
4401 siocnopen(&sp, iobase, speed);
4402 siocntxwait(iobase);
4403 outb(iobase + com_data, c);
4404 siocnclose(&sp, iobase);
4405 if (need_unlock)
4406 mtx_unlock_spin(&sio_lock);
4407 splx(s);
4408}
4409
4261 }
4262 s = spltty();
4263 need_unlock = 0;
4264 if (sio_inited == 2 && !mtx_owned(&sio_lock)) {
4265 mtx_lock_spin(&sio_lock);
4266 need_unlock = 1;
4267 }
4268 siocnopen(&sp, iobase, speed);
4269 siocntxwait(iobase);
4270 outb(iobase + com_data, c);
4271 siocnclose(&sp, iobase);
4272 if (need_unlock)
4273 mtx_unlock_spin(&sio_lock);
4274 splx(s);
4275}
4276
4410#ifdef __alpha__
4411int
4412siogdbgetc()
4277/*
4278 * Remote gdb(1) support.
4279 */
4280
4281#if defined(GDB)
4282
4283#include <gdb/gdb.h>
4284
4285static gdb_probe_f siogdbprobe;
4286static gdb_init_f siogdbinit;
4287static gdb_term_f siogdbterm;
4288static gdb_getc_f siogdbgetc;
4289static gdb_checkc_f siogdbcheckc;
4290static gdb_putc_f siogdbputc;
4291
4292GDB_DBGPORT(sio, siogdbprobe, siogdbinit, siogdbterm, siogdbcheckc,
4293 siogdbgetc, siogdbputc);
4294
4295static int
4296siogdbprobe(void)
4413{
4297{
4414 int c;
4415 Port_t iobase;
4416 speed_t speed;
4417 int s;
4418 struct siocnstate sp;
4298 return ((siogdbiobase != 0) ? 0 : -1);
4299}
4419
4300
4420 if (siogdbunit == siocnunit) {
4421 iobase = siocniobase;
4422 speed = comdefaultrate;
4423 } else {
4424 iobase = siogdbiobase;
4425 speed = gdbdefaultrate;
4426 }
4301static void
4302siogdbinit(void)
4303{
4304}
4427
4305
4428 s = spltty();
4429 siocnopen(&sp, iobase, speed);
4430 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
4431 ;
4432 c = inb(iobase + com_data);
4433 siocnclose(&sp, iobase);
4434 splx(s);
4435 return (c);
4306static void
4307siogdbterm(void)
4308{
4436}
4437
4309}
4310
4438void
4439siogdbputc(c)
4440 int c;
4311static void
4312siogdbputc(int c)
4441{
4313{
4442 Port_t iobase;
4443 speed_t speed;
4444 int s;
4445 struct siocnstate sp;
4314 siocnputc(NULL, c);
4315}
4446
4316
4447 if (siogdbunit == siocnunit) {
4448 iobase = siocniobase;
4449 speed = comdefaultrate;
4450 } else {
4451 iobase = siogdbiobase;
4452 speed = gdbdefaultrate;
4453 }
4317static int
4318siogdbcheckc(void)
4319{
4320 return (siocncheckc(NULL));
4321}
4454
4322
4455 s = spltty();
4456 siocnopen(&sp, iobase, speed);
4457 siocntxwait(siogdbiobase);
4458 outb(siogdbiobase + com_data, c);
4459 siocnclose(&sp, siogdbiobase);
4460 splx(s);
4323static int
4324siogdbgetc(void)
4325{
4326 return (siocngetc(NULL));
4461}
4327}
4328
4462#endif
4463
4464#ifdef PC98
4465/*
4466 * pc98 local function
4467 */
4468static void
4469com_tiocm_bis(struct com_s *com, int msr)

--- 583 unchanged lines hidden ---
4329#endif
4330
4331#ifdef PC98
4332/*
4333 * pc98 local function
4334 */
4335static void
4336com_tiocm_bis(struct com_s *com, int msr)

--- 583 unchanged lines hidden ---