Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp218958ima; Fri, 1 Feb 2019 02:12:03 -0800 (PST) X-Google-Smtp-Source: AHgI3IYm+psZTAmZbt8tzQKh7IlMUYK+lZxYjPQK6rAy+XjX73O8FdMATGYFvpC1tULNgnZwCTh7 X-Received: by 2002:a63:6ecf:: with SMTP id j198mr1677478pgc.3.1549015923644; Fri, 01 Feb 2019 02:12:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549015923; cv=none; d=google.com; s=arc-20160816; b=FbBtewRa/KqWnyIWfqj0LB5myNuVHDCkHbcz6cVCM7KLAMDJua0fiOp09SZR24Bgtc RmgZnMLpJ9UonzDAWpWiDHVUCxevtB26DG8jexT9ZVZ92gwSd0TtaPSFCr2VKMKys1xk 35bTHyImGHffjNChfj4ZxnQYvb/2WyZYQ3IyzgJmmhMcij8OWEjCtJpp/NWcNabBquEk GcMpHdwziKyzx1ZslBNAu5ajo98WPaDW2MYpGF9RNDhGgFJ2prwRdG0znPkEZVcXBTYa xHjjCnuOa7gnUR0OY6rbBrDxRST6fnVDU19WXv7ZDiU39bCl7Dv7njKo/Rl1s/DbN7Iy sJUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=FiRsK6Rkv+MGMGuc5WsI9lDR8qk6mP1jDsr/R3+Ts38=; b=pK2uK+e6BCnBOaJYO5oSvd86Bxzct9T+G4DTq7vV8sCO7r4PXrjG/eBRFKTHhdpLqn ifax7+smyeBPLg+NUZaEbDJo/k4jsgK6O0MfgnMfmQZG9s+Pa1JGi3YorLsRcbqgAAnV C4e7x7InUxfNqejYMGpUD01MQEdJMyoQZCwfrXuAqBXJnIsvJB6zurlwsjRW8RTudGAy 6scsVyzwcLDfVtaxZMJMKn55ThaELf+xs3PFnDwfSVTG7/+c29E8iqgUoDfSNqUKgDO7 x2vRK05yzmhppAO4DPYO47LJyf37/9rfIX9+CezqdRjhq7Jcw3JKOgf9a10ZXirCjos1 HN2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=WFxTxX2h; 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 32si7172943ple.72.2019.02.01.02.11.48; Fri, 01 Feb 2019 02:12:03 -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=WFxTxX2h; 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 S1727943AbfBAJ7s (ORCPT + 99 others); Fri, 1 Feb 2019 04:59:48 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34077 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726658AbfBAJ7s (ORCPT ); Fri, 1 Feb 2019 04:59:48 -0500 Received: by mail-wm1-f65.google.com with SMTP id y185so4136095wmd.1 for ; Fri, 01 Feb 2019 01:59:47 -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; bh=FiRsK6Rkv+MGMGuc5WsI9lDR8qk6mP1jDsr/R3+Ts38=; b=WFxTxX2htHocA7ziAHT44X9GHyroRFZDjWeGl1wJQP5WgZTAdioUYL7AwLlxRa+9oi AXnG5d/9Ow3QsJ8GuJY9qOKf+TmSSaJ0R9sfV4DP7GGMJRm7qShUFKai2LHQ5YSxrQuM CsBE1upw4E+gsy0xlCjinyoGDI5qjRqtztdCg8WdbIvUg74jgu0jiQeOP0N3dtxEc2VU CQbYzv6c4KMLK4X3cpmMDs2je/nlYTURMtGg9hVt8F8CX4J/YAbVr69VFk+gwYG9etE0 ze9YmdPz43NLDBeEdn59w+RspCFrmgiVVItaF9nUEJn85ndX5hKDu50u/gQUbYYMc9G3 pj1Q== 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; bh=FiRsK6Rkv+MGMGuc5WsI9lDR8qk6mP1jDsr/R3+Ts38=; b=kJRIJxrTKzi8GWDaDgJIY0SvNSRMN+hjozD0uHsxs/zi9CB1hokgv7Ndv5y0rkPUD3 dMpnTsxIUHOd3ooqXuIhP5FZp7bplfNcycPWtl33WH/S+Hxz1Wia0R7DpV1Ta30tmhOh 2B6ZTVwZ/BLVtlS/BB7KHST9ewhVgutQyMmUReDP8WptqUb5yYhTtIijCtEjt4A6GoMJ kP/ww+5HX3BzN9ZrBJa3Khkrobc+JQSAGJueAfFzeTJB6fAXc0OkIN78PzbqclJetI5o kCHmcc1Gwbs+h/yIkXyWOCglq7AUZX8Uu+F/a9Tmj8eSaOZOHWhrI0Febytjv0dGfxUL o5pw== X-Gm-Message-State: AHQUAuYasCLyjqncgp8kbEVoDRJlUQ43vMBg07tvMIhrtfTIS8xo7qTX eJExcPJEbph+ttu7OZf1ls/isA== X-Received: by 2002:a1c:7fca:: with SMTP id a193mr1724626wmd.36.1549015186690; Fri, 01 Feb 2019 01:59:46 -0800 (PST) Received: from julienm-ubuntu-20JES0UQ00.home ([2a01:cb1d:333:ad00:9812:3ac:b5fb:9a4e]) by smtp.gmail.com with ESMTPSA id 129sm4086575wmd.18.2019.02.01.01.59.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 01:59:45 -0800 (PST) From: Julien Masson To: Greg Kroah-Hartman , Kevin Hilman Cc: Julien Masson , Jiri Slaby , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] tty: serial: meson_uart: Add support for kernel debugger Date: Fri, 1 Feb 2019 10:59:22 +0100 Message-Id: <1549015162-17418-1-git-send-email-jmasson@baylibre.com> X-Mailer: git-send-email 2.7.4 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 --- It has been tested on "Le Potato" board: https://libre.computer/products/boards/aml-s905x-cc/ 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 apply this patch: https://lore.kernel.org/patchwork/patch/562423/ drivers/tty/serial/meson_uart.c | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index 8a84259..49b20da 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -426,6 +426,48 @@ 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; + + spin_lock_irqsave(&port->lock, flags); + + while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_EMPTY)) + cpu_relax(); + + writel(c, port->membase + AML_UART_WFIFO); + + while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_EMPTY)) + cpu_relax(); + + 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, @@ -441,6 +483,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.7.4