From nobody Mon Oct 14 22:17:36 2024 X-Original-To: dev-commits-src-main@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 4XSBS05xzbz5ZG5C; Mon, 14 Oct 2024 22:17:36 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XSBS04634z3xLC; Mon, 14 Oct 2024 22:17:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728944256; 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=bDhlXS3rjx8mJATT0xhWYZfouBSGfdALGY101NUUISM=; b=GfCuieNDsJ0HWDfzvQ5m7mnPOZHjUL52jUrwV7CyJJUyfCDiottGE2wvvdJuHj3GAt3NAo oIdtSwyGlW3slgIOgW1+BoftIEbuCajF/AvyY1sdHYb5t31Er2i9Pzy0NYntez2dOy7I+f njQTzaP9B3Xo3SO+cSsEICO4GB+w3w3ZeDdOvYTJzcHFrPOQoNzpVmPbIce3bxx9ULmwJ6 tJu8q9MJT4CAN+9wUBVABC5kT378Okj7B2pJnoPJJvgoCWgjYUF8Blg1GuBUaZ35/JARVc ze/yHjQXYqh0npc0mO+0Sx8TWetREMY/L+wdW7AopU3J62oK96eFia6/gNdUaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728944256; 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=bDhlXS3rjx8mJATT0xhWYZfouBSGfdALGY101NUUISM=; b=Cn9aeaZiq5W6wloeKp36atY2SpucEy7iynutPe2u/O9Jj4oxXcFxKCUKKl1yZHK1H6x1yW pELfFGlvInUjbSriVtWTiSgy5naIy7ARJUHkiz8nKOwq7AvCaqfSQwQFwjDhn6XeKmHJrm AW6NZnD3kzdpg292nttIrsEOnIu3Hl5zoKuGw11FpUICgNtrZ/iSqsdbHld82uCa5jehu/ BXCrh/ohH85oDd/8g+cjZ1M5Nrhnp1fgCYJuT8y+grlDeZpnS3hvQT1PqtrnYftsftQNlG hqid9UGNjkWQO53rM1ZvsMmyUZuYF41WBXcyMGKqV8ukA6d1smyUne+d6RMMNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728944256; a=rsa-sha256; cv=none; b=MWJ2E1FXe/dieo+1uXUslUK++ieZRO4jN5e5c5CHVzdNPwr6ZFtSV1BSZHJhx+7SH1MhI1 bYX2SuQXidz2TuBjRxqBpEBCZm0LYXnCKjMzLkpfRjFcJ1tRgtLTl0qSDi/v7mjKXJEPMV EAfExcBhIwoFE/RahUinzAwpEoucYXhO8fehjyQ8l2kjzPXpZvDBDrPLFREt+7F2M4/RiD 9Sbeeen0rKY4IlcUa11+1Bgb5/v/7RCpHiQFxpfJnTf68q+wxz0i50gy1MKpPO7NAAoJK4 pVmOkG7jVGpq3I6QTPCn1XrKTKZtB8D4MjOViShHdfOBuzpolz+bogCTNOftBQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XSBS03jqhzwK2; Mon, 14 Oct 2024 22:17:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49EMHaCa074867; Mon, 14 Oct 2024 22:17:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49EMHa43074864; Mon, 14 Oct 2024 22:17:36 GMT (envelope-from git) Date: Mon, 14 Oct 2024 22:17:36 GMT Message-Id: <202410142217.49EMHa43074864@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 4097cd06ca49 - main - uart/ns8250: Factor out reading the divisor List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4097cd06ca49a4a212c25177007509838c7d04a9 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=4097cd06ca49a4a212c25177007509838c7d04a9 commit 4097cd06ca49a4a212c25177007509838c7d04a9 Author: Warner Losh AuthorDate: 2024-10-14 21:57:44 +0000 Commit: Warner Losh CommitDate: 2024-10-14 22:03:58 +0000 uart/ns8250: Factor out reading the divisor We have two copies (soon to be three) of reading the divisor. Since it's a complicated tricky process, abstract it to its own routine. Sponsored by: Netflix Reviewed by: andrew, markj Differential Revision: https://reviews.freebsd.org/D47074 --- sys/dev/uart/uart_dev_ns8250.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index 9f88a43f462a..d43a48f319e4 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -126,11 +126,11 @@ ns8250_clrint(struct uart_bas *bas) } } -static int -ns8250_delay(struct uart_bas *bas) +static uint32_t +ns8250_get_divisor(struct uart_bas *bas) { - int divisor; - u_char lcr; + uint32_t divisor; + uint8_t lcr; lcr = uart_getreg(bas, REG_LCR); uart_setreg(bas, REG_LCR, lcr | LCR_DLAB); @@ -140,6 +140,16 @@ ns8250_delay(struct uart_bas *bas) uart_setreg(bas, REG_LCR, lcr); uart_barrier(bas); + return (divisor); +} + +static int +ns8250_delay(struct uart_bas *bas) +{ + int divisor; + + divisor = ns8250_get_divisor(bas); + /* 1/10th the time to transmit 1 character (estimate). */ if (divisor <= 134) return (16000000 * divisor / bas->rclk); @@ -727,14 +737,7 @@ ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) uart_barrier(bas); break; case UART_IOCTL_BAUD: - lcr = uart_getreg(bas, REG_LCR); - uart_setreg(bas, REG_LCR, lcr | LCR_DLAB); - uart_barrier(bas); - divisor = uart_getreg(bas, REG_DLL) | - (uart_getreg(bas, REG_DLH) << 8); - uart_barrier(bas); - uart_setreg(bas, REG_LCR, lcr); - uart_barrier(bas); + divisor = ns8250_get_divisor(bas); baudrate = (divisor > 0) ? bas->rclk / divisor / 16 : 0; if (baudrate > 0) *(int*)data = baudrate;