Deleted Added
full compact
comconsole.c (120118) comconsole.c (146011)
1/*
1/*-
2 * Copyright (c) 1998 Michael Smith (msmith@freebsd.org)
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
2 * Copyright (c) 1998 Michael Smith (msmith@freebsd.org)
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
27__FBSDID("$FreeBSD: head/sys/boot/pc98/libpc98/comconsole.c 120118 2003-09-16 11:24:23Z bde $");
27__FBSDID("$FreeBSD: head/sys/boot/pc98/libpc98/comconsole.c 146011 2005-05-08 14:17:28Z nyan $");
28
29#include <stand.h>
30#include <bootstrap.h>
31#include <machine/cpufunc.h>
32#include <dev/ic/ns16550.h>
33#include "libi386.h"
34
35#define COMC_FMT 0x3 /* 8N1 */
36#define COMC_TXWAIT 0x40000 /* transmit timeout */
37#define COMC_BPS(x) (115200 / (x)) /* speed to DLAB divisor */
38
39#ifndef COMPORT
28
29#include <stand.h>
30#include <bootstrap.h>
31#include <machine/cpufunc.h>
32#include <dev/ic/ns16550.h>
33#include "libi386.h"
34
35#define COMC_FMT 0x3 /* 8N1 */
36#define COMC_TXWAIT 0x40000 /* transmit timeout */
37#define COMC_BPS(x) (115200 / (x)) /* speed to DLAB divisor */
38
39#ifndef COMPORT
40#ifdef PC98
41#define COMPORT 0x238
40#define COMPORT 0x238
42#else
43#define COMPORT 0x3f8
44#endif
41#endif
45#endif
46#ifndef COMSPEED
47#define COMSPEED 9600
48#endif
49
50static void comc_probe(struct console *cp);
51static int comc_init(int arg);
52static void comc_putchar(int c);
53static int comc_getchar(void);
54static int comc_ischar(void);
55
56static int comc_started;
57
58struct console comconsole = {
59 "comconsole",
60 "serial port",
61 0,
62 comc_probe,
63 comc_init,
64 comc_putchar,
65 comc_getchar,
66 comc_ischar
67};
68
69static void
70comc_probe(struct console *cp)
71{
72 /* XXX check the BIOS equipment list? */
73 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
74}
75
76static int
77comc_init(int arg)
78{
79 if (comc_started && arg == 0)
80 return 0;
81 comc_started = 1;
82
83 outb(COMPORT + com_cfcr, CFCR_DLAB | COMC_FMT);
84 outb(COMPORT + com_dlbl, COMC_BPS(COMSPEED) & 0xff);
85 outb(COMPORT + com_dlbh, COMC_BPS(COMSPEED) >> 8);
86 outb(COMPORT + com_cfcr, COMC_FMT);
87 outb(COMPORT + com_mcr, MCR_RTS | MCR_DTR);
88
89 do
90 inb(COMPORT + com_data);
91 while (inb(COMPORT + com_lsr) & LSR_RXRDY);
92
93 return(0);
94}
95
96static void
97comc_putchar(int c)
98{
99 int wait;
100
101 for (wait = COMC_TXWAIT; wait > 0; wait--)
102 if (inb(COMPORT + com_lsr) & LSR_TXRDY) {
103 outb(COMPORT + com_data, (u_char)c);
104 break;
105 }
106}
107
108static int
109comc_getchar(void)
110{
111 return(comc_ischar() ? inb(COMPORT + com_data) : -1);
112}
113
114static int
115comc_ischar(void)
116{
117 return(inb(COMPORT + com_lsr) & LSR_RXRDY);
118}
42#ifndef COMSPEED
43#define COMSPEED 9600
44#endif
45
46static void comc_probe(struct console *cp);
47static int comc_init(int arg);
48static void comc_putchar(int c);
49static int comc_getchar(void);
50static int comc_ischar(void);
51
52static int comc_started;
53
54struct console comconsole = {
55 "comconsole",
56 "serial port",
57 0,
58 comc_probe,
59 comc_init,
60 comc_putchar,
61 comc_getchar,
62 comc_ischar
63};
64
65static void
66comc_probe(struct console *cp)
67{
68 /* XXX check the BIOS equipment list? */
69 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
70}
71
72static int
73comc_init(int arg)
74{
75 if (comc_started && arg == 0)
76 return 0;
77 comc_started = 1;
78
79 outb(COMPORT + com_cfcr, CFCR_DLAB | COMC_FMT);
80 outb(COMPORT + com_dlbl, COMC_BPS(COMSPEED) & 0xff);
81 outb(COMPORT + com_dlbh, COMC_BPS(COMSPEED) >> 8);
82 outb(COMPORT + com_cfcr, COMC_FMT);
83 outb(COMPORT + com_mcr, MCR_RTS | MCR_DTR);
84
85 do
86 inb(COMPORT + com_data);
87 while (inb(COMPORT + com_lsr) & LSR_RXRDY);
88
89 return(0);
90}
91
92static void
93comc_putchar(int c)
94{
95 int wait;
96
97 for (wait = COMC_TXWAIT; wait > 0; wait--)
98 if (inb(COMPORT + com_lsr) & LSR_TXRDY) {
99 outb(COMPORT + com_data, (u_char)c);
100 break;
101 }
102}
103
104static int
105comc_getchar(void)
106{
107 return(comc_ischar() ? inb(COMPORT + com_data) : -1);
108}
109
110static int
111comc_ischar(void)
112{
113 return(inb(COMPORT + com_lsr) & LSR_RXRDY);
114}