From owner-svn-src-all@freebsd.org Thu Mar 19 16:51:58 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EFFDC264411; Thu, 19 Mar 2020 16:51:58 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48jtH25DB3z45dC; Thu, 19 Mar 2020 16:51:58 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9512CE0D5; Thu, 19 Mar 2020 16:51:58 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02JGpwAE029637; Thu, 19 Mar 2020 16:51:58 GMT (envelope-from tsoome@FreeBSD.org) Received: (from tsoome@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02JGpwea029635; Thu, 19 Mar 2020 16:51:58 GMT (envelope-from tsoome@FreeBSD.org) Message-Id: <202003191651.02JGpwea029635@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tsoome set sender to tsoome@FreeBSD.org using -f From: Toomas Soome Date: Thu, 19 Mar 2020 16:51:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r359143 - in stable/12/stand: efi/loader i386/libi386 X-SVN-Group: stable-12 X-SVN-Commit-Author: tsoome X-SVN-Commit-Paths: in stable/12/stand: efi/loader i386/libi386 X-SVN-Commit-Revision: 359143 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2020 16:51:59 -0000 Author: tsoome Date: Thu Mar 19 16:51:57 2020 New Revision: 359143 URL: https://svnweb.freebsd.org/changeset/base/359143 Log: MFC r354240, r354252, r358906 libi386/comconsole.c updates: We don't support configuring serial PCI cards in EFI. Make this clearer in the source rather than obfuscaring it behind NO_PCI (nothing else declares that, so it's not making the ifdefs clearer). libi386/comconsole.c cstyle cleanup test if port does exist via using scratch register Modified: stable/12/stand/efi/loader/Makefile stable/12/stand/i386/libi386/comconsole.c Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/efi/loader/Makefile ============================================================================== --- stable/12/stand/efi/loader/Makefile Thu Mar 19 16:51:33 2020 (r359142) +++ stable/12/stand/efi/loader/Makefile Thu Mar 19 16:51:57 2020 (r359143) @@ -55,7 +55,7 @@ CFLAGS+= -I${EFISRC}/include CFLAGS+= -I${EFISRC}/include/${MACHINE} CFLAGS+= -I${SYSDIR}/contrib/dev/acpica/include CFLAGS+= -I${BOOTSRC}/i386/libi386 -CFLAGS+= -DNO_PCI -DEFI +CFLAGS+= -DEFI .if !defined(BOOT_HIDE_SERIAL_NUMBERS) # Export serial numbers, UUID, and asset tag from loader. Modified: stable/12/stand/i386/libi386/comconsole.c ============================================================================== --- stable/12/stand/i386/libi386/comconsole.c Thu Mar 19 16:51:33 2020 (r359142) +++ stable/12/stand/i386/libi386/comconsole.c Thu Mar 19 16:51:57 2020 (r359143) @@ -67,144 +67,144 @@ static int comc_port = COMPORT; static uint32_t comc_locator; struct console comconsole = { - "comconsole", - "serial port", - 0, - comc_probe, - comc_init, - comc_putchar, - comc_getchar, - comc_ischar + .c_name = "comconsole", + .c_desc = "serial port", + .c_flags = 0, + .c_probe = comc_probe, + .c_init = comc_init, + .c_out = comc_putchar, + .c_in = comc_getchar, + .c_ready = comc_ischar }; static void comc_probe(struct console *cp) { - char intbuf[16]; - char *cons, *env; - int speed, port; - uint32_t locator; + char intbuf[16]; + char *cons, *env; + int speed, port; + uint32_t locator; - if (comc_curspeed == 0) { - comc_curspeed = COMSPEED; - /* - * Assume that the speed was set by an earlier boot loader if - * comconsole is already the preferred console. - */ - cons = getenv("console"); - if ((cons != NULL && strcmp(cons, comconsole.c_name) == 0) || - getenv("boot_multicons") != NULL) { - comc_curspeed = comc_getspeed(); - } + if (comc_curspeed == 0) { + comc_curspeed = COMSPEED; + /* + * Assume that the speed was set by an earlier boot loader if + * comconsole is already the preferred console. + */ + cons = getenv("console"); + if ((cons != NULL && strcmp(cons, comconsole.c_name) == 0) || + getenv("boot_multicons") != NULL) { + comc_curspeed = comc_getspeed(); + } - env = getenv("comconsole_speed"); - if (env != NULL) { - speed = comc_parseint(env); - if (speed > 0) - comc_curspeed = speed; - } + 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); + 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; - } + 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); + 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); - } + 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); + unsetenv("comconsole_pcidev"); + env_setenv("comconsole_pcidev", EV_VOLATILE, env, + comc_pcidev_set, env_nounset); + } + comc_setup(comc_curspeed, comc_port); } static int comc_init(int arg) { - comc_setup(comc_curspeed, comc_port); + comc_setup(comc_curspeed, comc_port); - if ((comconsole.c_flags & (C_PRESENTIN | C_PRESENTOUT)) == - (C_PRESENTIN | C_PRESENTOUT)) - return (CMD_OK); - return (CMD_ERROR); + if ((comconsole.c_flags & (C_PRESENTIN | C_PRESENTOUT)) == + (C_PRESENTIN | C_PRESENTOUT)) + return (CMD_OK); + return (CMD_ERROR); } static void comc_putchar(int c) { - int wait; + int wait; - for (wait = COMC_TXWAIT; wait > 0; wait--) - if (inb(comc_port + com_lsr) & LSR_TXRDY) { - outb(comc_port + com_data, (u_char)c); - break; - } + for (wait = COMC_TXWAIT; wait > 0; wait--) + if (inb(comc_port + com_lsr) & LSR_TXRDY) { + outb(comc_port + com_data, (u_char)c); + break; + } } static int comc_getchar(void) { - return (comc_ischar() ? inb(comc_port + com_data) : -1); + return (comc_ischar() ? inb(comc_port + com_data) : -1); } static int comc_ischar(void) { - return (inb(comc_port + com_lsr) & LSR_RXRDY); + return (inb(comc_port + com_lsr) & LSR_RXRDY); } static int comc_speed_set(struct env_var *ev, int flags, const void *value) { - int speed; + int speed; - if (value == NULL || (speed = comc_parseint(value)) <= 0) { - printf("Invalid speed\n"); - return (CMD_ERROR); - } + if (value == NULL || (speed = comc_parseint(value)) <= 0) { + printf("Invalid speed\n"); + return (CMD_ERROR); + } - if (comc_curspeed != speed) - comc_setup(speed, comc_port); + if (comc_curspeed != speed) + 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 comc_port_set(struct env_var *ev, int flags, const void *value) { - int port; + int port; - if (value == NULL || (port = comc_parseint(value)) <= 0) { - printf("Invalid port\n"); - return (CMD_ERROR); - } + if (value == NULL || (port = comc_parseint(value)) <= 0) { + printf("Invalid port\n"); + return (CMD_ERROR); + } - if (comc_port != port) - comc_setup(comc_curspeed, port); + if (comc_port != 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); } /* @@ -214,7 +214,8 @@ comc_port_set(struct env_var *ev, int flags, const voi static uint32_t comc_parse_pcidev(const char *string) { -#ifdef NO_PCI +#ifdef EFI + /* We don't support PCI in EFI yet */ return (0); #else char *p, *p1; @@ -256,7 +257,8 @@ comc_parse_pcidev(const char *string) static int comc_pcidev_handle(uint32_t locator) { -#ifdef NO_PCI +#ifdef EFI + /* We don't support PCI in EFI yet */ return (CMD_ERROR); #else char intbuf[64]; @@ -318,46 +320,56 @@ comc_pcidev_set(struct env_var *ev, int flags, const v static void comc_setup(int speed, int port) { - static int TRY_COUNT = 1000000; - char intbuf[64]; - int tries; + static int TRY_COUNT = 1000000; + char intbuf[64]; + int tries; - unsetenv("hw.uart.console"); - comc_curspeed = speed; - comc_port = port; - if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) == 0) - return; + unsetenv("hw.uart.console"); + comc_curspeed = speed; + comc_port = port; + if ((comconsole.c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) == 0) + return; - outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT); - outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff); - outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8); - outb(comc_port + com_cfcr, COMC_FMT); - outb(comc_port + com_mcr, MCR_RTS | MCR_DTR); +#define COMC_TEST 0xbb + /* + * Write byte to scratch register and read it out. + */ + outb(comc_port + com_scr, COMC_TEST); + if (inb(comc_port + com_scr) != COMC_TEST) { + comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT); + return; + } - tries = 0; - do - inb(comc_port + com_data); - while (inb(comc_port + com_lsr) & LSR_RXRDY && ++tries < TRY_COUNT); + outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT); + outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff); + outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8); + outb(comc_port + com_cfcr, COMC_FMT); + outb(comc_port + com_mcr, MCR_RTS | MCR_DTR); - if (tries < TRY_COUNT) { - comconsole.c_flags |= (C_PRESENTIN | C_PRESENTOUT); - sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed); - env_setenv("hw.uart.console", EV_VOLATILE, intbuf, NULL, NULL); - } else - comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT); + tries = 0; + do + inb(comc_port + com_data); + while (inb(comc_port + com_lsr) & LSR_RXRDY && ++tries < TRY_COUNT); + + if (tries < TRY_COUNT) { + comconsole.c_flags |= (C_PRESENTIN | C_PRESENTOUT); + sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed); + env_setenv("hw.uart.console", EV_VOLATILE, intbuf, NULL, NULL); + } else + comconsole.c_flags &= ~(C_PRESENTIN | C_PRESENTOUT); } static int comc_parseint(const char *speedstr) { - char *p; - int speed; + char *p; + int speed; - speed = strtol(speedstr, &p, 0); - if (p == speedstr || *p != '\0' || speed <= 0) - return (-1); + speed = strtol(speedstr, &p, 0); + if (p == speedstr || *p != '\0' || speed <= 0) + return (-1); - return (speed); + return (speed); } static int