From nobody Mon Oct 14 22:17:34 2024 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 4XSBRz12Psz5ZFtl; Mon, 14 Oct 2024 22:17:35 +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 4XSBRy3sRNz3xRK; Mon, 14 Oct 2024 22:17:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728944254; 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=CooC9QO4VpLSd2ZxMc+GiZoLE6hHSolROUHNzYHSozE=; b=ruhGkWDMbeQSiTPNIdFihQm1EuO5aVjV8CPiEOG84i/xcnmO2N5EDJaCXy9LsWTwMoGlkd /622F0T1pOPeI2o956P7Kn8ukj7xuTWL92z9B/fjpFZOerOcueEQF2bZHW0Aa2mImRO0D/ VF36RRIFWsOgie5IV5fNm8+aAMwQ49oAe8tT5G+Wl3akkvqCaE7nNLD8E5P2/R56RvV/G+ nNhFaMC2PmEVsM3EN5j5kwobzuWea7dWqNnn+wsV91AQEft7SQU/AUpo6+IbzLJcPVCK3A KQpBv8zbFcmuyka02HM2hk7Z0QEDBw2XJn+QW9XQ83lqKeodbSDgAkW5V1Lc1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728944254; 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=CooC9QO4VpLSd2ZxMc+GiZoLE6hHSolROUHNzYHSozE=; b=JEdCWjBdc++HelMVahVGDbxD9w0NjZWDuksXx6+ux2mdQqNwzOzKjXg0z6NhK6CyOPw+II nLcDkwppUHEo6NIhA29SUUAkLmHMoPp7qSkkzkVHF/3TYjiPRqs/x8UsQLvbHiF+1FovSh wpaPPfBKv0uWklbwvzsSEBTbxkenT8iZaSgSeO/gOP0PT5jKj5+FCY/taJqo5Qv+0yzbf8 rLXNK+5VBHdBYWc3ksajvQ9HL8W7DT2T0a6JhuY0ofr5yr2BATPyOhcc7QBYYn/Mby+N/I rkGxjAkNDuGEGKFieBfxneJZzT7puVjuUJhOiNYEM4ZsHGcKScrcwTF63o1MTQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728944254; a=rsa-sha256; cv=none; b=cLPXpU/OYE4ShbsFcdYBGEirfnA0M7Ccf++AEJY5zv0d9MErDj6bBNQDrrq5OC6V7iKtDr rEvIQkkL71PyvNJV54X/LKKZuSNcuqBE57V5Z5ODOqUdYAwa8EwtT9XCkRzxInFkmQUJVN 6HYugnPyxtLwWdQS79+QMqk3i+rC351RkqF12GmBj7jIskV88cMtQXn2I2lc6IsKXd2MlA LAlIcJYWf6acWikqUZFunoc3YUPhfkxfkejnlNS/ojbdtvIgtboXkX7ZflO1QgmUxj8xyC 3KxgJsrWPuT/6y+guyJgIdbkNYLr9LdbCkiHhRYVPWzY335bTzjT2l4yVTKPlg== 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 4XSBRy1yrWzwBC; Mon, 14 Oct 2024 22:17:34 +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 49EMHYcx074765; Mon, 14 Oct 2024 22:17:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49EMHYJm074762; Mon, 14 Oct 2024 22:17:34 GMT (envelope-from git) Date: Mon, 14 Oct 2024 22:17:34 GMT Message-Id: <202410142217.49EMHYJm074762@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: b2fd259edd18 - main - uart: Add a signal to compute rclk from baudrate List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: b2fd259edd18af1fe35912bdb602bbe907dbbbcb Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b2fd259edd18af1fe35912bdb602bbe907dbbbcb commit b2fd259edd18af1fe35912bdb602bbe907dbbbcb Author: Warner Losh AuthorDate: 2024-10-14 21:57:25 +0000 Commit: Warner Losh CommitDate: 2024-10-14 22:03:58 +0000 uart: Add a signal to compute rclk from baudrate With newer, more diverse hardware designs, the rclk can be unknown. Currently deployed systems have no standard way to discover the baud-clock generator frequency. However, sometimes we have a fairly good idea that the firmware programmed the UART to be the baud rate that it's telling us it's at. Create a way to instruct the uart class drivers to compute the baud clock frequency the first time their init routines are called. Usually the 'divisors' are relatively small, meaning we will likely have a fairly large error (goes as 1 / (divisor + 1). However, we also know that the baud-generator clock needs to be divided down to the baud-rate +/- about 5% (so while the error could be large for an arbitrary baud-clock, standard baud rates generally will give an error of 5% or less). Often, the console speed and the getty-configured speed are the same, so this heuristic allows boot messages and login sessions to work. Sponsored by: Netflix Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D47072 --- sys/dev/uart/uart.h | 1 + sys/dev/uart/uart_cpu_acpi.c | 8 ++++++++ sys/dev/uart/uart_subr.c | 2 ++ 3 files changed, 11 insertions(+) diff --git a/sys/dev/uart/uart.h b/sys/dev/uart/uart.h index 4cdec00c9829..9b80f0148dc2 100644 --- a/sys/dev/uart/uart.h +++ b/sys/dev/uart/uart.h @@ -45,6 +45,7 @@ struct uart_bas { u_int regshft; u_int regiowidth; u_int busy_detect; + u_int rclk_guess;/* if rclk == 0, use baud + divisor to compute rclk */ }; #define uart_regofs(bas, reg) ((reg) << (bas)->regshft) diff --git a/sys/dev/uart/uart_cpu_acpi.c b/sys/dev/uart/uart_cpu_acpi.c index ae22a9822aa6..816738ec31d5 100644 --- a/sys/dev/uart/uart_cpu_acpi.c +++ b/sys/dev/uart/uart_cpu_acpi.c @@ -189,6 +189,14 @@ uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di) (int)spcr->BaudRate); goto out; } + /* + * If no rclk is set, then we will assume the BIOS has configured the + * hardware at the stated baudrate, so we can use it to guess the rclk + * relatively accurately, so make a note for later. + */ + if (di->bas.rclk == 0) + di->bas.rclk_guess = 1; + if (spcr->PciVendorId != PCIV_INVALID && spcr->PciDeviceId != PCIV_INVALID) { di->pci_info.vendor = spcr->PciVendorId; diff --git a/sys/dev/uart/uart_subr.c b/sys/dev/uart/uart_subr.c index 49a046f019bb..070ae80d9aff 100644 --- a/sys/dev/uart/uart_subr.c +++ b/sys/dev/uart/uart_subr.c @@ -279,6 +279,8 @@ uart_getenv(int devtype, struct uart_devinfo *di, struct uart_class *class) break; case UART_TAG_XO: di->bas.rclk = uart_parse_long(&spec); + if (di->bas.rclk == 0) + di->bas.rclk_guess = 1; break; default: goto inval;