From nobody Fri Oct 04 00:01:54 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 4XKTHQ2dxRz5XXTX; Fri, 04 Oct 2024 00:01:54 +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 4XKTHQ1Qcgz4V48; Fri, 4 Oct 2024 00:01:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728000114; 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=F/xDKyVYvmw6/XstVgt2ned1oL98pXGO3OkAqLNLEGY=; b=nbvy9QauIoWkmzrv4mpSuabnWgv+SMLFJYMt6P8+/2xpdF7juEl7msRzQiXUiBpVMTa+Hb OA0Pnyi575AalIgj8tSHycx0WM1+49+r5SW760LY9u75Fc5Be5g+sJ3eYB7WAW3ZJeEMhV xZpiggrHgsX1ZzTVOqZA3nyzqFmWhPYZ1ZzldY9fxEp3yTkq/Rttm1eGY58m8tu7n8xGN2 gmtSTJbrqq2TF1uq5u2scMT4UpzFcHLNgqny+v6T5WeSxrNGGaisxYFJNfo3NSGbIgUSV9 i1j6H3vmhltWIobKSesNTAqrRn4hki8615lKetumPi00BLLL1IFlUE+irFnqOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728000114; 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=F/xDKyVYvmw6/XstVgt2ned1oL98pXGO3OkAqLNLEGY=; b=xNJ98z5go08kfH/PrIgbisBTQ8BUIjuTgtGWIxbrKwhWhbFbqjZXcyIYaMa3Q/fW1jhWUG bJceyNlvJDWW6XfvyS3TekIplWOwHK5Co4XFDXbWron9HJjCOZp3YSbYa4MwAa7JmW2/fP sc6bjYLuOJi3g5cz/stCb7RwQ88/tS8vv5rm77FTJaEwJCMGTpgQqKVHwWoC8bVbtVLaO1 m6jerQupwgILVl7IioGDH/rVEHq/ToQjIfzjfjPNrYhkBef5r3kx2nEO+Df8vjFhvwM9Vj 2hmMd/VvceyRkSB9zf40HeuBYSZ/Rp35eD4RH2dccY0uUvWneEDWUgmn/ia1Sg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728000114; a=rsa-sha256; cv=none; b=mJIW/AHpMnNomxDkdgizCsX0A+RKaJD11YmfH351vit2D2PQRIqH9GfmMAz5kA2gJlAJGZ oyzqrXuWTzofsdJtEcPgRCjNhvJecWSnqSyvD3E+ZeFXTEnuui4q+eYZb8Kgm2USg6ascO BEtWIH0QguXML+oBevClqtaWFRRpMy0HZ/sgMlQrBTIC9wZPGq04l0twySVI9BsqweIfqF +Y/CsK7aIH/fXI/PYnqNyDwAM1YYu0FlySewPy3V2kBmlb2Ev+RRlof1eJtwWqyD7tBRbF PtROWN9RqLkfC8Y4/WxUJMmuXX55bXGRtGzu/8OShr1UfoeApTQvCM4irxn7tA== 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 4XKTHQ11wPz1BML; Fri, 4 Oct 2024 00:01:54 +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 49401sZd039591; Fri, 4 Oct 2024 00:01:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49401sBs039588; Fri, 4 Oct 2024 00:01:54 GMT (envelope-from git) Date: Fri, 4 Oct 2024 00:01:54 GMT Message-Id: <202410040001.49401sBs039588@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: 593d7a1634b5 - main - apcidump: Add dumping SPCR 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: 593d7a1634b5536f0ce2935305c3a5d1d6dd56bd Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=593d7a1634b5536f0ce2935305c3a5d1d6dd56bd commit 593d7a1634b5536f0ce2935305c3a5d1d6dd56bd Author: Warner Losh AuthorDate: 2024-10-03 22:48:27 +0000 Commit: Warner Losh CommitDate: 2024-10-04 00:01:07 +0000 apcidump: Add dumping SPCR When we find a SPCR (Serial Port Console Redirection) TABLE, print all the details. This includes support for the recent Revision 3 and Revision 4 tables, though I've not encountered them in the wild yet, so that code is untested. https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table Sponsored by: Netflix --- usr.sbin/acpi/acpidump/acpi.c | 170 +++++++++++++++++++++++++++++++++++++- usr.sbin/acpi/acpidump/acpidump.8 | 1 + 2 files changed, 168 insertions(+), 3 deletions(-) diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c index fe68b5062351..95ecb42825eb 100644 --- a/usr.sbin/acpi/acpidump/acpi.c +++ b/usr.sbin/acpi/acpidump/acpi.c @@ -1257,18 +1257,180 @@ acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp) printf(END_COMMENT); } + static void acpi_handle_tpm2(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_TPM2 *tpm2; - + printf (BEGIN_COMMENT); acpi_print_sdt(sdp); tpm2 = (ACPI_TABLE_TPM2 *) sdp; printf ("\t\tControlArea=%jx\n", tpm2->ControlAddress); - printf ("\t\tStartMethod=%x\n", tpm2->StartMethod); + printf ("\t\tStartMethod=%x\n", tpm2->StartMethod); + printf (END_COMMENT); +} + +static int spcr_xlate_baud(uint8_t r) +{ + static int rates[] = { 9600, 19200, -1, 57600, 115200 }; + _Static_assert(nitems(rates) == 7 - 3 + 1, "rates array size incorrect"); + + if (r == 0) + return (0); + + if (r < 3 || r > 7) + return (-1); + + return (rates[r - 3]); +} + +static const char *spcr_interface_type(int ift) +{ + static const char *if_names[] = { + [0x00] = "Fully 16550-compatible", + [0x01] = "16550 subset compatible with DBGP Revision 1", + [0x02] = "MAX311xE SPI UART", + [0x03] = "Arm PL011 UART", + [0x04] = "MSM8x60 (e.g. 8960)", + [0x05] = "Nvidia 16550", + [0x06] = "TI OMAP", + [0x07] = "Reserved (Do Not Use)", + [0x08] = "APM88xxxx", + [0x09] = "MSM8974", + [0x0a] = "SAM5250", + [0x0b] = "Intel USIF", + [0x0c] = "i.MX 6", + [0x0d] = "(deprecated) Arm SBSA (2.x only) Generic UART supporting only 32-bit accesses", + [0x0e] = "Arm SBSA Generic UART", + [0x0f] = "Arm DCC", + [0x10] = "BCM2835", + [0x11] = "SDM845 with clock rate of 1.8432 MHz", + [0x12] = "16550-compatible with parameters defined in Generic Address Structure", + [0x13] = "SDM845 with clock rate of 7.372 MHz", + [0x14] = "Intel LPSS", + [0x15] = "RISC-V SBI console (any supported SBI mechanism)", + }; + + if (ift >= (int)nitems(if_names) || if_names[ift] == NULL) + return ("Reserved"); + return (if_names[ift]); +} + +static const char *spcr_interrupt_type(int ift) +{ + static char buf[100]; + +#define APPEND(b,s) \ + if ((ift & (b)) != 0) { \ + if (strlen(buf) > 0) \ + strlcat(buf, ",", sizeof(buf)); \ + strlcat(buf, s, sizeof(buf)); \ + } + + *buf = '\0'; + APPEND(0x01, "PC/AT IRQ"); + APPEND(0x02, "I/O APIC"); + APPEND(0x04, "I/O SAPIC"); + APPEND(0x08, "ARMH GIC"); + APPEND(0x10, "RISC-V PLIC/APLIC"); + +#undef APPEND + + return (buf); +} + +static const char *spcr_terminal_type(int type) +{ + static const char *term_names[] = { + [0] = "VT100", + [1] = "Extended VT100", + [2] = "VT-UTF8", + [3] = "ANSI", + }; + + if (type >= (int)nitems(term_names) || term_names[type] == NULL) + return ("Reserved"); + return (term_names[type]); +} + +/* + * Serial Port Console Redirection version 3 and 4 are too new to have proper + * definitions in ACPI headers, so provide them. + */ +#pragma pack(1) +struct SPCR_3 +{ + ACPI_TABLE_SPCR spcr2; + UINT32 UARTClockFrequency; +}; + +struct SPCR_4 +{ + struct SPCR_3 spcr3; + UINT32 PreciseBaudRate; + UINT16 NamespaceStringLength; + UINT16 NamespaceStringOffset; +}; +#pragma pack() + +static void acpi_handle_spcr(ACPI_TABLE_HEADER *sdp) +{ + ACPI_TABLE_SPCR *spcr; + + printf (BEGIN_COMMENT); + acpi_print_sdt(sdp); + + /* Rev 1 and 2 are the same size */ + spcr = (ACPI_TABLE_SPCR *) sdp; + printf ("\tInterfaceType=%d (%s)\n", spcr->InterfaceType, + spcr_interface_type(spcr->InterfaceType)); + printf ("\tSerialPort="); + acpi_print_gas(&spcr->SerialPort); + printf ("\n\tInterruptType=%#x (%s)\n", spcr->InterruptType, + spcr_interrupt_type(spcr->InterruptType)); + printf ("\tPcInterrupt=%d (%s)\n", spcr->PcInterrupt, + (spcr->InterruptType & 0x1) ? "Valid" : "Invalid"); + printf ("\tInterrupt=%d\n", spcr->Interrupt); + printf ("\tBaudRate=%d (%d)\n", spcr_xlate_baud(spcr->BaudRate), spcr->BaudRate); + printf ("\tParity=%d\n", spcr->Parity); + printf ("\tStopBits=%d\n", spcr->StopBits); + printf ("\tFlowControl=%d\n", spcr->FlowControl); + printf ("\tTerminalType=%d (%s)\n", spcr->TerminalType, + spcr_terminal_type(spcr->TerminalType)); + printf ("\tPciDeviceId=%#04x\n", spcr->PciDeviceId); + printf ("\tPciVendorId=%#04x\n", spcr->PciVendorId); + printf ("\tPciBus=%d\n", spcr->PciBus); + printf ("\tPciDevice=%d\n", spcr->PciDevice); + printf ("\tPciFunction=%d\n", spcr->PciFunction); + printf ("\tPciFlags=%d\n", spcr->PciFlags); + printf ("\tPciSegment=%d\n", spcr->PciSegment); + + /* Rev 3 added UARTClockFrequency */ + if (sdp->Revision >= 3) { + struct SPCR_3 *spcr3 = (struct SPCR_3 *)sdp; + + printf("\tUARTClockFrequency=%jd", + (uintmax_t)spcr3->UARTClockFrequency); + } + + /* Rev 4 added PreciseBaudRate and Namespace* */ + if (sdp->Revision >= 4) { + struct SPCR_4 *spcr4 = (struct SPCR_4 *)sdp; + + printf("\tPreciseBaudRate=%jd", + (uintmax_t)spcr4->PreciseBaudRate); + if (spcr4->NamespaceStringLength > 0 && + spcr4->NamespaceStringOffset >= sizeof(*spcr4) && + sdp->Length >= spcr4->NamespaceStringOffset + + spcr4->NamespaceStringLength) { + printf ("\tNamespaceString='%s'\n", + (char *)sdp + spcr4->NamespaceStringOffset); + } + } + printf (END_COMMENT); } - + static const char * devscope_type2str(int type) { @@ -2468,6 +2630,8 @@ acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp) acpi_handle_lpit(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_TPM2, 4)) acpi_handle_tpm2(sdp); + else if (!memcmp(sdp->Signature, ACPI_SIG_SPCR, 4)) + acpi_handle_spcr(sdp); else { printf(BEGIN_COMMENT); acpi_print_sdt(sdp); diff --git a/usr.sbin/acpi/acpidump/acpidump.8 b/usr.sbin/acpi/acpidump/acpidump.8 index f193b9a3511a..9703741f418f 100644 --- a/usr.sbin/acpi/acpidump/acpidump.8 +++ b/usr.sbin/acpi/acpidump/acpidump.8 @@ -112,6 +112,7 @@ utility dumps contents of the following tables: .It RSD PTR .It RSDT .It SLIT +.It SPCR Serial Port Console Redirection .It SRAT .It TCPA .It TPM2