loader: libi386/comconsole.c cstyle cleanup

Only cstyle, no functional changes.
This commit is contained in:
Toomas Soome 2019-11-02 10:53:23 +00:00
parent 183b6fead8
commit 0060947db1

View File

@ -67,144 +67,144 @@ static int comc_port = COMPORT;
static uint32_t comc_locator; static uint32_t comc_locator;
struct console comconsole = { struct console comconsole = {
"comconsole", .c_name = "comconsole",
"serial port", .c_desc = "serial port",
0, .c_flags = 0,
comc_probe, .c_probe = comc_probe,
comc_init, .c_init = comc_init,
comc_putchar, .c_out = comc_putchar,
comc_getchar, .c_in = comc_getchar,
comc_ischar .c_ready = comc_ischar
}; };
static void static void
comc_probe(struct console *cp) comc_probe(struct console *cp)
{ {
char intbuf[16]; char intbuf[16];
char *cons, *env; char *cons, *env;
int speed, port; int speed, port;
uint32_t locator; uint32_t locator;
if (comc_curspeed == 0) { if (comc_curspeed == 0) {
comc_curspeed = COMSPEED; comc_curspeed = COMSPEED;
/* /*
* Assume that the speed was set by an earlier boot loader if * Assume that the speed was set by an earlier boot loader if
* comconsole is already the preferred console. * comconsole is already the preferred console.
*/ */
cons = getenv("console"); cons = getenv("console");
if ((cons != NULL && strcmp(cons, comconsole.c_name) == 0) || if ((cons != NULL && strcmp(cons, comconsole.c_name) == 0) ||
getenv("boot_multicons") != NULL) { getenv("boot_multicons") != NULL) {
comc_curspeed = comc_getspeed(); comc_curspeed = comc_getspeed();
}
env = getenv("comconsole_speed");
if (env != NULL) {
speed = comc_parseint(env);
if (speed > 0)
comc_curspeed = speed;
}
sprintf(intbuf, "%d", comc_curspeed);
unsetenv("comconsole_speed");
env_setenv("comconsole_speed", EV_VOLATILE, intbuf,
comc_speed_set, env_nounset);
env = getenv("comconsole_port");
if (env != NULL) {
port = comc_parseint(env);
if (port > 0)
comc_port = port;
}
sprintf(intbuf, "%d", comc_port);
unsetenv("comconsole_port");
env_setenv("comconsole_port", EV_VOLATILE, intbuf,
comc_port_set, env_nounset);
env = getenv("comconsole_pcidev");
if (env != NULL) {
locator = comc_parse_pcidev(env);
if (locator != 0)
comc_pcidev_handle(locator);
}
unsetenv("comconsole_pcidev");
env_setenv("comconsole_pcidev", EV_VOLATILE, env,
comc_pcidev_set, env_nounset);
} }
comc_setup(comc_curspeed, comc_port);
env = getenv("comconsole_speed");
if (env != NULL) {
speed = comc_parseint(env);
if (speed > 0)
comc_curspeed = speed;
}
sprintf(intbuf, "%d", comc_curspeed);
unsetenv("comconsole_speed");
env_setenv("comconsole_speed", EV_VOLATILE, intbuf, comc_speed_set,
env_nounset);
env = getenv("comconsole_port");
if (env != NULL) {
port = comc_parseint(env);
if (port > 0)
comc_port = port;
}
sprintf(intbuf, "%d", comc_port);
unsetenv("comconsole_port");
env_setenv("comconsole_port", EV_VOLATILE, intbuf, comc_port_set,
env_nounset);
env = getenv("comconsole_pcidev");
if (env != NULL) {
locator = comc_parse_pcidev(env);
if (locator != 0)
comc_pcidev_handle(locator);
}
unsetenv("comconsole_pcidev");
env_setenv("comconsole_pcidev", EV_VOLATILE, env, comc_pcidev_set,
env_nounset);
}
comc_setup(comc_curspeed, comc_port);
} }
static int static int
comc_init(int arg) comc_init(int arg)
{ {
comc_setup(comc_curspeed, comc_port); comc_setup(comc_curspeed, comc_port);
if ((comconsole.c_flags & (C_PRESENTIN | C_PRESENTOUT)) == if ((comconsole.c_flags & (C_PRESENTIN | C_PRESENTOUT)) ==
(C_PRESENTIN | C_PRESENTOUT)) (C_PRESENTIN | C_PRESENTOUT))
return (CMD_OK); return (CMD_OK);
return (CMD_ERROR); return (CMD_ERROR);
} }
static void static void
comc_putchar(int c) comc_putchar(int c)
{ {
int wait; int wait;
for (wait = COMC_TXWAIT; wait > 0; wait--) for (wait = COMC_TXWAIT; wait > 0; wait--)
if (inb(comc_port + com_lsr) & LSR_TXRDY) { if (inb(comc_port + com_lsr) & LSR_TXRDY) {
outb(comc_port + com_data, (u_char)c); outb(comc_port + com_data, (u_char)c);
break; break;
} }
} }
static int static int
comc_getchar(void) comc_getchar(void)
{ {
return (comc_ischar() ? inb(comc_port + com_data) : -1); return (comc_ischar() ? inb(comc_port + com_data) : -1);
} }
static int static int
comc_ischar(void) comc_ischar(void)
{ {
return (inb(comc_port + com_lsr) & LSR_RXRDY); return (inb(comc_port + com_lsr) & LSR_RXRDY);
} }
static int static int
comc_speed_set(struct env_var *ev, int flags, const void *value) comc_speed_set(struct env_var *ev, int flags, const void *value)
{ {
int speed; int speed;
if (value == NULL || (speed = comc_parseint(value)) <= 0) { if (value == NULL || (speed = comc_parseint(value)) <= 0) {
printf("Invalid speed\n"); printf("Invalid speed\n");
return (CMD_ERROR); return (CMD_ERROR);
} }
if (comc_curspeed != speed) if (comc_curspeed != speed)
comc_setup(speed, comc_port); comc_setup(speed, comc_port);
env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
return (CMD_OK); return (CMD_OK);
} }
static int static int
comc_port_set(struct env_var *ev, int flags, const void *value) comc_port_set(struct env_var *ev, int flags, const void *value)
{ {
int port; int port;
if (value == NULL || (port = comc_parseint(value)) <= 0) { if (value == NULL || (port = comc_parseint(value)) <= 0) {
printf("Invalid port\n"); printf("Invalid port\n");
return (CMD_ERROR); return (CMD_ERROR);
} }
if (comc_port != port) if (comc_port != port)
comc_setup(comc_curspeed, port); comc_setup(comc_curspeed, port);
env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
return (CMD_OK); return (CMD_OK);
} }
/* /*
@ -320,46 +320,46 @@ comc_pcidev_set(struct env_var *ev, int flags, const void *value)
static void static void
comc_setup(int speed, int port) comc_setup(int speed, int port)
{ {
static int TRY_COUNT = 1000000; static int TRY_COUNT = 1000000;
char intbuf[64]; char intbuf[64];
int tries; int tries;
unsetenv("hw.uart.console"); unsetenv("hw.uart.console");
comc_curspeed = speed; comc_curspeed = speed;
comc_port = port; comc_port = port;
if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) == 0) if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) == 0)
return; return;
outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT); outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT);
outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff); outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff);
outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8); outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8);
outb(comc_port + com_cfcr, COMC_FMT); outb(comc_port + com_cfcr, COMC_FMT);
outb(comc_port + com_mcr, MCR_RTS | MCR_DTR); outb(comc_port + com_mcr, MCR_RTS | MCR_DTR);
tries = 0; tries = 0;
do do
inb(comc_port + com_data); inb(comc_port + com_data);
while (inb(comc_port + com_lsr) & LSR_RXRDY && ++tries < TRY_COUNT); while (inb(comc_port + com_lsr) & LSR_RXRDY && ++tries < TRY_COUNT);
if (tries < TRY_COUNT) { if (tries < TRY_COUNT) {
comconsole.c_flags |= (C_PRESENTIN | C_PRESENTOUT); comconsole.c_flags |= (C_PRESENTIN | C_PRESENTOUT);
sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed); sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed);
env_setenv("hw.uart.console", EV_VOLATILE, intbuf, NULL, NULL); env_setenv("hw.uart.console", EV_VOLATILE, intbuf, NULL, NULL);
} else } else
comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT); comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT);
} }
static int static int
comc_parseint(const char *speedstr) comc_parseint(const char *speedstr)
{ {
char *p; char *p;
int speed; int speed;
speed = strtol(speedstr, &p, 0); speed = strtol(speedstr, &p, 0);
if (p == speedstr || *p != '\0' || speed <= 0) if (p == speedstr || *p != '\0' || speed <= 0)
return (-1); return (-1);
return (speed); return (speed);
} }
static int static int