From nobody Mon Oct 14 22:17:38 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 4XSBS31vWwz5ZG77; Mon, 14 Oct 2024 22:17:39 +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 4XSBS26WdDz3xQ2; Mon, 14 Oct 2024 22:17:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728944258; 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=oqI96qoy0Uf/W+5Ko5pDKhp3Py5KpqbYJ1qT2tUB/LY=; b=eMPYyBf54aWe6FQLoIndXO0CiO0dDDejSln/qhNot+ncTO4UTFE506ICPgqmu1EEaTI0lr AOYw99TPnc/KgClrbH8OKREIkwXzn06fiE/KHAFxUW4h4R1VdQwzaflwBeBp2Stq8aU7Xn 9K73J5ESaKck/4Y6xZvzrMvdQQjhX+kgsApCn09l54XS99k1SV8uEpj6yvgkE/7baxsFLr 7hsoVQ1HUPMIISoX8JlK/GYpkKBmjBu1dH0wvJMvNT4jJPQ47s11ME3b1BxcgXOmeInN8+ RYZrXQPmZuiMog+PKeJQzQoiWkVDixshLmveL5pmXVz66/6Y3fGdBKLDGsHTvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728944258; 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=oqI96qoy0Uf/W+5Ko5pDKhp3Py5KpqbYJ1qT2tUB/LY=; b=NQ7wh4ZGQxPusS61mHg6ZplkvKqWFMFttumdEzD4iZLMXuYEYBE58WGwPXugV7/awe5gOV Rfne55Dn/ughZmDD5igVdnH5g686k16zRuaHJFX9beWlTbGnHxR/1Li9NK0SJt+ToLee15 MSAV4/0xdO+hVdxrrQIAZJ6rX5unHBDE26ceQI5Z8yFeTodhU3uGSqKaW26VRNfsZTzImx jbZHNw+KRcLP3LMT19MBvXA8zwMKtU5QmWOK0e29QCx5DmFcIoiH5u6fGgd+oW8bUuensM kIp/6+snYon7YjDexUAvex7VFQW4NtyPYPO1Npkjq0TyXkC1RJXXAKraDhuK7g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728944258; a=rsa-sha256; cv=none; b=T2jf9FBDHrxG7CCc+xIGnEp9mWAw8x63JWJrUL9VmCWHtSTSzpqMNsVqbzVLVXVp5f1dWf xz5dSHOEWGiISgZOuNMuTzxLT3AEJu4Euq0kBixgVAkFk4YReV45Dvc/6F1qiH0KS/0gTQ c2RaVBg/ZCMsdQoB66XIg4wKCWQf1UkPyaGgD3jbMiUF0qBohKfksEB9P4n+YIWgD+YDLb JrDSK+/3MRDYrOZTStr1DEA6vB7nMziQuhWE2F9HLPwOPMJrAAp98zRLHNCGo2sah64B0i T9+JSl9ZghnJcpbCj5qkxOqWWT775j8UH0fA14FfF7KOXvBmlxnVHJJ6KJi0Bg== 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 4XSBS25g1CzwBD; Mon, 14 Oct 2024 22:17:38 +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 49EMHcFB074960; Mon, 14 Oct 2024 22:17:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49EMHc5a074957; Mon, 14 Oct 2024 22:17:38 GMT (envelope-from git) Date: Mon, 14 Oct 2024 22:17:38 GMT Message-Id: <202410142217.49EMHc5a074957@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: 8190dfbb1d58 - main - uart/ns8250: Add support for computing rclk 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: 8190dfbb1d58a1c52f73992d84ae00c4fff35890 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=8190dfbb1d58a1c52f73992d84ae00c4fff35890 commit 8190dfbb1d58a1c52f73992d84ae00c4fff35890 Author: Warner Losh AuthorDate: 2024-10-14 21:58:01 +0000 Commit: Warner Losh CommitDate: 2024-10-14 22:03:59 +0000 uart/ns8250: Add support for computing rclk When instructed to do so, compute the rclk (baud rate generator clock) based on the currently programmed divisor and the communicated baud rate. We only do this once and only for consoles that tell us the configured rate and flag we can likely safely compute rclk. Sponsored by: Netflix Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D47076 --- sys/dev/uart/uart_dev_ns8250.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index f59f5fa80e9c..3da2e8b8c758 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -294,8 +294,8 @@ ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits, lcr |= LCR_STOPB; lcr |= parity << 3; - /* Set baudrate. */ - if (baudrate > 0) { + /* Set baudrate if we know a rclk and both are not 0. */ + if (baudrate > 0 && bas->rclk > 0) { divisor = ns8250_divisor(bas->rclk, baudrate); if (divisor == 0) return (EINVAL); @@ -369,8 +369,28 @@ ns8250_init(struct uart_bas *bas, int baudrate, int databits, int stopbits, uart_setreg(bas, REG_IER, ier); uart_barrier(bas); - if (bas->rclk == 0) + /* + * Loader tells us to infer the rclk when it sets xo to 0 in + * hw.uart.console. We know the baudrate was set by the firmware, so + * calculate rclk from baudrate and the divisor register. If 'div' is + * actually 0, the resulting 0 value will have us fall back to other + * rclk methods. + */ + if (bas->rclk_guess && bas->rclk == 0 && baudrate != 0) { + uint32_t div; + + div = ns8250_get_divisor(bas); + bas->rclk = baudrate * div * 16; + } + + /* + * Pick a default because we just don't know. This likely needs future + * refinement, but that's hard outside of consoles to know what to use. + * But defer as long as possible if there's no defined baud rate. + */ + if (bas->rclk == 0 && baudrate != 0) bas->rclk = DEFAULT_RCLK; + ns8250_param(bas, baudrate, databits, stopbits, parity); /* Disable the FIFO (if present). */