Deleted Added
full compact
comconsole.c (229435) comconsole.c (241300)
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.

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

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>
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.

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

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/i386/libi386/comconsole.c 229435 2012-01-03 22:36:12Z kib $");
27__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/comconsole.c 241300 2012-10-06 20:04:51Z avg $");
28
29#include <stand.h>
30#include <bootstrap.h>
31#include <machine/cpufunc.h>
32#include <dev/ic/ns16550.h>
33#include <dev/pci/pcireg.h>
34#include "libi386.h"
35

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

58 const void *value);
59static int comc_pcidev_handle(uint32_t locator);
60static int comc_port_set(struct env_var *ev, int flags,
61 const void *value);
62static void comc_setup(int speed, int port);
63static int comc_speed_set(struct env_var *ev, int flags,
64 const void *value);
65
28
29#include <stand.h>
30#include <bootstrap.h>
31#include <machine/cpufunc.h>
32#include <dev/ic/ns16550.h>
33#include <dev/pci/pcireg.h>
34#include "libi386.h"
35

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

58 const void *value);
59static int comc_pcidev_handle(uint32_t locator);
60static int comc_port_set(struct env_var *ev, int flags,
61 const void *value);
62static void comc_setup(int speed, int port);
63static int comc_speed_set(struct env_var *ev, int flags,
64 const void *value);
65
66static int comc_started;
67static int comc_curspeed;
68static int comc_port = COMPORT;
69static uint32_t comc_locator;
70
71struct console comconsole = {
72 "comconsole",
73 "serial port",
74 0,

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

82static void
83comc_probe(struct console *cp)
84{
85 char intbuf[16];
86 char *cons, *env;
87 int speed, port;
88 uint32_t locator;
89
66static int comc_curspeed;
67static int comc_port = COMPORT;
68static uint32_t comc_locator;
69
70struct console comconsole = {
71 "comconsole",
72 "serial port",
73 0,

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

81static void
82comc_probe(struct console *cp)
83{
84 char intbuf[16];
85 char *cons, *env;
86 int speed, port;
87 uint32_t locator;
88
90 /* XXX check the BIOS equipment list? */
91 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
92
93 if (comc_curspeed == 0) {
94 comc_curspeed = COMSPEED;
95 /*
96 * Assume that the speed was set by an earlier boot loader if
97 * comconsole is already the preferred console.
98 */
99 cons = getenv("console");
100 if ((cons != NULL && strcmp(cons, comconsole.c_name) == 0) ||

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

132 if (locator != 0)
133 comc_pcidev_handle(locator);
134 }
135
136 unsetenv("comconsole_pcidev");
137 env_setenv("comconsole_pcidev", EV_VOLATILE, env, comc_pcidev_set,
138 env_nounset);
139 }
89 if (comc_curspeed == 0) {
90 comc_curspeed = COMSPEED;
91 /*
92 * Assume that the speed was set by an earlier boot loader if
93 * comconsole is already the preferred console.
94 */
95 cons = getenv("console");
96 if ((cons != NULL && strcmp(cons, comconsole.c_name) == 0) ||

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

128 if (locator != 0)
129 comc_pcidev_handle(locator);
130 }
131
132 unsetenv("comconsole_pcidev");
133 env_setenv("comconsole_pcidev", EV_VOLATILE, env, comc_pcidev_set,
134 env_nounset);
135 }
136 comc_setup(comc_curspeed, comc_port);
140}
141
142static int
143comc_init(int arg)
144{
137}
138
139static int
140comc_init(int arg)
141{
145 if (comc_started && arg == 0)
146 return 0;
147 comc_started = 1;
148
149 comc_setup(comc_curspeed, comc_port);
150
142
143 comc_setup(comc_curspeed, comc_port);
144
151 return(0);
145 if ((comconsole.c_flags & (C_PRESENTIN | C_PRESENTOUT)) ==
146 (C_PRESENTIN | C_PRESENTOUT))
147 return (CMD_OK);
148 return (CMD_ERROR);
152}
153
154static void
155comc_putchar(int c)
156{
157 int wait;
158
159 for (wait = COMC_TXWAIT; wait > 0; wait--)
160 if (inb(comc_port + com_lsr) & LSR_TXRDY) {
161 outb(comc_port + com_data, (u_char)c);
162 break;
163 }
164}
165
166static int
167comc_getchar(void)
168{
149}
150
151static void
152comc_putchar(int c)
153{
154 int wait;
155
156 for (wait = COMC_TXWAIT; wait > 0; wait--)
157 if (inb(comc_port + com_lsr) & LSR_TXRDY) {
158 outb(comc_port + com_data, (u_char)c);
159 break;
160 }
161}
162
163static int
164comc_getchar(void)
165{
169 return(comc_ischar() ? inb(comc_port + com_data) : -1);
166 return (comc_ischar() ? inb(comc_port + com_data) : -1);
170}
171
172static int
173comc_ischar(void)
174{
167}
168
169static int
170comc_ischar(void)
171{
175 return(inb(comc_port + com_lsr) & LSR_RXRDY);
172 return (inb(comc_port + com_lsr) & LSR_RXRDY);
176}
177
178static int
179comc_speed_set(struct env_var *ev, int flags, const void *value)
180{
181 int speed;
182
183 if (value == NULL || (speed = comc_parseint(value)) <= 0) {
184 printf("Invalid speed\n");
185 return (CMD_ERROR);
186 }
187
173}
174
175static int
176comc_speed_set(struct env_var *ev, int flags, const void *value)
177{
178 int speed;
179
180 if (value == NULL || (speed = comc_parseint(value)) <= 0) {
181 printf("Invalid speed\n");
182 return (CMD_ERROR);
183 }
184
188 if (comc_started && comc_curspeed != speed)
185 if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) != 0 &&
186 comc_curspeed != speed)
189 comc_setup(speed, comc_port);
190
191 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
192
193 return (CMD_OK);
194}
195
196static int
197comc_port_set(struct env_var *ev, int flags, const void *value)
198{
199 int port;
200
201 if (value == NULL || (port = comc_parseint(value)) <= 0) {
202 printf("Invalid port\n");
203 return (CMD_ERROR);
204 }
205
187 comc_setup(speed, comc_port);
188
189 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
190
191 return (CMD_OK);
192}
193
194static int
195comc_port_set(struct env_var *ev, int flags, const void *value)
196{
197 int port;
198
199 if (value == NULL || (port = comc_parseint(value)) <= 0) {
200 printf("Invalid port\n");
201 return (CMD_ERROR);
202 }
203
206 if (comc_started && comc_port != port) {
204 if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) != 0 &&
205 comc_port != port) {
207 comc_setup(comc_curspeed, port);
208 set_hw_console_hint();
209 }
210
211 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
212
213 return (CMD_OK);
214}

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

