From nobody Tue Feb 13 11:51:48 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 4TZ06Y3GRTz5B7Gh; Tue, 13 Feb 2024 11:51: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 4TZ06Y0sByz44kt; Tue, 13 Feb 2024 11:51:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707825109; 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=C4F2Df/4L2J9qjVekzHYdHM9nrOPhC9kqI86fE4hKCQ=; b=qw2Czc/fkntXvSeOkQOxj0sOqmEGvGcFGpm9VWM0ooKpHG9t8XUaqFXSn5jCCTUnWY04m8 v2I3ceh78nzBpAC8y6S2y8xjV9/4eSSHRMrATR8wms4qvmX0/FfwAxZHGteSmFxQDlz+AI 0BehD/iH2YVKTodedvCFwJLgWpfnde+1x8ZviEy15EZGfodAYrmzhvmrIPClQVs1QcTjUk fGlFz5bLk/pEPUbxpVKMwQOAufZjsTJY97RGLPbP7s7F7WGAs61X41RMgHh4fgZxydGRew kFbPazfz5nM2UexS3uRiiujvds6+6T3BFe4I5blh1sUh2eP4mmqZJ9ISWpXUaw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707825109; a=rsa-sha256; cv=none; b=KG1/8nHIoPXcZVEIulZj799PpLIH+z+h4s/Se/MRaUk2zzWqR2VOapyai+Vb8fssL0jxw9 t5SinJfvGiUtm5R76OgVzXFcgTE/FU8CgLDlJW0L8+pwDXDirBXonTmRygbN9N25Nansom v8mGOuD3nFa+5iVeMxJ1yWJIL07pbn2rAH09CCUWIVE/kLr9i6tym+wESDfn9cci45SoD2 r3iWXr16xA+qWoRuI04zl1TpJZj7fAa36VDzKUdThWJgPWSteCRHYzZggEZ7MIcBal4WUW CWbyk5nTwol5ZNWaxg8lSHgh13yOMxid3IlXjUF65N3DJ7+DWLI/Gkatt3UPTA== 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=1707825109; 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=C4F2Df/4L2J9qjVekzHYdHM9nrOPhC9kqI86fE4hKCQ=; b=GXhG4YIFGjASLBbMkzIT1cBN0uWyR/tgsvxcyjD9pwllj0L4gL4K20gsfbB1oWchyO4F1l FD5RaeA+j00IwQ8c2bOqCeGGW7oJHMkWUGNRvCvdGJxaVTwVUL3fdnE4rSg2WfTJ9ihhi+ uqhvHeoxmbhlxqUgfiOrMzgG/B9uP4kSIpJGI8YG0y5VSkN41gAJ6b2Sa/Tjg9WC3F1Wie YGiyeT6wlfJrEZoGwJ6RwPzm4TN761XK7mItWfzLKvtD+Vust9qKilaI/hqY76ZJbFFqSI qSBcUpPZpNDLLF3z6kudxI1g4MIqr1V/SCGOwaUD3m80bfkRQyjN5xfWt4irpg== 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 4TZ06X70MpzDbK; Tue, 13 Feb 2024 11:51:48 +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 41DBpmiO045813; Tue, 13 Feb 2024 11:51:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41DBpmtb045810; Tue, 13 Feb 2024 11:51:48 GMT (envelope-from git) Date: Tue, 13 Feb 2024 11:51:48 GMT Message-Id: <202402131151.41DBpmtb045810@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: 202890922e31 - main - sys: Simplify enabling EARLY_PRINTF uarts 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 202890922e31382f9b11bf5f78d3dd0350d69dc1 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=202890922e31382f9b11bf5f78d3dd0350d69dc1 commit 202890922e31382f9b11bf5f78d3dd0350d69dc1 Author: Andrew Turner AuthorDate: 2024-01-08 14:45:51 +0000 Commit: Andrew Turner CommitDate: 2024-02-13 11:48:52 +0000 sys: Simplify enabling EARLY_PRINTF uarts Support selecting the early uart with "options EARLY_PRINTF=foo" in the kernel configuration file. This allows us to not have to change source files when enabling EARLY_PRINTF, simplifying enabling it. New uart drivers can be enabled by defining a new early_printf_foo value to be unique, then using "#if CHECK_EARLY_PRINTF(foo)" to decide when to enable the uart. While here add pl011 early printf support. Reviewed by: imp (earlier version) Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D43360 --- sys/dev/uart/uart_dev_mvebu.c | 11 +++-------- sys/dev/uart/uart_dev_ns8250.c | 7 +++++-- sys/dev/uart/uart_dev_pl011.c | 14 ++++++++++++++ sys/dev/uart/uart_dev_snps.c | 19 ++++++++----------- sys/kern/kern_cons.c | 12 ++++++++++++ sys/sys/systm.h | 9 +++++++++ 6 files changed, 51 insertions(+), 21 deletions(-) diff --git a/sys/dev/uart/uart_dev_mvebu.c b/sys/dev/uart/uart_dev_mvebu.c index 921298ffb6c7..8f989aa0ca14 100644 --- a/sys/dev/uart/uart_dev_mvebu.c +++ b/sys/dev/uart/uart_dev_mvebu.c @@ -104,18 +104,15 @@ /* * For debugging purposes */ -#if 0 -#ifdef EARLY_PRINTF -#if defined(SOCDEV_PA) && defined(SOCDEV_VA) -#define UART_REG_OFFSET 0x12000 +#if CHECK_EARLY_PRINTF(mvebu) static void uart_mvebu_early_putc(int c) { volatile uint32_t *tsh; volatile uint32_t *stat; - tsh = (uint32_t *)(SOCDEV_VA + UART_REG_OFFSET + UART_TSH); - stat = (uint32_t *)(SOCDEV_VA + UART_REG_OFFSET + UART_STAT); + tsh = (uint32_t *)(socdev_va + UART_REG_OFFSET + UART_TSH); + stat = (uint32_t *)(socdev_va + UART_REG_OFFSET + UART_STAT); while(!(*stat & STAT_TX_RDY)) ; @@ -125,8 +122,6 @@ uart_mvebu_early_putc(int c) early_putc_t *early_putc = uart_mvebu_early_putc; #endif -#endif -#endif /* * Low-level UART interface. diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index f211084cb013..090909fdf8d2 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -81,9 +81,12 @@ SYSCTL_INT(_hw, OID_AUTO, broken_txfifo, CTLFLAG_RWTUN, * To use early printf on x86, add the following to your kernel config: * * options UART_NS8250_EARLY_PORT=0x3f8 - * options EARLY_PRINTF + * options EARLY_PRINTF=ns8250 */ -#if defined(EARLY_PRINTF) && (defined(__amd64__) || defined(__i386__)) +#if CHECK_EARLY_PRINTF(ns8250) +#if !(defined(__amd64__) || defined(__i386__)) +#error ns8250 early putc is x86 specific as it uses inb/outb +#endif static void uart_ns8250_early_putc(int c) { diff --git a/sys/dev/uart/uart_dev_pl011.c b/sys/dev/uart/uart_dev_pl011.c index 4fd53ab67bf3..bfcf8cf1584e 100644 --- a/sys/dev/uart/uart_dev_pl011.c +++ b/sys/dev/uart/uart_dev_pl011.c @@ -249,6 +249,20 @@ uart_pl011_term(struct uart_bas *bas) { } +#if CHECK_EARLY_PRINTF(pl011) +static void +uart_pl011_early_putc(int c) +{ + volatile uint32_t *fr = (uint32_t *)(socdev_va + UART_FR * 4); + volatile uint32_t *dr = (uint32_t *)(socdev_va + UART_DR * 4); + + while ((*fr & FR_TXFF) != 0) + ; + *dr = c & 0xff; +} +early_putc_t *early_putc = uart_pl011_early_putc; +#endif /* CHECK_EARLY_PRINTF */ + static void uart_pl011_putc(struct uart_bas *bas, int c) { diff --git a/sys/dev/uart/uart_dev_snps.c b/sys/dev/uart/uart_dev_snps.c index b8b1f1f78142..b6efd1948b3e 100644 --- a/sys/dev/uart/uart_dev_snps.c +++ b/sys/dev/uart/uart_dev_snps.c @@ -54,18 +54,16 @@ struct snps_softc { /* * To use early printf on 64 bits Allwinner SoC, add to kernel config * options SOCDEV_PA=0x0 - * options SOCDEV_VA=0x40000000 - * options EARLY_PRINTF + * options EARLY_PRINTF=snps * * To use early printf on 32 bits Allwinner SoC, add to kernel config * options SOCDEV_PA=0x01C00000 * options SOCDEV_VA=0x10000000 - * options EARLY_PRINTF + * options EARLY_PRINTF=snps * * remove the if 0 */ -#if 0 -#ifdef EARLY_PRINTF +#if CHECK_EARLY_PRINTF(snps) static void uart_snps_early_putc(int c) { @@ -73,12 +71,12 @@ uart_snps_early_putc(int c) volatile uint32_t *tx; #ifdef ALLWINNER_64 - stat = (uint32_t *) (SOCDEV_VA + 0x1C2807C); - tx = (uint32_t *) (SOCDEV_VA + 0x1C28000); + stat = (uint32_t *) (socdev_va + 0x1C2807C); + tx = (uint32_t *) (socdev_va + 0x1C28000); #endif #ifdef ALLWINNER_32 - stat = (uint32_t *) (SOCDEV_VA + 0x2807C); - tx = (uint32_t *) (SOCDEV_VA + 0x28000); + stat = (uint32_t *) (socdev_va + 0x2807C); + tx = (uint32_t *) (socdev_va + 0x28000); #endif while ((*stat & (1 << 2)) == 0) @@ -86,8 +84,7 @@ uart_snps_early_putc(int c) *tx = c; } early_putc_t *early_putc = uart_snps_early_putc; -#endif /* EARLY_PRINTF */ -#endif +#endif /* CHECK_EARLY_PRINTF */ static kobj_method_t snps_methods[] = { KOBJMETHOD(uart_probe, ns8250_bus_probe), diff --git a/sys/kern/kern_cons.c b/sys/kern/kern_cons.c index 462cd0c45758..a99699ed5bce 100644 --- a/sys/kern/kern_cons.c +++ b/sys/kern/kern_cons.c @@ -72,6 +72,18 @@ #include #include +/* + * Check for 'options EARLY_PRINTF' that may have been used in old kernel + * config files. If you are hitting this error you should update your + * config to use 'options EARLY_PRINTF=', e.g. with the + * Arm pl011 use: + * + * options EARLY_PRINTF=pl011 + */ +#if CHECK_EARLY_PRINTF(1) +#error Update your config to use 'options EARLY_PRINTF=' +#endif + static MALLOC_DEFINE(M_TTYCONS, "tty console", "tty console handling"); struct cn_device { diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 376a35e7e8e2..f72f82c100dc 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -208,6 +208,15 @@ critical_exit(void) #ifdef EARLY_PRINTF typedef void early_putc_t(int ch); extern early_putc_t *early_putc; +#define CHECK_EARLY_PRINTF(x) \ + __CONCAT(early_printf_, EARLY_PRINTF) == __CONCAT(early_printf_, x) +#define early_printf_1 1 +#define early_printf_mvebu 2 +#define early_printf_ns8250 3 +#define early_printf_pl011 4 +#define early_printf_snps 5 +#else +#define CHECK_EARLY_PRINTF(x) 0 #endif int kvprintf(char const *, void (*)(int, void*), void *, int, __va_list) __printflike(1, 0);