linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: serial: meson_uart: Add support for kernel debugger
@ 2019-02-01  9:59 Julien Masson
  2019-02-01 10:10 ` Corentin Labbe
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Masson @ 2019-02-01  9:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Kevin Hilman
  Cc: Julien Masson, linux-kernel, linux-serial, Jiri Slaby,
	linux-amlogic, linux-arm-kernel

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 <jmasson@baylibre.com>
---
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


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tty: serial: meson_uart: Add support for kernel debugger
  2019-02-01  9:59 [PATCH] tty: serial: meson_uart: Add support for kernel debugger Julien Masson
@ 2019-02-01 10:10 ` Corentin Labbe
  2019-02-07 17:04   ` Masson, Julien
  0 siblings, 1 reply; 3+ messages in thread
From: Corentin Labbe @ 2019-02-01 10:10 UTC (permalink / raw)
  To: Julien Masson
  Cc: Greg Kroah-Hartman, linux-kernel, Kevin Hilman, linux-serial,
	Jiri Slaby, linux-amlogic, linux-arm-kernel

On Fri, Feb 01, 2019 at 10:59:22AM +0100, Julien Masson wrote:
> 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 <jmasson@baylibre.com>
> ---
> 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();

Hello

Perhaps you could use read_poll_timeout() ?
This will also permit to handle the timeout case.

Regards


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tty: serial: meson_uart: Add support for kernel debugger
  2019-02-01 10:10 ` Corentin Labbe
@ 2019-02-07 17:04   ` Masson, Julien
  0 siblings, 0 replies; 3+ messages in thread
From: Masson, Julien @ 2019-02-07 17:04 UTC (permalink / raw)
  To: Corentin Labbe
  Cc: Julien Masson, Greg Kroah-Hartman, linux-kernel, Kevin Hilman,
	linux-serial, Jiri Slaby, linux-amlogic, linux-arm-kernel


On Fri 01 Feb 2019 at 11:10, Corentin Labbe <clabbe.montjoie@gmail.com> wrote:

> On Fri, Feb 01, 2019 at 10:59:22AM +0100, Julien Masson wrote:
>> 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 <jmasson@baylibre.com>
>> ---
>> 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();
>
> Hello
>
> Perhaps you could use read_poll_timeout() ?
> This will also permit to handle the timeout case.
>
> Regards

Thanks for the tips Corentin.

I tested with a poll of 5 usec and 1 msec of timeout.
I had to use readl_poll_timeout_atomic(...) since I'm in atomic context
(spinlock).

I'll send a v2 of this patch.

Regards

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-07 17:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-01  9:59 [PATCH] tty: serial: meson_uart: Add support for kernel debugger Julien Masson
2019-02-01 10:10 ` Corentin Labbe
2019-02-07 17:04   ` Masson, Julien

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).