Deleted Added
full compact
comconsole.c (241300) comconsole.c (245848)
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 241300 2012-10-06 20:04:51Z avg $");
27__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/comconsole.c 245848 2013-01-23 18:34:21Z jhb $");
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

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

45#define COMSPEED 9600
46#endif
47
48static void comc_probe(struct console *cp);
49static int comc_init(int arg);
50static void comc_putchar(int c);
51static int comc_getchar(void);
52static int comc_getspeed(void);
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

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

45#define COMSPEED 9600
46#endif
47
48static void comc_probe(struct console *cp);
49static int comc_init(int arg);
50static void comc_putchar(int c);
51static int comc_getchar(void);
52static int comc_getspeed(void);
53static void set_hw_console_hint(void);
54static int comc_ischar(void);
55static int comc_parseint(const char *string);
56static uint32_t comc_parse_pcidev(const char *string);
57static int comc_pcidev_set(struct env_var *ev, int flags,
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);

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

197 int port;
198
199 if (value == NULL || (port = comc_parseint(value)) <= 0) {
200 printf("Invalid port\n");
201 return (CMD_ERROR);
202 }
203
204 if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) != 0 &&
53static int comc_ischar(void);
54static int comc_parseint(const char *string);
55static uint32_t comc_parse_pcidev(const char *string);
56static int comc_pcidev_set(struct env_var *ev, int flags,
57 const void *value);
58static int comc_pcidev_handle(uint32_t locator);
59static int comc_port_set(struct env_var *ev, int flags,
60 const void *value);

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

196 int port;
197
198 if (value == NULL || (port = comc_parseint(value)) <= 0) {
199 printf("Invalid port\n");
200 return (CMD_ERROR);
201 }
202
203 if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) != 0 &&
205 comc_port != port) {
204 comc_port != port)
206 comc_setup(comc_curspeed, port);
205 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}
214
206
207 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
208
209 return (CMD_OK);
210}
211
215static void
216set_hw_console_hint(void)
217{
218 char intbuf[64];
219
220 unsetenv("hw.uart.console");
221 sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed);
222 env_setenv("hw.uart.console", EV_VOLATILE, intbuf,
223 env_noset, env_nounset);
224}
225
226/*
227 * Input: bus:dev:func[:bar]. If bar is not specified, it is 0x10.
228 * Output: bar[24:16] bus[15:8] dev[7:3] func[2:0]
229 */
230static uint32_t
231comc_parse_pcidev(const char *string)
232{
233 char *p, *p1;

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

283 port &= PCIM_BAR_IO_BASE;
284
285 sprintf(intbuf, "%d", port);
286 unsetenv("comconsole_port");
287 env_setenv("comconsole_port", EV_VOLATILE, intbuf,
288 comc_port_set, env_nounset);
289
290 comc_setup(comc_curspeed, port);
212/*
213 * Input: bus:dev:func[:bar]. If bar is not specified, it is 0x10.
214 * Output: bar[24:16] bus[15:8] dev[7:3] func[2:0]
215 */
216static uint32_t
217comc_parse_pcidev(const char *string)
218{
219 char *p, *p1;

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

269 port &= PCIM_BAR_IO_BASE;
270
271 sprintf(intbuf, "%d", port);
272 unsetenv("comconsole_port");
273 env_setenv("comconsole_port", EV_VOLATILE, intbuf,
274 comc_port_set, env_nounset);
275
276 comc_setup(comc_curspeed, port);
291 set_hw_console_hint();
292 comc_locator = locator;
293
294 return (CMD_OK);
295}
296
297static int
298comc_pcidev_set(struct env_var *ev, int flags, const void *value)
299{

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

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;
277 comc_locator = locator;
278
279 return (CMD_OK);
280}
281
282static int
283comc_pcidev_set(struct env_var *ev, int flags, const void *value)
284{

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

298 env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
299 return (CMD_OK);
300}
301
302static void
303comc_setup(int speed, int port)
304{
305 static int TRY_COUNT = 1000000;
306 char intbuf[64];
321 int tries;
322
307 int tries;
308
309 unsetenv("hw.uart.console");
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;
333 do
334 inb(comc_port + com_data);
335 while (inb(comc_port + com_lsr) & LSR_RXRDY && ++tries < TRY_COUNT);
336
310 comc_curspeed = speed;
311 comc_port = port;
312
313 outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT);
314 outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff);
315 outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8);
316 outb(comc_port + com_cfcr, COMC_FMT);
317 outb(comc_port + com_mcr, MCR_RTS | MCR_DTR);
318
319 tries = 0;
320 do
321 inb(comc_port + com_data);
322 while (inb(comc_port + com_lsr) & LSR_RXRDY && ++tries < TRY_COUNT);
323
337 if (tries < TRY_COUNT)
324 if (tries < TRY_COUNT) {
338 comconsole.c_flags |= (C_PRESENTIN | C_PRESENTOUT);
325 comconsole.c_flags |= (C_PRESENTIN | C_PRESENTOUT);
339 else
326 sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed);
327 env_setenv("hw.uart.console", EV_VOLATILE, intbuf, NULL, NULL);
328 } else
340 comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT);
341}
342
343static int
344comc_parseint(const char *speedstr)
345{
346 char *p;
347 int speed;

--- 31 unchanged lines hidden ---
329 comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT);
330}
331
332static int
333comc_parseint(const char *speedstr)
334{
335 char *p;
336 int speed;

--- 31 unchanged lines hidden ---