git: 501983e62e75 - main - loader.efi: Parse SPCR v3 and v4

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 11:14:07 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=501983e62e754d0b260c0dfe7f23042c89acd9f1

commit 501983e62e754d0b260c0dfe7f23042c89acd9f1
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-10-15 11:12:59 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-10-15 11:12:59 +0000

    loader.efi: Parse SPCR v3 and v4
    
    We can get the UART clock from v3 SPCR, and a precise baudrate from
    v4. Some precise baudrates will currently be rejected by the kernel.
    
    Sponsored by:           Netflix
    Reviewed by:            adrian, andrew
    Differential Revision:  https://reviews.freebsd.org/D47096
---
 stand/efi/loader/main.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index e8db72bf4c8a..0e2c580d1a8a 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -888,14 +888,24 @@ check_acpi_spcr(void)
 	db = 8;
 
 	/*
-	 * Note: We don't support SPCR Rev3 or Rev4 so use Rev2 values, if we
-	 * did we wouldn't have to do this weird dances with baud or xtal rates.
-	 * Rev 3 and 4 are too new to have seen any deployment, and aren't in
-	 * the system's actblX.h files yet. This will fail for newer high-speed
-	 * consoles until acpica catches up with Microsoft's new definitions.
+	 * UartClkFreq is 3 and newer. We always use it then (it's only valid if
+	 * it isn't 0, but if it is 0, we want to use 0 to have the kernel
+	 * guess).
 	 */
-	xo = 0;
-	br = acpi_uart_baud(spcr->BaudRate);
+	if (spcr->Header.Revision <= 2)
+		xo = 0;
+	else
+		xo = spcr->UartClkFreq;
+
+	/*
+	 * PreciseBaudrate, when non-zero, is to be preferred. It's only valid,
+	 * though, for rev 4 and newer. So when it's 0 or the version is too
+	 * old, we do the old-style table lookup. Otherwise we believe it.
+	 */
+	if (spcr->Header.Revision <= 3 || spcr->PreciseBaudrate == 0)
+		br = acpi_uart_baud(spcr->BaudRate);
+	else
+		br = spcr->PreciseBaudrate;
 
 	if (io != -1) {
 		asprintf(&val, "db:%d,dt:%s,io:%#x,pa:%s,br:%d,xo=%d",