From: peter@hurleysoftware.com (Peter Hurley)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 3/5] ACPI: parse SPCR and enable matching console
Date: Mon, 4 Apr 2016 14:23:45 -0700 [thread overview]
Message-ID: <5702DB61.4010805@hurleysoftware.com> (raw)
In-Reply-To: <1459431629-27934-4-git-send-email-aleksey.makarov@linaro.org>
On 03/31/2016 06:40 AM, Aleksey Makarov wrote:
> 'ARM Server Base Boot Requiremets' [1] mentions SPCR (Serial Port
> Console Redirection Table) [2] as a mandatory ACPI table that
> specifies the configuration of serial console.
>
> Defer initialization of DT earlycon until ACPI/DT decision is made.
>
> Parse the ACPI SPCR table, setup earlycon if required,
> enable specified console.
>
> Thanks to Peter Hurley for explaining how this should work.
>
> [1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0044a/index.html
> [2] https://msdn.microsoft.com/en-us/library/windows/hardware/dn639132(v=vs.85).aspx
So for the code:
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
However, I still have concerns regarding the license of this code
as GPL, when the Microsoft patent notice in [2] above only provides
two license options, neither of which are referred to in the
drivers/acpi/spcr.c file header and neither of which (I believe) are
GPL compatible.
> Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
> ---
> drivers/acpi/Kconfig | 3 ++
> drivers/acpi/Makefile | 1 +
> drivers/acpi/spcr.c | 111 ++++++++++++++++++++++++++++++++++++++++++
> drivers/tty/serial/earlycon.c | 19 +++++++-
> include/linux/acpi.h | 6 +++
> include/linux/serial_core.h | 6 +++
> 6 files changed, 144 insertions(+), 2 deletions(-)
> create mode 100644 drivers/acpi/spcr.c
>
> diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
> index 65fb483..5611eb6 100644
> --- a/drivers/acpi/Kconfig
> +++ b/drivers/acpi/Kconfig
> @@ -77,6 +77,9 @@ config ACPI_DEBUGGER_USER
>
> endif
>
> +config ACPI_SPCR_TABLE
> + bool
> +
> config ACPI_SLEEP
> bool
> depends on SUSPEND || HIBERNATION
> diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> index 7395928..f70ae14 100644
> --- a/drivers/acpi/Makefile
> +++ b/drivers/acpi/Makefile
> @@ -82,6 +82,7 @@ obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o
> obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o
> obj-$(CONFIG_ACPI_BGRT) += bgrt.o
> obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o
> +obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o
> obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o
>
> # processor has its own "processor." module_param namespace
> diff --git a/drivers/acpi/spcr.c b/drivers/acpi/spcr.c
> new file mode 100644
> index 0000000..68ffc33
> --- /dev/null
> +++ b/drivers/acpi/spcr.c
> @@ -0,0 +1,111 @@
> +/*
> + * Copyright (c) 2012, Intel Corporation
> + * Copyright (c) 2015, Red Hat, Inc.
> + * Copyright (c) 2015, 2016 Linaro Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + */
> +
> +#define pr_fmt(fmt) "ACPI: SPCR: " fmt
> +
> +#include <linux/acpi.h>
> +#include <linux/console.h>
> +#include <linux/kernel.h>
> +#include <linux/serial_core.h>
> +
> +/**
> + * parse_spcr() - parse ACPI SPCR table and add preferred console
> + *
> + * @earlycon: set up earlycon for the console specified by the table
> + *
> + * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
> + * defined to parse ACPI SPCR table. As a result of the parsing preferred
> + * console is registered and if @earlycon is true, earlycon is set up.
> + *
> + * When CONFIG_ACPI_SPCR_TABLE is defined, this function should should be called
> + * from arch inintialization code as soon as the DT/ACPI decision is made.
> + *
> + */
> +int __init parse_spcr(bool earlycon)
> +{
> + static char opts[64];
> + struct acpi_table_spcr *table;
> + acpi_size table_size;
> + acpi_status status;
> + char *uart;
> + char *iotype;
> + int baud_rate;
> + int err;
> +
> + if (acpi_disabled)
> + return -ENODEV;
> +
> + status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0,
> + (struct acpi_table_header **)&table,
> + &table_size);
> +
> + if (ACPI_FAILURE(status))
> + return -ENOENT;
> +
> + if (table->header.revision < 2) {
> + err = -ENOENT;
> + pr_err("wrong table version\n");
> + goto done;
> + }
> +
> + iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
> + "mmio" : "io";
> +
> + switch (table->interface_type) {
> + case ACPI_DBG2_ARM_SBSA_32BIT:
> + iotype = "mmio32";
> + /* fall through */
> + case ACPI_DBG2_ARM_PL011:
> + case ACPI_DBG2_ARM_SBSA_GENERIC:
> + case ACPI_DBG2_BCM2835:
> + uart = "pl011";
> + break;
> + case ACPI_DBG2_16550_COMPATIBLE:
> + case ACPI_DBG2_16550_SUBSET:
> + uart = "uart";
> + break;
> + default:
> + err = -ENOENT;
> + goto done;
> + }
> +
> + switch (table->baud_rate) {
> + case 3:
> + baud_rate = 9600;
> + break;
> + case 4:
> + baud_rate = 19200;
> + break;
> + case 6:
> + baud_rate = 57600;
> + break;
> + case 7:
> + baud_rate = 115200;
> + break;
> + default:
> + err = -ENOENT;
> + goto done;
> + }
> +
> + snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
> + table->serial_port.address, baud_rate);
> +
> + pr_info("console: %s", opts);
> +
> + if (earlycon)
> + setup_earlycon(opts);
> +
> + err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
> +
> +done:
> + early_acpi_os_unmap_memory((void __iomem *)table, table_size);
> + return err;
> +}
> diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
> index 7aae655..ea00b9f 100644
> --- a/drivers/tty/serial/earlycon.c
> +++ b/drivers/tty/serial/earlycon.c
> @@ -21,6 +21,7 @@
> #include <linux/sizes.h>
> #include <linux/of.h>
> #include <linux/of_fdt.h>
> +#include <linux/acpi.h>
>
> #ifdef CONFIG_FIX_EARLYCON_MEM
> #include <asm/fixmap.h>
> @@ -199,6 +200,14 @@ int __init setup_earlycon(char *buf)
> return -ENOENT;
> }
>
> +/*
> + * When CONFIG_ACPI_SPCR_TABLE is defined, "earlycon" without parameters in
> + * command line does not start DT earlycon immediately, instead it defers
> + * starting it until DT/ACPI decision is made. At that time if ACPI is enabled
> + * call parse_spcr(), else call early_init_dt_scan_chosen_stdout()
> + */
> +bool earlycon_init_is_deferred __initdata;
> +
> /* early_param wrapper for setup_earlycon() */
> static int __init param_setup_earlycon(char *buf)
> {
> @@ -208,8 +217,14 @@ static int __init param_setup_earlycon(char *buf)
> * Just 'earlycon' is a valid param for devicetree earlycons;
> * don't generate a warning from parse_early_params() in that case
> */
> - if (!buf || !buf[0])
> - return early_init_dt_scan_chosen_stdout();
> + if (!buf || !buf[0]) {
> + if (IS_ENABLED(CONFIG_ACPI_SPCR_TABLE)) {
> + earlycon_init_is_deferred = true;
> + return 0;
> + } else {
> + return early_init_dt_scan_chosen_stdout();
> + }
> + }
>
> err = setup_earlycon(buf);
> if (err == -ENOENT || err == -EALREADY)
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 06ed7e5..1095ed6 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -1004,4 +1004,10 @@ static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev,
> #define acpi_probe_device_table(t) ({ int __r = 0; __r;})
> #endif
>
> +#ifdef CONFIG_ACPI_SPCR_TABLE
> +int parse_spcr(bool earlycon);
> +#else
> +static inline int parse_spcr(bool earlycon) { return 0; }
> +#endif
> +
> #endif /*_LINUX_ACPI_H*/
> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
> index cbfcf38..de6750f 100644
> --- a/include/linux/serial_core.h
> +++ b/include/linux/serial_core.h
> @@ -363,6 +363,12 @@ extern int of_setup_earlycon(const struct earlycon_id *match,
> unsigned long node,
> const char *options);
>
> +#ifdef CONFIG_SERIAL_EARLYCON
> +extern bool earlycon_init_is_deferred __initdata;
> +#else
> +static const bool earlycon_init_is_deferred;
> +#endif
> +
> struct uart_port *uart_get_console(struct uart_port *ports, int nr,
> struct console *c);
> int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,
>
next prev parent reply other threads:[~2016-04-04 21:23 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-31 13:40 [PATCH v7 0/5] ACPI: parse the SPCR table Aleksey Makarov
2016-03-31 13:40 ` [PATCH v7 1/5] of/serial: move earlycon early_param handling to serial Aleksey Makarov
2016-03-31 16:32 ` Greg Kroah-Hartman
2016-03-31 17:04 ` Aleksey Makarov
2016-03-31 17:37 ` Greg Kroah-Hartman
2016-03-31 18:21 ` Aleksey Makarov
2016-04-04 21:07 ` Peter Hurley
2016-04-29 0:42 ` Greg Kroah-Hartman
2016-03-31 13:40 ` [PATCH v7 2/5] ACPICA: Headers: Add new constants for the DBG2 ACPI table Aleksey Makarov
2016-03-31 13:40 ` [PATCH v7 3/5] ACPI: parse SPCR and enable matching console Aleksey Makarov
2016-04-04 21:23 ` Peter Hurley [this message]
2016-04-06 10:31 ` Aleksey Makarov
2016-03-31 13:40 ` [PATCH v7 4/5] ARM64: ACPI: enable ACPI_SPCR_TABLE Aleksey Makarov
2016-03-31 13:40 ` [PATCH v7 5/5] serial: pl011: add console matching function Aleksey Makarov
2016-04-04 21:08 ` Peter Hurley
2016-04-29 0:43 ` Greg Kroah-Hartman
2016-04-05 16:27 ` [PATCH v7 0/5] ACPI: parse the SPCR table Mark Salter
2016-04-06 10:24 ` Aleksey Makarov
2016-04-06 10:52 ` Graeme Gregory
2016-04-06 14:18 ` Mark Salter
2016-04-06 16:27 ` Peter Hurley
2016-04-06 19:00 ` Mark Salter
2016-05-12 8:20 ` Jon Masters
2016-05-12 11:52 ` Aleksey Makarov
2016-05-12 13:08 ` Kefeng Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5702DB61.4010805@hurleysoftware.com \
--to=peter@hurleysoftware.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).