* [PATCH v6 1/5] of/serial: move earlycon early_param handling to serial
2016-03-24 12:51 [PATCH v6 0/5] ACPI: parse the SPCR table Aleksey Makarov
@ 2016-03-24 12:51 ` Aleksey Makarov
2016-03-24 21:07 ` Rob Herring
2016-03-24 12:52 ` [PATCH v6 2/5] ACPI: add definitions of DBG2 subtypes Aleksey Makarov
` (4 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Aleksey Makarov @ 2016-03-24 12:51 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown
Cc: linux-serial, linux-acpi, linux-kernel, linux-arm-kernel,
Aleksey Makarov, Russell King, Leif Lindholm, Graeme Gregory,
Al Stone, Christopher Covington, Yury Norov, Peter Hurley, Zheng,
Lv, Rob Herring, Frank Rowand, Grant Likely, Jiri Slaby,
devicetree
From: Leif Lindholm <leif.lindholm@linaro.org>
We have multiple "earlycon" early_param handlers - merge the DT one into
the main earlycon one. It's a cleanup that also will be useful
to defer setting up DT console until ACPI/DT decision is made.
Rename the exported function to avoid clashing with the function from
arch/microblaze/kernel/prom.c
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
---
drivers/of/fdt.c | 11 +----------
drivers/tty/serial/earlycon.c | 2 +-
include/linux/of_fdt.h | 2 ++
3 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 3349d2a..b50f775 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -805,7 +805,7 @@ static inline void early_init_dt_check_for_initrd(unsigned long node)
#ifdef CONFIG_SERIAL_EARLYCON
-static int __init early_init_dt_scan_chosen_serial(void)
+int __init early_init_dt_scan_chosen_stdout(void)
{
int offset;
const char *p, *q, *options = NULL;
@@ -849,15 +849,6 @@ static int __init early_init_dt_scan_chosen_serial(void)
}
return -ENODEV;
}
-
-static int __init setup_of_earlycon(char *buf)
-{
- if (buf)
- return 0;
-
- return early_init_dt_scan_chosen_serial();
-}
-early_param("earlycon", setup_of_earlycon);
#endif
/**
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 067783f..7aae655 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -209,7 +209,7 @@ static int __init param_setup_earlycon(char *buf)
* don't generate a warning from parse_early_params() in that case
*/
if (!buf || !buf[0])
- return 0;
+ return early_init_dt_scan_chosen_stdout();
err = setup_earlycon(buf);
if (err == -ENOENT || err == -EALREADY)
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index 2fbe868..5cfe322 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -63,6 +63,7 @@ extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
int depth, void *data);
extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
int depth, void *data);
+extern int early_init_dt_scan_chosen_stdout(void);
extern void early_init_fdt_scan_reserved_mem(void);
extern void early_init_fdt_reserve_self(void);
extern void early_init_dt_add_memory_arch(u64 base, u64 size);
@@ -91,6 +92,7 @@ extern void early_get_first_memblock_info(void *, phys_addr_t *);
extern u64 of_flat_dt_translate_address(unsigned long node);
extern void of_fdt_limit_memory(int limit);
#else /* CONFIG_OF_FLATTREE */
+static inline int early_init_dt_scan_chosen_stdout(void) { return -ENODEV; }
static inline void early_init_fdt_scan_reserved_mem(void) {}
static inline void early_init_fdt_reserve_self(void) {}
static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v6 1/5] of/serial: move earlycon early_param handling to serial
2016-03-24 12:51 ` [PATCH v6 1/5] of/serial: move earlycon early_param handling to serial Aleksey Makarov
@ 2016-03-24 21:07 ` Rob Herring
0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2016-03-24 21:07 UTC (permalink / raw)
To: Aleksey Makarov
Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown, linux-serial,
linux-acpi, linux-kernel, linux-arm-kernel, Russell King,
Leif Lindholm, Graeme Gregory, Al Stone, Christopher Covington,
Yury Norov, Peter Hurley, Zheng, Lv, Frank Rowand, Grant Likely,
Jiri Slaby, devicetree
On Thu, Mar 24, 2016 at 7:51 AM, Aleksey Makarov
<aleksey.makarov@linaro.org> wrote:
> From: Leif Lindholm <leif.lindholm@linaro.org>
>
> We have multiple "earlycon" early_param handlers - merge the DT one into
> the main earlycon one. It's a cleanup that also will be useful
> to defer setting up DT console until ACPI/DT decision is made.
>
> Rename the exported function to avoid clashing with the function from
> arch/microblaze/kernel/prom.c
>
> Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
> Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
Acked-by: Rob Herring <robh@kernel.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v6 2/5] ACPI: add definitions of DBG2 subtypes
2016-03-24 12:51 [PATCH v6 0/5] ACPI: parse the SPCR table Aleksey Makarov
2016-03-24 12:51 ` [PATCH v6 1/5] of/serial: move earlycon early_param handling to serial Aleksey Makarov
@ 2016-03-24 12:52 ` Aleksey Makarov
2016-03-24 16:45 ` Moore, Robert
2016-03-24 12:52 ` [PATCH v6 3/5] ACPI: parse SPCR and enable matching console Aleksey Makarov
` (3 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Aleksey Makarov @ 2016-03-24 12:52 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown
Cc: linux-serial, linux-acpi, linux-kernel, linux-arm-kernel,
Aleksey Makarov, Russell King, Leif Lindholm, Graeme Gregory,
Al Stone, Christopher Covington, Yury Norov, Peter Hurley, Zheng,
Lv, Robert Moore, Rafael J. Wysocki, devel
The recent version of Microsoft Debug Port Table 2 (DBG2) [1]
specifies additional serial debug port subtypes. These constants
are also referred by Serial Port Console Redirection Table (SPCR) [2]
Add these constants.
[1] https://msdn.microsoft.com/en-us/library/windows/hardware/dn639131(v=vs.85).aspx
[2] https://msdn.microsoft.com/en-us/library/windows/hardware/dn639132(v=vs.85).aspx
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
---
include/acpi/actbl2.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h
index a4ef625..652f747 100644
--- a/include/acpi/actbl2.h
+++ b/include/acpi/actbl2.h
@@ -371,6 +371,11 @@ struct acpi_dbg2_device {
#define ACPI_DBG2_16550_COMPATIBLE 0x0000
#define ACPI_DBG2_16550_SUBSET 0x0001
+#define ACPI_DBG2_ARM_PL011 0x0003
+#define ACPI_DBG2_ARM_SBSA_32BIT 0x000D
+#define ACPI_DBG2_ARM_SBSA_GENERIC 0x000E
+#define ACPI_DBG2_ARM_DCC 0x000F
+#define ACPI_DBG2_BCM2835 0x0010
#define ACPI_DBG2_1394_STANDARD 0x0000
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread* RE: [PATCH v6 2/5] ACPI: add definitions of DBG2 subtypes
2016-03-24 12:52 ` [PATCH v6 2/5] ACPI: add definitions of DBG2 subtypes Aleksey Makarov
@ 2016-03-24 16:45 ` Moore, Robert
0 siblings, 0 replies; 10+ messages in thread
From: Moore, Robert @ 2016-03-24 16:45 UTC (permalink / raw)
To: Aleksey Makarov, Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown
Cc: linux-serial, linux-acpi, linux-kernel, linux-arm-kernel,
Russell King, Leif Lindholm, Graeme Gregory, Al Stone,
Christopher Covington, Yury Norov, Peter Hurley, Zheng, Lv,
Wysocki, Rafael J, devel
We implemented all of these in ACPICA version 20160318.
> -----Original Message-----
> From: Aleksey Makarov [mailto:aleksey.makarov@linaro.org]
> Sent: Thursday, March 24, 2016 5:52 AM
> To: Greg Kroah-Hartman; Rafael J . Wysocki; Len Brown
> Cc: linux-serial@vger.kernel.org; linux-acpi@vger.kernel.org; linux-
> kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; Aleksey
> Makarov; Russell King; Leif Lindholm; Graeme Gregory; Al Stone;
> Christopher Covington; Yury Norov; Peter Hurley; Zheng, Lv; Moore, Robert;
> Wysocki, Rafael J; devel@acpica.org
> Subject: [PATCH v6 2/5] ACPI: add definitions of DBG2 subtypes
>
> The recent version of Microsoft Debug Port Table 2 (DBG2) [1] specifies
> additional serial debug port subtypes. These constants are also referred
> by Serial Port Console Redirection Table (SPCR) [2]
>
> Add these constants.
>
> [1] https://msdn.microsoft.com/en-
> us/library/windows/hardware/dn639131(v=vs.85).aspx
> [2] https://msdn.microsoft.com/en-
> us/library/windows/hardware/dn639132(v=vs.85).aspx
>
> Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
> ---
> include/acpi/actbl2.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index
> a4ef625..652f747 100644
> --- a/include/acpi/actbl2.h
> +++ b/include/acpi/actbl2.h
> @@ -371,6 +371,11 @@ struct acpi_dbg2_device {
>
> #define ACPI_DBG2_16550_COMPATIBLE 0x0000
> #define ACPI_DBG2_16550_SUBSET 0x0001
> +#define ACPI_DBG2_ARM_PL011 0x0003
> +#define ACPI_DBG2_ARM_SBSA_32BIT 0x000D
> +#define ACPI_DBG2_ARM_SBSA_GENERIC 0x000E
> +#define ACPI_DBG2_ARM_DCC 0x000F
> +#define ACPI_DBG2_BCM2835 0x0010
>
> #define ACPI_DBG2_1394_STANDARD 0x0000
>
> --
> 2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v6 3/5] ACPI: parse SPCR and enable matching console
2016-03-24 12:51 [PATCH v6 0/5] ACPI: parse the SPCR table Aleksey Makarov
2016-03-24 12:51 ` [PATCH v6 1/5] of/serial: move earlycon early_param handling to serial Aleksey Makarov
2016-03-24 12:52 ` [PATCH v6 2/5] ACPI: add definitions of DBG2 subtypes Aleksey Makarov
@ 2016-03-24 12:52 ` Aleksey Makarov
2016-03-26 0:01 ` Rafael J. Wysocki
2016-03-24 12:52 ` [PATCH v6 4/5] ACPI: enable ACPI_SPCR_TABLE on ARM64 Aleksey Makarov
` (2 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Aleksey Makarov @ 2016-03-24 12:52 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown
Cc: linux-serial, linux-acpi, linux-kernel, linux-arm-kernel,
Aleksey Makarov, Russell King, Leif Lindholm, Graeme Gregory,
Al Stone, Christopher Covington, Yury Norov, Peter Hurley, Zheng,
Lv, Jiri Slaby
'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.
If ACPI is enabled, parse the table, setup earlycon
and enable the specified console.
If it is disabled, try to set up earlycon from DT.
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
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
---
drivers/acpi/Kconfig | 3 +
drivers/acpi/Makefile | 1 +
drivers/acpi/spcr.c | 125 ++++++++++++++++++++++++++++++++++++++++++
drivers/tty/serial/earlycon.c | 11 +++-
include/linux/acpi.h | 8 +++
5 files changed, 146 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..31e667e
--- /dev/null
+++ b/drivers/acpi/spcr.c
@@ -0,0 +1,125 @@
+/*
+ * 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>
+#include <linux/of_fdt.h>
+
+static bool earlycon_init_is_deferred __initdata;
+
+void __init defer_earlycon_init(void)
+{
+ earlycon_init_is_deferred = true;
+}
+
+/**
+ * parse_spcr() - parse ACPI SPCR table and add preferred console
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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. If ACPI is enabled at that time,
+ * parse_spcr() parses the table, adds preferred console and sets up it as an
+ * earlycon. If ACPI is disabled at that time, it tries to set up earlycon
+ * from DT.
+ */
+int __init parse_spcr(void)
+{
+#define OPTS_LEN 64
+ static char opts[OPTS_LEN];
+ 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 earlycon_init_is_deferred ?
+ early_init_dt_scan_chosen_stdout() : 0;
+
+ 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 = -EINVAL;
+ 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, OPTS_LEN, "%s,%s,0x%llx,%d", uart, iotype,
+ table->serial_port.address, baud_rate);
+
+ pr_info("console: %s", opts);
+
+ if (earlycon_init_is_deferred)
+ 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..ed6aaf8 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>
@@ -208,8 +209,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)) {
+ defer_earlycon_init();
+ 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..3523995 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1004,4 +1004,12 @@ 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(void);
+void defer_earlycon_init(void);
+#else
+static inline int parse_spcr(void) { return 0; }
+static inline void defer_earlycon_init(void) { }
+#endif
+
#endif /*_LINUX_ACPI_H*/
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v6 3/5] ACPI: parse SPCR and enable matching console
2016-03-24 12:52 ` [PATCH v6 3/5] ACPI: parse SPCR and enable matching console Aleksey Makarov
@ 2016-03-26 0:01 ` Rafael J. Wysocki
0 siblings, 0 replies; 10+ messages in thread
From: Rafael J. Wysocki @ 2016-03-26 0:01 UTC (permalink / raw)
To: Aleksey Makarov
Cc: Greg Kroah-Hartman, Len Brown, linux-serial, linux-acpi,
linux-kernel, linux-arm-kernel, Russell King, Leif Lindholm,
Graeme Gregory, Al Stone, Christopher Covington, Yury Norov,
Peter Hurley, Zheng, Lv, Jiri Slaby
On Thursday, March 24, 2016 03:52:01 PM 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.
>
> If ACPI is enabled, parse the table, setup earlycon
> and enable the specified console.
>
> If it is disabled, try to set up earlycon from DT.
>
> 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
>
> Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
> ---
> drivers/acpi/Kconfig | 3 +
> drivers/acpi/Makefile | 1 +
> drivers/acpi/spcr.c | 125 ++++++++++++++++++++++++++++++++++++++++++
> drivers/tty/serial/earlycon.c | 11 +++-
> include/linux/acpi.h | 8 +++
> 5 files changed, 146 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..31e667e
> --- /dev/null
> +++ b/drivers/acpi/spcr.c
> @@ -0,0 +1,125 @@
> +/*
> + * 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>
> +#include <linux/of_fdt.h>
> +
> +static bool earlycon_init_is_deferred __initdata;
> +
> +void __init defer_earlycon_init(void)
> +{
> + earlycon_init_is_deferred = true;
> +}
> +
> +/**
> + * parse_spcr() - parse ACPI SPCR table and add preferred console
> + *
> + * 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.
> + *
> + * 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.
> + *
> + * 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. If ACPI is enabled at that time,
> + * parse_spcr() parses the table, adds preferred console and sets up it as an
> + * earlycon. If ACPI is disabled at that time, it tries to set up earlycon
> + * from DT.
> + */
> +int __init parse_spcr(void)
> +{
> +#define OPTS_LEN 64
I'm not sure if you need that symbol.
ISTR that sizeof(opts) will give you the size of the array (but maybe I'm
confusing this with something else).
> + static char opts[OPTS_LEN];
> + 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 earlycon_init_is_deferred ?
> + early_init_dt_scan_chosen_stdout() : 0;
I would prefer this to be arranged differently, so a specific error value is
returned when ACPI is disabled and the the fallback to DT happens in the
caller (if it cares about DT, that is).
> +
> + 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 = -EINVAL;
Why -EINVAL?
> + pr_err("wrong table version\n");
> + goto done;
> + }
> +
> + iotype = (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) ?
The parens are not necessary.
Thanks,
Rafael
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v6 4/5] ACPI: enable ACPI_SPCR_TABLE on ARM64
2016-03-24 12:51 [PATCH v6 0/5] ACPI: parse the SPCR table Aleksey Makarov
` (2 preceding siblings ...)
2016-03-24 12:52 ` [PATCH v6 3/5] ACPI: parse SPCR and enable matching console Aleksey Makarov
@ 2016-03-24 12:52 ` Aleksey Makarov
2016-03-24 12:52 ` [PATCH v6 5/5] serial: pl011: add console matching function Aleksey Makarov
2016-03-24 13:16 ` [PATCH v6 0/5] ACPI: parse the SPCR table Rafael J. Wysocki
5 siblings, 0 replies; 10+ messages in thread
From: Aleksey Makarov @ 2016-03-24 12:52 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown
Cc: linux-serial, linux-acpi, linux-kernel, linux-arm-kernel,
Aleksey Makarov, Russell King, Leif Lindholm, Graeme Gregory,
Al Stone, Christopher Covington, Yury Norov, Peter Hurley, Zheng,
Lv, Catalin Marinas, Will Deacon
SBBR mentions SPCR as a mandatory ACPI table. So enable it for ARM64
Earlycon should be set up as early as possible. ACPI boot tables are
mapped in arch/arm64/kernel/acpi.c:acpi_boot_table_init() called from
setup_arch() and that's where we parse SPCR. So it has to be opted-in
per-arch.
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
---
arch/arm64/Kconfig | 1 +
arch/arm64/kernel/acpi.c | 5 ++++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 07b6a16..c77b4b2 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -3,6 +3,7 @@ config ARM64
select ACPI_CCA_REQUIRED if ACPI
select ACPI_GENERIC_GSI if ACPI
select ACPI_REDUCED_HARDWARE_ONLY if ACPI
+ select ACPI_SPCR_TABLE if ACPI
select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
select ARCH_HAS_ELF_RANDOMIZE
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index d1ce8e2..046f095 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -189,7 +189,7 @@ void __init acpi_boot_table_init(void)
*/
if (param_acpi_off ||
(!param_acpi_force && of_scan_flat_dt(dt_scan_depth1_nodes, NULL)))
- return;
+ goto done;
/*
* ACPI is disabled at this point. Enable it in order to parse
@@ -209,6 +209,9 @@ void __init acpi_boot_table_init(void)
if (!param_acpi_force)
disable_acpi();
}
+
+done:
+ parse_spcr();
}
#ifdef CONFIG_ACPI_APEI
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v6 5/5] serial: pl011: add console matching function
2016-03-24 12:51 [PATCH v6 0/5] ACPI: parse the SPCR table Aleksey Makarov
` (3 preceding siblings ...)
2016-03-24 12:52 ` [PATCH v6 4/5] ACPI: enable ACPI_SPCR_TABLE on ARM64 Aleksey Makarov
@ 2016-03-24 12:52 ` Aleksey Makarov
2016-03-24 13:16 ` [PATCH v6 0/5] ACPI: parse the SPCR table Rafael J. Wysocki
5 siblings, 0 replies; 10+ messages in thread
From: Aleksey Makarov @ 2016-03-24 12:52 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown
Cc: linux-serial, linux-acpi, linux-kernel, linux-arm-kernel,
Aleksey Makarov, Russell King, Leif Lindholm, Graeme Gregory,
Al Stone, Christopher Covington, Yury Norov, Peter Hurley, Zheng,
Lv, Jiri Slaby
This patch adds function pl011_console_match() that implements
method match of struct console. It allows to match consoles against
data specified in a string, for example taken from command line or
compiled by ACPI SPCR table handler.
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
---
drivers/tty/serial/amba-pl011.c | 56 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 7c198e0..4139b64 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2287,12 +2287,68 @@ static int __init pl011_console_setup(struct console *co, char *options)
return uart_set_options(&uap->port, co, baud, parity, bits, flow);
}
+/**
+ * pl011_console_match - non-standard console matching
+ * @co: registering console
+ * @name: name from console command line
+ * @idx: index from console command line
+ * @options: ptr to option string from console command line
+ *
+ * Only attempts to match console command lines of the form:
+ * console=pl011,mmio|mmio32,<addr>[,<options>]
+ * console=pl011,0x<addr>[,<options>]
+ * This form is used to register an initial earlycon boot console and
+ * replace it with the amba_console at pl011 driver init.
+ *
+ * Performs console setup for a match (as required by interface)
+ * If no <options> are specified, then assume the h/w is already setup.
+ *
+ * Returns 0 if console matches; otherwise non-zero to use default matching
+ */
+static int __init pl011_console_match(struct console *co, char *name, int idx,
+ char *options)
+{
+ char match[] = "pl011"; /* pl011-specific earlycon name */
+ unsigned char iotype;
+ unsigned long addr;
+ int i;
+
+ if (strncmp(name, match, 5) != 0)
+ return -ENODEV;
+
+ if (uart_parse_earlycon(options, &iotype, &addr, &options))
+ return -ENODEV;
+
+ /* try to match the port specified on the command line */
+ for (i = 0; i < ARRAY_SIZE(amba_ports); i++) {
+ struct uart_port *port;
+
+ if (!amba_ports[i])
+ continue;
+
+ port = &amba_ports[i]->port;
+
+ if (port->iotype != iotype)
+ continue;
+ if ((iotype == UPIO_MEM || iotype == UPIO_MEM32) &&
+ (port->mapbase != addr))
+ continue;
+
+ co->index = i;
+ port->cons = co;
+ return pl011_console_setup(co, options);
+ }
+
+ return -ENODEV;
+}
+
static struct uart_driver amba_reg;
static struct console amba_console = {
.name = "ttyAMA",
.write = pl011_console_write,
.device = uart_console_device,
.setup = pl011_console_setup,
+ .match = pl011_console_match,
.flags = CON_PRINTBUFFER,
.index = -1,
.data = &amba_reg,
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v6 0/5] ACPI: parse the SPCR table
2016-03-24 12:51 [PATCH v6 0/5] ACPI: parse the SPCR table Aleksey Makarov
` (4 preceding siblings ...)
2016-03-24 12:52 ` [PATCH v6 5/5] serial: pl011: add console matching function Aleksey Makarov
@ 2016-03-24 13:16 ` Rafael J. Wysocki
5 siblings, 0 replies; 10+ messages in thread
From: Rafael J. Wysocki @ 2016-03-24 13:16 UTC (permalink / raw)
To: Aleksey Makarov
Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Len Brown, linux-serial,
ACPI Devel Maling List, Linux Kernel Mailing List,
linux-arm-kernel, Russell King, Leif Lindholm, Graeme Gregory,
Al Stone, Christopher Covington, Yury Norov, Peter Hurley, Zheng,
Lv
On Thu, Mar 24, 2016 at 1:51 PM, Aleksey Makarov
<aleksey.makarov@linaro.org> wrote:
> 'ARM Server Base Boot Requirements' [1] mentions SPCR (Serial Port
> Console Redirection Table) [2] as a mandatory ACPI table that
> specifies the configuration of serial console.
>
> Move "earlycon" early_param handling to earlycon.c to parse this option once
>
> Patch "ACPI: add definitions of DBG2 subtypes" is required for the next patch.
> ACPI maintainers said that they had got it for the next release of ACPICA,
> but it has not appeared in linux-next yet.
It will. Patches containing it have just been posted.
> Parse SPCR table, setup earlycon and add register specified console.
>
> Enable parsing this table on ARM64. Earlycon should be set up
> as early as possible. ACPI boot tables are mapped in
> arch/arm64/kernel/acpi.c:acpi_boot_table_init() called from setup_arch()
> and that's where we parse spcr. So it has to be opted-in per-arch.
>
> Implement console_match() for pl011.
>
> Based on the work by Leif Lindholm [3]
> Thanks to Peter Hurley for explaining how this should work.
>
> Should be applied to next-20160324.
>
> Tested on QEMU. SPCR support is included in QEMU's ARM mach-virt
> since 2.4 release.
Honestly, I'm not sure why I'm regarded as the right maintainer to send this to.
The only patch here touching generic ACPI code is [3/5] (the [2/5] is
going in through ACPICA) and the rest is all about ARM64 AFAICS. Why
don't you send it to the ARM64 maintainers instead?
I'll have some comments on [3/5], I'll send them later today or tomorrow.
Thanks,
Rafael
^ permalink raw reply [flat|nested] 10+ messages in thread