Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3919407ybl; Tue, 21 Jan 2020 09:25:13 -0800 (PST) X-Google-Smtp-Source: APXvYqyJg0mOHiY5Vw4u5yk0+rUKr5RsrV33ESAYnkmo7Y2ElzsSD8E+Gh7z0+k+w+i2ZX/V6t/6 X-Received: by 2002:a9d:6b89:: with SMTP id b9mr4256457otq.298.1579627512948; Tue, 21 Jan 2020 09:25:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579627512; cv=none; d=google.com; s=arc-20160816; b=cdGknCc5xA14RBW6XtlFAZ3D3DK/5eg1kJLxplYImoi/p6cyKthgTc3aGTRK7rLRho XXP3Hnx94N+lY4L8dUaJ7ihAQjdB66rr5ED4S9n1bDvbQecb9ZXk3vBi2XqS9KlOZTAV jPF7dXl/sHu2BQpzJUAYzcsMkFgi+4v91PHxiCqaYBmIZyKLKAVNwBDpRoyz6Q5Kg5Iy sBr0VeKl6LlG/QV6PeVMntio0Cfzqs3VgLFBr3MCh6EF44BfGImKK4Twi8l+g7jgryYH oHX3I0D3jhJt48n2fZGszKULTAtM7V6oBenJdEAYwJIaiMN7wx0zxVnynnazKOW67vdG cvjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=qulnROX80EQfKAAAdi+58//mX5ebVC1xGhbdWeXljF8=; b=rnti+9f6H/J7AGvBio0pq+1SRZsJnf14QqOF6Y3owfL5nTOFhbICc6v03IpVSD0sTC F6t6RarC+Ek57IakBlMICmTp4Vz0ImWFkpfoK/h1gbEkMuWKnZ6cVM4TPNmt9dhkHV7W 75D+bOrGyBmu/+owuIGYNelCoxJ7JShCHHEg6S1nwcZe/EEfvWWJKP0mKQcjOtMO8UIc +FVhBDBPJeAzHApO0dslZ9PeK8L9EV3Wd/kccor7ETd6rbCjaKhJgndQ7zZcI1sBgYLI KF2Yge4GZsJDhF/Q6HyBupyLjlcJ411EQtzCu74X+dThIECOGau5fWDeXvg2iBKkZ7Vj T+RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=eG+XPRzq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5si19760270otp.174.2020.01.21.09.24.57; Tue, 21 Jan 2020 09:25:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=eG+XPRzq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729180AbgAURX4 (ORCPT + 99 others); Tue, 21 Jan 2020 12:23:56 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39499 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729113AbgAURX4 (ORCPT ); Tue, 21 Jan 2020 12:23:56 -0500 Received: by mail-wr1-f68.google.com with SMTP id y11so4169257wrt.6 for ; Tue, 21 Jan 2020 09:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version; bh=qulnROX80EQfKAAAdi+58//mX5ebVC1xGhbdWeXljF8=; b=eG+XPRzqZ6F4FmKkHJAHP7CO4l7BZ/6BzcAqbm2s8SSy6AGDVp+wczEGbXiWb1iJrF Qel8TreGnPjZz8PUCYkTC4w3bpZrvq14Te2kY9eKJjYdYs9OKTlRsPOaYb8aVn3OFn2m 8i/m6y6AhASt6vHlvmwxUINw4oLnuf9zpJ25d0aMoMs/1BiDVPVBaUcmDTy6tHSSpuqN I+/L6N5zkTNiF5VxEIju3XoRsRyhOKys1YQrLc/gedSp9HHhZSrJ+79xczPT9EcTosSD QdD2EsKS16F8ivI0zBotGeSgd5Z+xtBoOU6Uh7Ogew341LgTJs5I/MBo3Dh3lyqwhGLi ILdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=qulnROX80EQfKAAAdi+58//mX5ebVC1xGhbdWeXljF8=; b=Gz2rBmsyuU3VLXdFtydHZXoo4970qxyDyFScXr8pKzjtJ3n07YqlPQBNvG6tgIpL3A FMwymE7kH4+kNCwn6Prg0SInfr3UiK3Nacnd+MqLSFjLxRL5AAOwDAoKLObfxU4jIwin toURhn2OCaFqz0Vz8uKkf9oatIVqBQpMioIQBLbFLV2+2MU4ImvX+YU267Tjr6XsuCtk Ft77yiYyIlnqrvmk9PahqtPL+GVoeJ8gyotaC9NNeywp553YWT3JyeYRhpeyI3R+FdLC +A1Llt7nxro/mQCv44SvukZ/csmZ4t+1cf57vRAW1Mu4rz1HLiOTXpquZGuBLMuAV0yp n4JQ== X-Gm-Message-State: APjAAAV92TQ9DrjE/p9JOD96Lwq02jJc6nUPFh456xbtZyP/TsHGDQn7 5bSPNF2wKzKcsZyt3+Y1YJCWTQ== X-Received: by 2002:a5d:5273:: with SMTP id l19mr6609447wrc.175.1579627433651; Tue, 21 Jan 2020 09:23:53 -0800 (PST) Received: from localhost (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id v14sm52906783wrm.28.2020.01.21.09.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2020 09:23:52 -0800 (PST) From: Julien Masson To: Kevin Hilman , Greg Kroah-Hartman Cc: linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, Jiri Slaby , linux-kernel@vger.kernel.org, Julien Masson Subject: [PATCH v3] tty: serial: meson_uart: Add support for kernel debugger Date: Tue, 21 Jan 2020 18:22:52 +0100 Message-ID: <867e1klo48.fsf@julienm-fedora-R90NQGV9.i-did-not-set--mail-host-address--so-tickle-me> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kgdb invokes the poll_put_char and poll_get_char when communicating with the host. This patch implement the serial polling hooks for the meson_uart to be used for KGDB debugging over serial line. Signed-off-by: Julien Masson --- Changes since v2 [1]: * Increase UART timeout to 10 ms -> For some reasons the previous value (1ms) is now too low with recent kernel. It made KGDB hang when printing long string for example. By setting this timeout to 10 ms, we avoid this kind of issue. Changes since v1 [0]: * Use readl_poll_timeout_atomic instead of looping with read + cpu_relax -> read every 5 usecs during 1 msec * add some comments * Test environment: Board: "Le Potato" https://libre.computer/products/boards/aml-s905x-cc/ Kernel Tree: https://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-amlogic.git Kernel command line arguments: kgdboc=ttyAML0,115200 kgdbretry=4 nokaslr kgdbcon Kernel modules: CONFIG_DEBUG_INFO=y CONFIG_DEBUG_KERNEL=y CONFIG_FRAME_POINTER=y CONFIG_KGDB=y CONFIG_KGDB_SERIAL_CONSOLE=y WARNING: for single step instruction I had to adapt/apply this patch: https://lore.kernel.org/patchwork/patch/562423/ [0]: https://patchwork.kernel.org/patch/10792397/ [1]: https://patchwork.kernel.org/patch/10801583/ drivers/tty/serial/meson_uart.c | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index fbc5bc022a39..b79c6d64bfb2 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,8 @@ #define AML_UART_PORT_OFFSET 6 #define AML_UART_DEV_NAME "ttyAML" +#define AML_UART_POLL_USEC 5 +#define AML_UART_TIMEOUT_USEC 10000 static struct uart_driver meson_uart_driver; @@ -427,6 +430,64 @@ static void meson_uart_config_port(struct uart_port *port, int flags) } } +#ifdef CONFIG_CONSOLE_POLL +/* + * Console polling routines for writing and reading from the uart while + * in an interrupt or debug context (i.e. kgdb). + */ + +static int meson_uart_poll_get_char(struct uart_port *port) +{ + u32 c; + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + + if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) + c = NO_POLL_CHAR; + else + c = readl(port->membase + AML_UART_RFIFO); + + spin_unlock_irqrestore(&port->lock, flags); + + return c; +} + +static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c) +{ + unsigned long flags; + u32 reg; + int ret; + + spin_lock_irqsave(&port->lock, flags); + + /* Wait until FIFO is empty or timeout */ + ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, + reg & AML_UART_TX_EMPTY, + AML_UART_POLL_USEC, + AML_UART_TIMEOUT_USEC); + if (ret == -ETIMEDOUT) { + dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); + goto out; + } + + /* Write the character */ + writel(c, port->membase + AML_UART_WFIFO); + + /* Wait until FIFO is empty or timeout */ + ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, + reg & AML_UART_TX_EMPTY, + AML_UART_POLL_USEC, + AML_UART_TIMEOUT_USEC); + if (ret == -ETIMEDOUT) + dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); + +out: + spin_unlock_irqrestore(&port->lock, flags); +} + +#endif /* CONFIG_CONSOLE_POLL */ + static const struct uart_ops meson_uart_ops = { .set_mctrl = meson_uart_set_mctrl, .get_mctrl = meson_uart_get_mctrl, @@ -442,6 +503,10 @@ static const struct uart_ops meson_uart_ops = { .request_port = meson_uart_request_port, .release_port = meson_uart_release_port, .verify_port = meson_uart_verify_port, +#ifdef CONFIG_CONSOLE_POLL + .poll_get_char = meson_uart_poll_get_char, + .poll_put_char = meson_uart_poll_put_char, +#endif }; #ifdef CONFIG_SERIAL_MESON_CONSOLE -- 2.21.1