From nobody Fri May 17 16:12:49 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 4VgsSK4Vj8z5LPVW; Fri, 17 May 2024 16:12:49 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VgsSK3rBwz4QGD; Fri, 17 May 2024 16:12:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715962369; 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=0cPWXgiVod6XhUE+y2NL4gj3Wo12+JjU4IOxb0FGiZ8=; b=y2qChA+zKa9OEzj+FMg0sHz2YrqzbVLBgoi0+bBbGY3fKLfHrZkNR0DByi23GwwgQjlMZn UBtNZ+JWC4FTpbCe3J8F+QQHpxNEzBVkUusxv3/ks4q8S9PXIXt3/JxeAsdvCX3mcu0tkR Cq0OlIhgY4oBK89qTgAkjdY26n9r48/ksWiSRhCWtQmpz08fY43I40IpB491kWV9Ehgl4g l/6/Vd/zXHjOYrMmXWw2h6ndjvyb/xo0MLqXevXDjAT07kjASU+L8j/SDhOvaLwJWOdWVL zxho/vK+RErr4xljKe2a4MZFpLNM2FbQJy11J1zuYI5NjRKJKR1rzQ/lylZ7mw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715962369; a=rsa-sha256; cv=none; b=FyZGzHs2gyk0/fEJBeHXlZhb/vouGBACDi9WzJ68lv4pSell0eXnl3jOhikhYn+47DpJr0 DTHw62bxCJn5V32ewBhoLq2IgJenSORSlt1bZw3Kv835DO0rd/nGKkMajakXD2Cf/yDWO4 uymWu/OHAw7jejHwFkNDR2FxcG20c6YcOVkwpXVra48EVPIkrcJIxfl8thzuDfhJqiSIjX 161OAxFT5bgkap198p7hmp+XHZPmfQJrYohfJwQHmh83lp6MKw1PBFni9VCqZUsDztSq61 V/wLv6jh22sTiIz0xy3Y2pYsAzNm4PVZXJaJeg7WfzIUyEk0LIWWM3ZK86gN+g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715962369; 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=0cPWXgiVod6XhUE+y2NL4gj3Wo12+JjU4IOxb0FGiZ8=; b=qKLHY/7oTLeu3kCs6DUkEvgxqxN7h9+LjbEMXIf+cXh6fnOA2YizI8S6uJ+Gh7wJNOr5Ch T9nOkdFKM5eJc7aDXcfNSQfdiHaP4JMVt/VQVK+/Nsnny+pFSl3Snp86E1Kc1QP0eJTxXg 6ql2NThr+WKMCFuy5MY7zXJEFuEfwqjDnhrfyzUaGQmx764Rfutnf9mIERLK5s8CwVv/oD ERKVOYAi6h2/eV98QvGSARD7kdfVv0w5ryj+bQcA6LVaG4l2yTfvlWTlLrzc/IN3u9E6FK 6fKtqCN/gSjYwooEti2uPAdOGnQxfqKfl+ueISWZpfltcHdAUGDPU2J0oueYxw== 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 4VgsSK3KGlzpxs; Fri, 17 May 2024 16:12:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44HGCnH0065064; Fri, 17 May 2024 16:12:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44HGCneJ065061; Fri, 17 May 2024 16:12:49 GMT (envelope-from git) Date: Fri, 17 May 2024 16:12:49 GMT Message-Id: <202405171612.44HGCneJ065061@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 097bd33dd7a6 - main - uart: DBG2 support to find the debug uart 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 097bd33dd7a687cd3ad7fd4bc7ededa3b9e00e28 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=097bd33dd7a687cd3ad7fd4bc7ededa3b9e00e28 commit 097bd33dd7a687cd3ad7fd4bc7ededa3b9e00e28 Author: Andrew Turner AuthorDate: 2024-03-12 18:15:29 +0000 Commit: Andrew Turner CommitDate: 2024-05-17 16:07:15 +0000 uart: DBG2 support to find the debug uart The Debug Port Table 2 (DBG2) contains information on which devices can be used for debugging purposes. Add support to the uart driver to use the DBG2 table when enabled from loader. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D44359 --- sys/dev/uart/uart_cpu_acpi.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/sys/dev/uart/uart_cpu_acpi.c b/sys/dev/uart/uart_cpu_acpi.c index 9c9ffc1e3194..53fe459e64a1 100644 --- a/sys/dev/uart/uart_cpu_acpi.c +++ b/sys/dev/uart/uart_cpu_acpi.c @@ -210,12 +210,95 @@ out: return (error); } +static int +uart_cpu_acpi_dbg2(struct uart_devinfo *di) +{ + vm_paddr_t dbg2_physaddr; + ACPI_TABLE_DBG2 *dbg2; + ACPI_DBG2_DEVICE *dbg2_dev; + ACPI_GENERIC_ADDRESS *base_address; + struct acpi_uart_compat_data *cd; + struct uart_class *class; + int error; + bool found; + + /* Look for the SPCR table. */ + dbg2_physaddr = acpi_find_table(ACPI_SIG_DBG2); + if (dbg2_physaddr == 0) + return (ENXIO); + + dbg2 = acpi_map_table(dbg2_physaddr, ACPI_SIG_DBG2); + if (dbg2 == NULL) { + printf("Unable to map the DBG2 table!\n"); + return (ENXIO); + } + + error = ENXIO; + + dbg2_dev = (ACPI_DBG2_DEVICE *)((vm_offset_t)dbg2 + dbg2->InfoOffset); + found = false; + while ((vm_offset_t)dbg2_dev + dbg2_dev->Length <= + (vm_offset_t)dbg2 + dbg2->Header.Length) { + if (dbg2_dev->PortType != ACPI_DBG2_SERIAL_PORT) + goto next; + + /* XXX: Too restrictive? */ + if (dbg2_dev->RegisterCount != 1) + goto next; + + cd = uart_cpu_acpi_scan(dbg2_dev->PortSubtype); + if (cd == NULL) + goto next; + + class = cd->cd_class; + base_address = (ACPI_GENERIC_ADDRESS *) + ((vm_offset_t)dbg2_dev + dbg2_dev->BaseAddressOffset); + + error = uart_cpu_acpi_init_devinfo(di, class, base_address); + if (error == 0) { + found = true; + break; + } + +next: + dbg2_dev = (ACPI_DBG2_DEVICE *) + ((vm_offset_t)dbg2_dev + dbg2_dev->Length); + } + if (!found) + goto out; + + /* XXX: Find the correct value */ + di->baudrate = 115200; + + /* Apply device tweaks. */ + if ((cd->cd_quirks & UART_F_IGNORE_SPCR_REGSHFT) == + UART_F_IGNORE_SPCR_REGSHFT) { + di->bas.regshft = cd->cd_regshft; + } + + /* Create a bus space handle. */ + error = bus_space_map(di->bas.bst, base_address->Address, + uart_getrange(class), 0, &di->bas.bsh); + +out: + acpi_unmap_table(dbg2); + return (error); +} + int uart_cpu_acpi_setup(int devtype, struct uart_devinfo *di) { + char *cp; + switch(devtype) { case UART_DEV_CONSOLE: return (uart_cpu_acpi_spcr(devtype, di)); + case UART_DEV_DBGPORT: + /* Use the Debug Port Table 2 (DBG2) to find a debug uart */ + cp = kern_getenv("hw.acpi.enable_dbg2"); + if (cp != NULL && strcasecmp(cp, "yes") == 0) + return (uart_cpu_acpi_dbg2(di)); + break; } return (ENXIO); }