300{
301 uint32_t locator;
302 int error;
303
304 if (value == NULL || (locator = comc_parse_pcidev(value)) <= 0) {
305 printf("Invalid pcidev\n");
306 return (CMD_ERROR);
307 }
206 comc_setup(comc_curspeed, port);
207 set_hw_console_hint();
208 }
209
210 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
211
212 return (CMD_OK);
213}

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

299{
300 uint32_t locator;
301 int error;
302
303 if (value == NULL || (locator = comc_parse_pcidev(value)) <= 0) {
304 printf("Invalid pcidev\n");
305 return (CMD_ERROR);
306 }
308 if (comc_started && comc_locator != locator) {
307 if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) != 0 &&
308 comc_locator != locator) {
309 error = comc_pcidev_handle(locator);
310 if (error != CMD_OK)
311 return (error);
312 }
313 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
314 return (CMD_OK);
315}
316
317static void
318comc_setup(int speed, int port)
319{
309 error = comc_pcidev_handle(locator);
310 if (error != CMD_OK)
311 return (error);
312 }
313 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
314 return (CMD_OK);
315}
316
317static void
318comc_setup(int speed, int port)
319{
320 static int TRY_COUNT = 1000000;
321 int tries;
320
321 comc_curspeed = speed;
322 comc_port = port;
323
324 outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT);
325 outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff);
326 outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8);
327 outb(comc_port + com_cfcr, COMC_FMT);
328 outb(comc_port + com_mcr, MCR_RTS | MCR_DTR);
329
322
323 comc_curspeed = speed;
324 comc_port = port;
325
326 outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT);
327 outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff);
328 outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8);
329 outb(comc_port + com_cfcr, COMC_FMT);
330 outb(comc_port + com_mcr, MCR_RTS | MCR_DTR);
331
332 tries = 0;
330 do
331 inb(comc_port + com_data);
333 do
334 inb(comc_port + com_data);
332 while (inb(comc_port + com_lsr) & LSR_RXRDY);
335 while (inb(comc_port + com_lsr) & LSR_RXRDY && ++tries < TRY_COUNT);
336
337 if (tries < TRY_COUNT)
338 comconsole.c_flags |= (C_PRESENTIN | C_PRESENTOUT);
339 else
340 comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT);
333}
334
335static int
336comc_parseint(const char *speedstr)
337{
338 char *p;
339 int speed;
340

--- 30 unchanged lines hidden ---
341}
342
343static int
344comc_parseint(const char *speedstr)
345{
346 char *p;
347 int speed;
348

--- 30 unchanged lines hidden ---