From owner-svn-src-all@freebsd.org Fri Jun 29 19:35:26 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 00011F76A0B; Fri, 29 Jun 2018 19:35:25 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9F3C67838B; Fri, 29 Jun 2018 19:35:25 +0000 (UTC) (envelope-from jhibbits@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 7B9B1252D6; Fri, 29 Jun 2018 19:35:25 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5TJZPlq072829; Fri, 29 Jun 2018 19:35:25 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5TJZPjV072828; Fri, 29 Jun 2018 19:35:25 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201806291935.w5TJZPjV072828@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Fri, 29 Jun 2018 19:35:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335801 - head/sys/powerpc/powernv X-SVN-Group: head X-SVN-Commit-Author: jhibbits X-SVN-Commit-Paths: head/sys/powerpc/powernv X-SVN-Commit-Revision: 335801 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.26 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: Fri, 29 Jun 2018 19:35:26 -0000 Author: jhibbits Date: Fri Jun 29 19:35:25 2018 New Revision: 335801 URL: https://svnweb.freebsd.org/changeset/base/335801 Log: Support multiple OPAL consoles, and don't crash if uart is not stdout Summary: If the chosen console is not the OPAL uart, but OPAL uart devices exist, the console device doesn't attach properly, and faults in the interrupt handler, with a NULL pointer dereference. To fix this, and as a byproduct, also support multiple OPAL consoles, refactor to have the console getc callback use the appropriate softc instead of the global console_sc, which may be NULL in the case of a different device being the console. Reviewed by: nwhitehorn Differential Revision: https://reviews.freebsd.org/D16071 Modified: head/sys/powerpc/powernv/opal_console.c Modified: head/sys/powerpc/powernv/opal_console.c ============================================================================== --- head/sys/powerpc/powernv/opal_console.c Fri Jun 29 18:45:29 2018 (r335800) +++ head/sys/powerpc/powernv/opal_console.c Fri Jun 29 19:35:25 2018 (r335801) @@ -70,14 +70,14 @@ struct uart_opal_softc { char opal_inbuf[16]; uint64_t inbuflen; uint8_t outseqno; +#if defined(KDB) + int alt_break_state; +#endif }; static struct uart_opal_softc *console_sc = NULL; +static struct consdev *stdout_cp; -#if defined(KDB) -static int alt_break_state; -#endif - enum { OPAL_RAW, OPAL_HVSI }; @@ -112,6 +112,7 @@ static driver_t uart_opal_driver = { DRIVER_MODULE(uart_opal, opalcons, uart_opal_driver, uart_devclass, 0, 0); +static int uart_opal_getc(struct uart_opal_softc *sc); static cn_probe_t uart_opal_cnprobe; static cn_init_t uart_opal_cninit; static cn_term_t uart_opal_cnterm; @@ -248,6 +249,8 @@ uart_opal_cnprobe(struct consdev *cp) cp->cn_pri = CN_NORMAL; console_sc = ≻ + cp->cn_arg = console_sc; + stdout_cp = cp; return; fail: @@ -262,23 +265,25 @@ uart_opal_attach(device_t dev) int unit; sc = device_get_softc(dev); - sc->dev = dev; sc->node = ofw_bus_get_node(dev); uart_opal_probe_node(sc); unit = device_get_unit(dev); - sc->tp = tty_alloc(&uart_opal_tty_class, sc); mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_SPIN | MTX_QUIET | MTX_NOWITNESS); if (console_sc != NULL && console_sc->vtermid == sc->vtermid) { device_printf(dev, "console\n"); - sc->outseqno = console_sc->outseqno; - console_sc = sc; + device_set_softc(dev, console_sc); + sc = console_sc; sprintf(uart_opal_consdev.cn_name, "ttyu%r", unit); - tty_init_console(sc->tp, 0); } + sc->tp = tty_alloc(&uart_opal_tty_class, sc); + if (console_sc == sc) + tty_init_console(sc->tp, 0); + + sc->dev = dev; sc->irqrid = 0; sc->irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqrid, RF_ACTIVE | RF_SHAREABLE); @@ -419,14 +424,20 @@ uart_opal_put(struct uart_opal_softc *sc, void *buffer static int uart_opal_cngetc(struct consdev *cp) { + return (uart_opal_getc(cp->cn_arg)); +} + +static int +uart_opal_getc(struct uart_opal_softc *sc) +{ unsigned char c; int retval; - retval = uart_opal_get(console_sc, &c, 1); + retval = uart_opal_get(sc, &c, 1); if (retval != 1) return (-1); #if defined(KDB) - kdb_alt_break(c, &alt_break_state); + kdb_alt_break(c, &sc->alt_break_state); #endif return (c); @@ -444,7 +455,7 @@ uart_opal_cnputc(struct consdev *cp, int c) opal_call(OPAL_POLL_EVENTS, NULL); } } - uart_opal_put(console_sc, &ch, 1); + uart_opal_put(cp->cn_arg, &ch, 1); } static void @@ -478,7 +489,7 @@ uart_opal_intr(void *v) int c; tty_lock(tp); - while ((c = uart_opal_cngetc(NULL)) > 0) + while ((c = uart_opal_getc(sc)) > 0) ttydisc_rint(tp, c, 0); ttydisc_rint_done(tp); tty_unlock(tp);