From nobody Fri Nov 20 01:13:41 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jVy5f2XfMz71pbR for ; Fri, 20 Nov 2026 01:13:42 +0000 (UTC) (envelope-from git@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) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jVy5f0G8Mz4YFQ for ; Fri, 20 Nov 2026 01:13:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795137222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pGy0gWL97tk7nCSIzU/KxicqQ+nSIq64NuB9rpAoeIQ=; b=Rh26OGoK1DyTU4/iTp1Y/bMv2Y4ebMoV+rXKN5us5q8lN0oVQH6L/Rb/eREAwAKJwXLiy+ Btr8i0J98DaFAG2aNKoiXvPdogxVo0Jr45DX6DsmBNkHGcs1hlVeVZn+o/OF25I656A1jN pORw7p2WoUeQxIirCx80n3UdsdK3cEMwV0yuRHqdmOpMsPKomvWFwwoC2C2GYTOIdKbICz gGFNTzzcQmfuRd+LDf/9ciapC8cUHxo7LqwKWdLy8eOa1xnxdAq4tOm3EhkrXJtVy4kmfN B+RKMmLL2JhqxCJtso7Ffj8caKDEEUEImds4hqQnXwvblznVLUpderLIwZmZZw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795137222; b=PeWBd++E5HCNs+basnBfg85O1tRZNDdwXkjSJ6tjs5UhNUBfQeK6XSeH/yjy2HKGzbogYR mHQstHjOMBnYMyOKYKbIppUBdwx1toOm3E6UD4Fhf2mKnxxy5RZgkVaXDigMy81U/w8RkH r0VJposg59FgzD/zW8fYC637prObUrLrrBYsGvg620sffe44POhobutuWNHd2z1F14o2yE a9pQuApsLZA2zZz3IqFuBpQxzX3f2vq/UvOXzbCGjkGLhwuuo7JdXIjTYwOXL3XqfwFJTZ 55y4MzTAdvbtRj73N2Duco3DYgj76MA2FMJXP68BdQ7jUB5FQZn6Il81vcRfLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795137222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pGy0gWL97tk7nCSIzU/KxicqQ+nSIq64NuB9rpAoeIQ=; b=HSHLQ685gL0IJeOfCC5VMuyTbvGWLh+fXbc+2O238pEAFLydYOcw5ZxJc8GzjysIuSWiyW +/0zEHmPV/USMrGsEUIkkWTARCiHoRQLc4gHF2y+WrQGkPbUnXPSnKnfrHukJsJsRSL435 A32OKjuz9mKJr/XL0YvZaY88sKYJCuXoKMH1a5A7Z/Lg/q+RE68tvZG4/DbGKJWbtPuPiT 5RdmrJZJnrHl/Okgh41N9NduOyMWaYsn2I7mf5cevQr9MCwpoaCXUZ534KaS7GL8qsG/lu w+yFv1r28/el+FAAVRsYqoIIC9bcxsvEESA/d3GNtjks58IMPwS0vNPODz6mQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jVy5d6mnJzQ65 for ; Fri, 20 Nov 2026 01:13:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3cf by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 20 Nov 2026 01:13:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Hayzam Sherif Subject: git: 49bd38b00970 - main - uart: Let ns8250 drivers provide their own baud rate generator List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hayzam X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 49bd38b0097080f102896e5741b63467b05fccf8 Auto-Submitted: auto-generated Date: Fri, 20 Nov 2026 01:13:41 +0000 Message-Id: <6aff9ec5.3cf.33d43bbc@gitrepo.freebsd.org> The branch main has been updated by hayzam: URL: https://cgit.FreeBSD.org/src/commit/?id=49bd38b0097080f102896e5741b63467b05fccf8 commit 49bd38b0097080f102896e5741b63467b05fccf8 Author: Hayzam Sherif AuthorDate: 2026-11-16 12:41:46 +0000 Commit: Hayzam Sherif CommitDate: 2026-11-20 01:10:53 +0000 uart: Let ns8250 drivers provide their own baud rate generator Add set_baudrate, get_baudrate and get_divisor function pointers to struct ns8250_softc. A driver for a UART with a baud rate generator of its own sets them before calling ns8250_bus_attach(), which sets the ones left NULL to the 16550 functions. The param, ioctl, flush and transmit methods use them, and ns8250_delay(), ns8250_drain() and ns8250_flush() now take the softc to reach them. While probing, the softc is not yet an ns8250_softc, so ns8250_delay() uses the 16550 divisor when UART_BAS_IN_PROBE is set. The low-level console code, which has no softc, also uses the 16550 functions. No functional change for existing drivers. Reviewed by: mmel Approved by: markj (mentor) Sponsored by: Alchemilla Ventures Private Limited Differential Revision: https://reviews.freebsd.org/D61611 --- sys/dev/uart/uart_dev_ns8250.c | 60 +++++++++++++++++++++++++++++------------- sys/dev/uart/uart_dev_ns8250.h | 14 ++++++++++ 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index e00be7a187c6..fdc16fa30d77 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -190,11 +190,18 @@ ns8250_get_divisor(struct uart_bas *bas) } static int -ns8250_delay(struct uart_bas *bas) +ns8250_delay(struct ns8250_softc *ns8250) { + struct uart_bas *bas; uint32_t divisor; - divisor = ns8250_get_divisor(bas); + bas = &ns8250->base.sc_bas; + + /* While probing, the softc is not yet an ns8250_softc. */ + if ((bas->flags & UART_BAS_IN_PROBE) != 0) + divisor = ns8250_get_divisor(bas); + else + divisor = ns8250->get_divisor(bas); /* 1/10th the time to transmit 1 character (estimate): one bit. */ return ((uint64_t)divisor * (1000000 / NS8250_DIVISOR_SCALE) / @@ -258,11 +265,13 @@ ns8250_set_baudrate(struct uart_bas *bas, int baudrate) } static int -ns8250_drain(struct uart_bas *bas, int what) +ns8250_drain(struct ns8250_softc *ns8250, int what) { + struct uart_bas *bas; int delay, limit; - delay = ns8250_delay(bas); + bas = &ns8250->base.sc_bas; + delay = ns8250_delay(ns8250); if (what & UART_DRAIN_TRANSMITTER) { /* @@ -315,12 +324,14 @@ ns8250_drain(struct uart_bas *bas, int what) * drained. WARNING: this function clobbers the FIFO setting! */ static void -ns8250_flush(struct uart_bas *bas, int what) +ns8250_flush(struct ns8250_softc *ns8250, int what) { + struct uart_bas *bas; uint8_t fcr; uint8_t lsr; int drain = 0; + bas = &ns8250->base.sc_bas; fcr = FCR_ENABLE; if (what & UART_FLUSH_TRANSMITTER) fcr |= FCR_XMT_RST; @@ -343,13 +354,13 @@ ns8250_flush(struct uart_bas *bas, int what) drain |= UART_DRAIN_RECEIVER; if (drain != 0) { printf("uart: ns8250: UART FCR is broken (%#x)\n", drain); - ns8250_drain(bas, drain); + ns8250_drain(ns8250, drain); } } static int ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits, - int parity) + int parity, ns8250_set_baudrate_t *set_baudrate) { int error; uint8_t lcr; @@ -373,7 +384,7 @@ ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits, /* Set baudrate if we know a rclk and both are not 0. */ if (baudrate > 0 && bas->rclk > 0) { - error = ns8250_set_baudrate(bas, baudrate); + error = set_baudrate(bas, baudrate); if (error != 0) return (error); } @@ -463,7 +474,8 @@ ns8250_init(struct uart_bas *bas, int baudrate, int databits, int stopbits, if (bas->rclk == 0 && baudrate != 0) bas->rclk = DEFAULT_RCLK; - ns8250_param(bas, baudrate, databits, stopbits, parity); + ns8250_param(bas, baudrate, databits, stopbits, parity, + ns8250_set_baudrate); /* Disable the FIFO (if present). */ uart_setreg(bas, REG_FCR, 0); @@ -655,6 +667,13 @@ ns8250_bus_attach(struct uart_softc *sc) bas = &sc->sc_bas; + if (ns8250->set_baudrate == NULL) + ns8250->set_baudrate = ns8250_set_baudrate; + if (ns8250->get_baudrate == NULL) + ns8250->get_baudrate = ns8250_get_baudrate; + if (ns8250->get_divisor == NULL) + ns8250->get_divisor = ns8250_get_divisor; + ns8250->busy_detect = bas->busy_detect; ns8250->mcr = uart_getreg(bas, REG_MCR); ns8250->fcr = FCR_ENABLE; @@ -746,12 +765,12 @@ ns8250_bus_flush(struct uart_softc *sc, int what) bas = &sc->sc_bas; uart_lock(sc->sc_hwmtx); if (sc->sc_rxfifosz > 1) { - ns8250_flush(bas, what); + ns8250_flush(ns8250, what); uart_setreg(bas, REG_FCR, ns8250->fcr); uart_barrier(bas); error = 0; } else - error = ns8250_drain(bas, what); + error = ns8250_drain(ns8250, what); uart_unlock(sc->sc_hwmtx); return (error); } @@ -796,6 +815,7 @@ ns8250_bus_getsig(struct uart_softc *sc) int ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) { + struct ns8250_softc *ns8250 = (struct ns8250_softc *)sc; struct uart_bas *bas; int baudrate, error; uint8_t efr, lcr; @@ -844,7 +864,7 @@ ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) uart_barrier(bas); break; case UART_IOCTL_BAUD: - baudrate = ns8250_get_baudrate(bas); + baudrate = ns8250->get_baudrate(bas); if (baudrate > 0) *(int*)data = baudrate; else @@ -937,7 +957,8 @@ ns8250_bus_param(struct uart_softc *sc, int baudrate, int databits, } } - error = ns8250_param(bas, baudrate, databits, stopbits, parity); + error = ns8250_param(bas, baudrate, databits, stopbits, parity, + ns8250->set_baudrate); uart_unlock(sc->sc_hwmtx); return (error); } @@ -945,6 +966,8 @@ ns8250_bus_param(struct uart_softc *sc, int baudrate, int databits, int ns8250_bus_probe(struct uart_softc *sc) { + /* Not an ns8250_softc yet; the helpers check UART_BAS_IN_PROBE. */ + struct ns8250_softc *ns8250 = (struct ns8250_softc *)sc; struct uart_bas *bas; int count, delay, error, limit; uint8_t lsr, mcr, ier; @@ -962,7 +985,7 @@ ns8250_bus_probe(struct uart_softc *sc) } else mcr |= MCR_DTR | MCR_RTS; - error = ns8250_drain(bas, UART_DRAIN_TRANSMITTER); + error = ns8250_drain(ns8250, UART_DRAIN_TRANSMITTER); if (error) return (error); @@ -998,10 +1021,11 @@ ns8250_bus_probe(struct uart_softc *sc) uart_barrier(bas); count = 0; - delay = ns8250_delay(bas); + delay = ns8250_delay(ns8250); /* We have FIFOs. Drain the transmitter and receiver. */ - error = ns8250_drain(bas, UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER); + error = ns8250_drain(ns8250, + UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER); if (error) { uart_setreg(bas, REG_MCR, mcr); uart_setreg(bas, REG_FCR, 0); @@ -1055,7 +1079,7 @@ ns8250_bus_probe(struct uart_softc *sc) uart_setreg(bas, REG_MCR, mcr); /* Reset FIFOs. */ - ns8250_flush(bas, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER); + ns8250_flush(ns8250, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER); describe: if (count >= 14 && count <= 16) { @@ -1198,7 +1222,7 @@ ns8250_bus_transmit(struct uart_softc *sc) uart_setreg(bas, REG_IER, ns8250->ier); uart_barrier(bas); if (broken_txfifo) - ns8250_drain(bas, UART_DRAIN_TRANSMITTER); + ns8250_drain(ns8250, UART_DRAIN_TRANSMITTER); else sc->sc_txbusy = 1; uart_unlock(sc->sc_hwmtx); diff --git a/sys/dev/uart/uart_dev_ns8250.h b/sys/dev/uart/uart_dev_ns8250.h index 5f4399282930..67403c29074d 100644 --- a/sys/dev/uart/uart_dev_ns8250.h +++ b/sys/dev/uart/uart_dev_ns8250.h @@ -35,6 +35,10 @@ */ #define NS8250_DIVISOR_SCALE 100 +typedef int ns8250_set_baudrate_t(struct uart_bas *, int); +typedef int ns8250_get_baudrate_t(struct uart_bas *); +typedef uint32_t ns8250_get_divisor_t(struct uart_bas *); + /* * High-level UART interface. */ @@ -48,6 +52,16 @@ struct ns8250_softc { uint8_t ier_rxbits; uint8_t busy_detect; int noise_count; + + /* + * The baud rate generator. A UART with a generator of its own sets + * these before ns8250_bus_attach(), which sets the ones left NULL to + * the 16550 versions. set_baudrate() must change nothing if it + * fails. get_baudrate() and get_divisor() must agree. + */ + ns8250_set_baudrate_t *set_baudrate; + ns8250_get_baudrate_t *get_baudrate; + ns8250_get_divisor_t *get_divisor; }; extern struct uart_ops uart_ns8250_ops;