8163715
From patchwork Fri Aug 12 11:07:14 2016
8163715
Content-Type: text/plain; charset="utf-8"
8163715
MIME-Version: 1.0
8163715
Content-Transfer-Encoding: 7bit
8163715
Subject: [v9,1/4] of/serial: move earlycon early_param handling to serial
8163715
From: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
X-Patchwork-Id: 9276727
8163715
Message-Id: <20160812110717.12351-1-aleksey.makarov@linaro.org>
8163715
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
8163715
 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8163715
Cc: linux-serial@vger.kernel.org, linux-acpi@vger.kernel.org,
8163715
 linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
8163715
 Aleksey Makarov <aleksey.makarov@linaro.org>,
8163715
 Russell King <linux@arm.linux.org.uk>, Len Brown <lenb@kernel.org>,
8163715
 Leif Lindholm <leif.lindholm@linaro.org>,
8163715
 Graeme Gregory <graeme.gregory@linaro.org>, Al Stone <ahs3@redhat.com>,
8163715
 Christopher Covington <cov@codeaurora.org>,
8163715
 Yury Norov <ynorov@caviumnetworks.com>,
8163715
 Peter Hurley <peter@hurleysoftware.com>,
8163715
 Andy Shevchenko <andy.shevchenko@gmail.com>,
8163715
 "Zheng, Lv" <lv.zheng@intel.com>, Mark Salter <msalter@redhat.com>,
8163715
 Kefeng Wang <wangkefeng.wang@huawei.com>,
8163715
 Rob Herring <robh+dt@kernel.org>, Frank Rowand <frowand.list@gmail.com>,
8163715
 Jiri Slaby <jslaby@suse.com>, devicetree@vger.kernel.org
8163715
Date: Fri, 12 Aug 2016 14:07:14 +0300
8163715
8163715
From: Leif Lindholm <leif.lindholm@linaro.org>
8163715
8163715
We have multiple "earlycon" early_param handlers - merge the DT one into
8163715
the main earlycon one.  It's a cleanup that also will be useful
8163715
to defer setting up DT console until ACPI/DT decision is made.
8163715
8163715
Rename the exported function to avoid clashing with the function from
8163715
arch/microblaze/kernel/prom.c
8163715
8163715
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
8163715
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
Acked-by: Rob Herring <robh@kernel.org>
8163715
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8163715
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
8163715
Tested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
8163715
---
8163715
 drivers/of/fdt.c              | 11 +----------
8163715
 drivers/tty/serial/earlycon.c |  2 +-
8163715
 include/linux/of_fdt.h        |  3 +++
8163715
 3 files changed, 5 insertions(+), 11 deletions(-)
8163715
8163715
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
8163715
index 55f1b83..741cac53 100644
8163715
--- a/drivers/of/fdt.c
8163715
+++ b/drivers/of/fdt.c
8163715
@@ -924,7 +924,7 @@ static inline void early_init_dt_check_for_initrd(unsigned long node)
8163715
 
8163715
 #ifdef CONFIG_SERIAL_EARLYCON
8163715
 
8163715
-static int __init early_init_dt_scan_chosen_serial(void)
8163715
+int __init early_init_dt_scan_chosen_stdout(void)
8163715
 {
8163715
 	int offset;
8163715
 	const char *p, *q, *options = NULL;
8163715
@@ -968,15 +968,6 @@ static int __init early_init_dt_scan_chosen_serial(void)
8163715
 	}
8163715
 	return -ENODEV;
8163715
 }
8163715
-
8163715
-static int __init setup_of_earlycon(char *buf)
8163715
-{
8163715
-	if (buf)
8163715
-		return 0;
8163715
-
8163715
-	return early_init_dt_scan_chosen_serial();
8163715
-}
8163715
-early_param("earlycon", setup_of_earlycon);
8163715
 #endif
8163715
 
8163715
 /**
8163715
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
8163715
index 067783f..7aae655 100644
8163715
--- a/drivers/tty/serial/earlycon.c
8163715
+++ b/drivers/tty/serial/earlycon.c
8163715
@@ -209,7 +209,7 @@ static int __init param_setup_earlycon(char *buf)
8163715
 	 * don't generate a warning from parse_early_params() in that case
8163715
 	 */
8163715
 	if (!buf || !buf[0])
8163715
-		return 0;
8163715
+		return early_init_dt_scan_chosen_stdout();
8163715
 
8163715
 	err = setup_earlycon(buf);
8163715
 	if (err == -ENOENT || err == -EALREADY)
8163715
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
8163715
index 26c3302..4341f32 100644
8163715
--- a/include/linux/of_fdt.h
8163715
+++ b/include/linux/of_fdt.h
8163715
@@ -14,6 +14,7 @@
8163715
 
8163715
 #include <linux/types.h>
8163715
 #include <linux/init.h>
8163715
+#include <linux/errno.h>
8163715
 
8163715
 /* Definitions used by the flattened device tree */
8163715
 #define OF_DT_HEADER		0xd00dfeed	/* marker */
8163715
@@ -66,6 +67,7 @@ extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
8163715
 				     int depth, void *data);
8163715
 extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
8163715
 				     int depth, void *data);
8163715
+extern int early_init_dt_scan_chosen_stdout(void);
8163715
 extern void early_init_fdt_scan_reserved_mem(void);
8163715
 extern void early_init_fdt_reserve_self(void);
8163715
 extern void early_init_dt_add_memory_arch(u64 base, u64 size);
8163715
@@ -94,6 +96,7 @@ extern void early_get_first_memblock_info(void *, phys_addr_t *);
8163715
 extern u64 of_flat_dt_translate_address(unsigned long node);
8163715
 extern void of_fdt_limit_memory(int limit);
8163715
 #else /* CONFIG_OF_FLATTREE */
8163715
+static inline int early_init_dt_scan_chosen_stdout(void) { return -ENODEV; }
8163715
 static inline void early_init_fdt_scan_reserved_mem(void) {}
8163715
 static inline void early_init_fdt_reserve_self(void) {}
8163715
 static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
8163715
From patchwork Thu Aug 11 15:31:39 2016
8163715
Content-Type: text/plain; charset="utf-8"
8163715
MIME-Version: 1.0
8163715
Content-Transfer-Encoding: 7bit
8163715
Subject: [v9,2/4] ACPI: parse SPCR and enable matching console
8163715
From: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
X-Patchwork-Id: 9275443
8163715
Message-Id: <20160811153152.755-3-aleksey.makarov@linaro.org>
8163715
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
8163715
 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8163715
Cc: linux-serial@vger.kernel.org, linux-acpi@vger.kernel.org,
8163715
 linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
8163715
 Aleksey Makarov <aleksey.makarov@linaro.org>,
8163715
 Russell King <linux@arm.linux.org.uk>, Len Brown <lenb@kernel.org>,
8163715
 Leif Lindholm <leif.lindholm@linaro.org>,
8163715
 Graeme Gregory <graeme.gregory@linaro.org>, Al Stone <ahs3@redhat.com>,
8163715
 Christopher Covington <cov@codeaurora.org>,
8163715
 Yury Norov <ynorov@caviumnetworks.com>,
8163715
 Peter Hurley <peter@hurleysoftware.com>,
8163715
 Andy Shevchenko <andy.shevchenko@gmail.com>,
8163715
 "Zheng, Lv" <lv.zheng@intel.com>, Mark Salter <msalter@redhat.com>,
8163715
 Kefeng Wang <wangkefeng.wang@huawei.com>, Jiri Slaby <jslaby@suse.com>
8163715
Date: Thu, 11 Aug 2016 18:31:39 +0300
8163715
8163715
'ARM Server Base Boot Requiremets' [1] mentions SPCR (Serial Port
8163715
Console Redirection Table) [2] as a mandatory ACPI table that
8163715
specifies the configuration of serial console.
8163715
8163715
Defer initialization of DT earlycon until ACPI/DT decision is made.
8163715
8163715
Parse the ACPI SPCR table, setup earlycon if required,
8163715
enable specified console.
8163715
8163715
Thanks to Peter Hurley for explaining how this should work.
8163715
8163715
[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0044a/index.html
8163715
[2] https://msdn.microsoft.com/en-us/library/windows/hardware/dn639132(v=vs.85).aspx
8163715
8163715
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
8163715
Tested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
8163715
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
8163715
---
8163715
 drivers/acpi/Kconfig          |   3 ++
8163715
 drivers/acpi/Makefile         |   1 +
8163715
 drivers/acpi/spcr.c           | 111 ++++++++++++++++++++++++++++++++++++++++++
8163715
 drivers/tty/serial/earlycon.c |  19 +++++++-
8163715
 include/linux/acpi.h          |   6 +++
8163715
 include/linux/serial_core.h   |   9 +++-
8163715
 6 files changed, 146 insertions(+), 3 deletions(-)
8163715
 create mode 100644 drivers/acpi/spcr.c
8163715
8163715
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
8163715
index 6cef2d1..4a269f9 100644
8163715
--- a/drivers/acpi/Kconfig
8163715
+++ b/drivers/acpi/Kconfig
8163715
@@ -77,6 +77,9 @@ config ACPI_DEBUGGER_USER
8163715
 
8163715
 endif
8163715
 
8163715
+config ACPI_SPCR_TABLE
8163715
+	bool
8163715
+
8163715
 config ACPI_SLEEP
8163715
 	bool
8163715
 	depends on SUSPEND || HIBERNATION
8163715
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
8163715
index e5ada78..d799593 100644
8163715
--- a/drivers/acpi/Makefile
8163715
+++ b/drivers/acpi/Makefile
8163715
@@ -81,6 +81,7 @@ obj-$(CONFIG_ACPI_EC_DEBUGFS)	+= ec_sys.o
8163715
 obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o
8163715
 obj-$(CONFIG_ACPI_BGRT)		+= bgrt.o
8163715
 obj-$(CONFIG_ACPI_CPPC_LIB)	+= cppc_acpi.o
8163715
+obj-$(CONFIG_ACPI_SPCR_TABLE)	+= spcr.o
8163715
 obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o
8163715
 
8163715
 # processor has its own "processor." module_param namespace
8163715
diff --git a/drivers/acpi/spcr.c b/drivers/acpi/spcr.c
8163715
new file mode 100644
8163715
index 0000000..e8d7bc7
8163715
--- /dev/null
8163715
+++ b/drivers/acpi/spcr.c
8163715
@@ -0,0 +1,111 @@
8163715
+/*
8163715
+ * Copyright (c) 2012, Intel Corporation
8163715
+ * Copyright (c) 2015, Red Hat, Inc.
8163715
+ * Copyright (c) 2015, 2016 Linaro Ltd.
8163715
+ *
8163715
+ * This program is free software; you can redistribute it and/or modify
8163715
+ * it under the terms of the GNU General Public License version 2 as
8163715
+ * published by the Free Software Foundation.
8163715
+ *
8163715
+ */
8163715
+
8163715
+#define pr_fmt(fmt) "ACPI: SPCR: " fmt
8163715
+
8163715
+#include <linux/acpi.h>
8163715
+#include <linux/console.h>
8163715
+#include <linux/kernel.h>
8163715
+#include <linux/serial_core.h>
8163715
+
8163715
+/**
8163715
+ * parse_spcr() - parse ACPI SPCR table and add preferred console
8163715
+ *
8163715
+ * @earlycon: set up earlycon for the console specified by the table
8163715
+ *
8163715
+ * For the architectures with support for ACPI, CONFIG_ACPI_SPCR_TABLE may be
8163715
+ * defined to parse ACPI SPCR table.  As a result of the parsing preferred
8163715
+ * console is registered and if @earlycon is true, earlycon is set up.
8163715
+ *
8163715
+ * When CONFIG_ACPI_SPCR_TABLE is defined, this function should be called
8163715
+ * from arch inintialization code as soon as the DT/ACPI decision is made.
8163715
+ *
8163715
+ */
8163715
+int __init parse_spcr(bool earlycon)
8163715
+{
8163715
+	static char opts[64];
8163715
+	struct acpi_table_spcr *table;
8163715
+	acpi_size table_size;
8163715
+	acpi_status status;
8163715
+	char *uart;
8163715
+	char *iotype;
8163715
+	int baud_rate;
8163715
+	int err;
8163715
+
8163715
+	if (acpi_disabled)
8163715
+		return -ENODEV;
8163715
+
8163715
+	status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0,
8163715
+					  (struct acpi_table_header **)&table,
8163715
+					  &table_size);
8163715
+
8163715
+	if (ACPI_FAILURE(status))
8163715
+		return -ENOENT;
8163715
+
8163715
+	if (table->header.revision < 2) {
8163715
+		err = -ENOENT;
8163715
+		pr_err("wrong table version\n");
8163715
+		goto done;
8163715
+	}
8163715
+
8163715
+	iotype = table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY ?
8163715
+			"mmio" : "io";
8163715
+
8163715
+	switch (table->interface_type) {
8163715
+	case ACPI_DBG2_ARM_SBSA_32BIT:
8163715
+		iotype = "mmio32";
8163715
+		/* fall through */
8163715
+	case ACPI_DBG2_ARM_PL011:
8163715
+	case ACPI_DBG2_ARM_SBSA_GENERIC:
8163715
+	case ACPI_DBG2_BCM2835:
8163715
+		uart = "pl011";
8163715
+		break;
8163715
+	case ACPI_DBG2_16550_COMPATIBLE:
8163715
+	case ACPI_DBG2_16550_SUBSET:
8163715
+		uart = "uart";
8163715
+		break;
8163715
+	default:
8163715
+		err = -ENOENT;
8163715
+		goto done;
8163715
+	}
8163715
+
8163715
+	switch (table->baud_rate) {
8163715
+	case 3:
8163715
+		baud_rate = 9600;
8163715
+		break;
8163715
+	case 4:
8163715
+		baud_rate = 19200;
8163715
+		break;
8163715
+	case 6:
8163715
+		baud_rate = 57600;
8163715
+		break;
8163715
+	case 7:
8163715
+		baud_rate = 115200;
8163715
+		break;
8163715
+	default:
8163715
+		err = -ENOENT;
8163715
+		goto done;
8163715
+	}
8163715
+
8163715
+	snprintf(opts, sizeof(opts), "%s,%s,0x%llx,%d", uart, iotype,
8163715
+		 table->serial_port.address, baud_rate);
8163715
+
8163715
+	pr_info("console: %s\n", opts);
8163715
+
8163715
+	if (earlycon)
8163715
+		setup_earlycon(opts);
8163715
+
8163715
+	err = add_preferred_console(uart, 0, opts + strlen(uart) + 1);
8163715
+
8163715
+done:
8163715
+	early_acpi_os_unmap_memory((void __iomem *)table, table_size);
8163715
+	return err;
8163715
+}
8163715
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
8163715
index 7aae655..ea00b9f 100644
8163715
--- a/drivers/tty/serial/earlycon.c
8163715
+++ b/drivers/tty/serial/earlycon.c
8163715
@@ -21,6 +21,7 @@
8163715
 #include <linux/sizes.h>
8163715
 #include <linux/of.h>
8163715
 #include <linux/of_fdt.h>
8163715
+#include <linux/acpi.h>
8163715
 
8163715
 #ifdef CONFIG_FIX_EARLYCON_MEM
8163715
 #include <asm/fixmap.h>
8163715
@@ -199,6 +200,14 @@ int __init setup_earlycon(char *buf)
8163715
 	return -ENOENT;
8163715
 }
8163715
 
8163715
+/*
8163715
+ * When CONFIG_ACPI_SPCR_TABLE is defined, "earlycon" without parameters in
8163715
+ * command line does not start DT earlycon immediately, instead it defers
8163715
+ * starting it until DT/ACPI decision is made.  At that time if ACPI is enabled
8163715
+ * call parse_spcr(), else call early_init_dt_scan_chosen_stdout()
8163715
+ */
8163715
+bool earlycon_init_is_deferred __initdata;
8163715
+
8163715
 /* early_param wrapper for setup_earlycon() */
8163715
 static int __init param_setup_earlycon(char *buf)
8163715
 {
8163715
@@ -208,8 +217,14 @@ static int __init param_setup_earlycon(char *buf)
8163715
 	 * Just 'earlycon' is a valid param for devicetree earlycons;
8163715
 	 * don't generate a warning from parse_early_params() in that case
8163715
 	 */
8163715
-	if (!buf || !buf[0])
8163715
-		return early_init_dt_scan_chosen_stdout();
8163715
+	if (!buf || !buf[0]) {
8163715
+		if (IS_ENABLED(CONFIG_ACPI_SPCR_TABLE)) {
8163715
+			earlycon_init_is_deferred = true;
8163715
+			return 0;
8163715
+		} else {
8163715
+			return early_init_dt_scan_chosen_stdout();
8163715
+		}
8163715
+	}
8163715
 
8163715
 	err = setup_earlycon(buf);
8163715
 	if (err == -ENOENT || err == -EALREADY)
8163715
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
8163715
index 4d8452c..32407e4 100644
8163715
--- a/include/linux/acpi.h
8163715
+++ b/include/linux/acpi.h
8163715
@@ -1074,4 +1074,10 @@ void acpi_table_upgrade(void);
8163715
 static inline void acpi_table_upgrade(void) { }
8163715
 #endif
8163715
 
8163715
+#ifdef CONFIG_ACPI_SPCR_TABLE
8163715
+int parse_spcr(bool earlycon);
8163715
+#else
8163715
+static inline int parse_spcr(bool earlycon) { return 0; }
8163715
+#endif
8163715
+
8163715
 #endif	/*_LINUX_ACPI_H*/
8163715
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
8163715
index 2f44e20..04b8cfb 100644
8163715
--- a/include/linux/serial_core.h
8163715
+++ b/include/linux/serial_core.h
8163715
@@ -367,11 +367,18 @@ extern const struct earlycon_id __earlycon_table_end[];
8163715
 
8163715
 #define EARLYCON_DECLARE(_name, fn)	OF_EARLYCON_DECLARE(_name, "", fn)
8163715
 
8163715
-extern int setup_earlycon(char *buf);
8163715
 extern int of_setup_earlycon(const struct earlycon_id *match,
8163715
 			     unsigned long node,
8163715
 			     const char *options);
8163715
 
8163715
+#ifdef CONFIG_SERIAL_EARLYCON
8163715
+extern bool earlycon_init_is_deferred __initdata;
8163715
+extern int setup_earlycon(char *buf);
8163715
+#else
8163715
+static const bool earlycon_init_is_deferred;
8163715
+static inline int setup_earlycon(char *buf) { return 0; }
8163715
+#endif
8163715
+
8163715
 struct uart_port *uart_get_console(struct uart_port *ports, int nr,
8163715
 				   struct console *c);
8163715
 int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,
8163715
From patchwork Thu Aug 11 15:31:40 2016
8163715
Content-Type: text/plain; charset="utf-8"
8163715
MIME-Version: 1.0
8163715
Content-Transfer-Encoding: 7bit
8163715
Subject: [v9,3/4] ARM64: ACPI: enable ACPI_SPCR_TABLE
8163715
From: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
X-Patchwork-Id: 9275457
8163715
Message-Id: <20160811153152.755-4-aleksey.makarov@linaro.org>
8163715
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
8163715
 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8163715
Cc: linux-serial@vger.kernel.org, linux-acpi@vger.kernel.org,
8163715
 linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
8163715
 Aleksey Makarov <aleksey.makarov@linaro.org>,
8163715
 Russell King <linux@arm.linux.org.uk>, Len Brown <lenb@kernel.org>,
8163715
 Leif Lindholm <leif.lindholm@linaro.org>,
8163715
 Graeme Gregory <graeme.gregory@linaro.org>, Al Stone <ahs3@redhat.com>,
8163715
 Christopher Covington <cov@codeaurora.org>,
8163715
 Yury Norov <ynorov@caviumnetworks.com>,
8163715
 Peter Hurley <peter@hurleysoftware.com>,
8163715
 Andy Shevchenko <andy.shevchenko@gmail.com>,
8163715
 "Zheng, Lv" <lv.zheng@intel.com>, Mark Salter <msalter@redhat.com>,
8163715
 Kefeng Wang <wangkefeng.wang@huawei.com>,
8163715
 Catalin Marinas <catalin.marinas@arm.com>,
8163715
 Will Deacon <will.deacon@arm.com>
8163715
Date: Thu, 11 Aug 2016 18:31:40 +0300
8163715
8163715
SBBR mentions SPCR as a mandatory ACPI table.  So enable it for ARM64
8163715
8163715
Earlycon should be set up as early as possible.  ACPI boot tables are
8163715
mapped in arch/arm64/kernel/acpi.c:acpi_boot_table_init() that
8163715
is called from setup_arch() and that's where we parse SPCR.
8163715
So it has to be opted-in per-arch.
8163715
8163715
When ACPI_SPCR_TABLE is defined initialization of DT earlycon is
8163715
deferred until the DT/ACPI decision is done.  Initialize DT earlycon
8163715
if ACPI is disabled.
8163715
8163715
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
Tested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
8163715
---
8163715
 arch/arm64/Kconfig       |  1 +
8163715
 arch/arm64/kernel/acpi.c | 11 ++++++++++-
8163715
 2 files changed, 11 insertions(+), 1 deletion(-)
8163715
8163715
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
8163715
index 69c8787..a54dfc0 100644
8163715
--- a/arch/arm64/Kconfig
8163715
+++ b/arch/arm64/Kconfig
8163715
@@ -4,6 +4,7 @@ config ARM64
8163715
 	select ACPI_GENERIC_GSI if ACPI
8163715
 	select ACPI_REDUCED_HARDWARE_ONLY if ACPI
8163715
 	select ACPI_MCFG if ACPI
8163715
+	select ACPI_SPCR_TABLE if ACPI
8163715
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
8163715
 	select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
8163715
 	select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
8163715
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
8163715
index 3e4f1a4..252a6d9 100644
8163715
--- a/arch/arm64/kernel/acpi.c
8163715
+++ b/arch/arm64/kernel/acpi.c
8163715
@@ -24,6 +24,7 @@
8163715
 #include <linux/memblock.h>
8163715
 #include <linux/of_fdt.h>
8163715
 #include <linux/smp.h>
8163715
+#include <linux/serial_core.h>
8163715
 
8163715
 #include <asm/cputype.h>
8163715
 #include <asm/cpu_ops.h>
8163715
@@ -206,7 +207,7 @@ void __init acpi_boot_table_init(void)
8163715
 	if (param_acpi_off ||
8163715
 	    (!param_acpi_on && !param_acpi_force &&
8163715
 	     of_scan_flat_dt(dt_scan_depth1_nodes, NULL)))
8163715
-		return;
8163715
+		goto done;
8163715
 
8163715
 	/*
8163715
 	 * ACPI is disabled at this point. Enable it in order to parse
8163715
@@ -226,6 +227,14 @@ void __init acpi_boot_table_init(void)
8163715
 		if (!param_acpi_force)
8163715
 			disable_acpi();
8163715
 	}
8163715
+
8163715
+done:
8163715
+	if (acpi_disabled) {
8163715
+		if (earlycon_init_is_deferred)
8163715
+			early_init_dt_scan_chosen_stdout();
8163715
+	} else {
8163715
+		parse_spcr(earlycon_init_is_deferred);
8163715
+	}
8163715
 }
8163715
 
8163715
 #ifdef CONFIG_ACPI_APEI
8163715
From patchwork Mon Aug 15 13:35:03 2016
8163715
Content-Type: text/plain; charset="utf-8"
8163715
MIME-Version: 1.0
8163715
Content-Transfer-Encoding: 7bit
8163715
Subject: [v9,4/4] serial: pl011: add console matching function
8163715
From: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
X-Patchwork-Id: 9280971
8163715
Message-Id: <20160815133505.15294-1-aleksey.makarov@linaro.org>
8163715
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
8163715
 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8163715
Cc: linux-serial@vger.kernel.org, linux-acpi@vger.kernel.org,
8163715
 linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
8163715
 Aleksey Makarov <aleksey.makarov@linaro.org>,
8163715
 Russell King <linux@arm.linux.org.uk>, Len Brown <lenb@kernel.org>,
8163715
 Leif Lindholm <leif.lindholm@linaro.org>,
8163715
 Graeme Gregory <graeme.gregory@linaro.org>, Al Stone <ahs3@redhat.com>,
8163715
 Christopher Covington <cov@codeaurora.org>,
8163715
 Yury Norov <ynorov@caviumnetworks.com>,
8163715
 Peter Hurley <peter@hurleysoftware.com>,
8163715
 Andy Shevchenko <andy.shevchenko@gmail.com>,
8163715
 "Zheng, Lv" <lv.zheng@intel.com>, Mark Salter <msalter@redhat.com>,
8163715
 Kefeng Wang <wangkefeng.wang@huawei.com>,
8163715
 Russell King <linux@armlinux.org.uk>, Jiri Slaby <jslaby@suse.com>
8163715
Date: Mon, 15 Aug 2016 16:35:03 +0300
8163715
8163715
This patch adds function pl011_console_match() that implements
8163715
method match of struct console.  It allows to match consoles against
8163715
data specified in a string, for example taken from command line or
8163715
compiled by ACPI SPCR table handler.
8163715
8163715
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
8163715
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
8163715
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
8163715
---
8163715
 drivers/tty/serial/amba-pl011.c | 55 +++++++++++++++++++++++++++++++++++++++++
8163715
 1 file changed, 55 insertions(+)
8163715
8163715
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
8163715
index 8a9e213..2f9af8a 100644
8163715
--- a/drivers/tty/serial/amba-pl011.c
8163715
+++ b/drivers/tty/serial/amba-pl011.c
8163715
@@ -2288,12 +2288,67 @@ static int __init pl011_console_setup(struct console *co, char *options)
8163715
 	return uart_set_options(&uap->port, co, baud, parity, bits, flow);
8163715
 }
8163715
 
8163715
+/**
8163715
+ *	pl011_console_match - non-standard console matching
8163715
+ *	@co:	  registering console
8163715
+ *	@name:	  name from console command line
8163715
+ *	@idx:	  index from console command line
8163715
+ *	@options: ptr to option string from console command line
8163715
+ *
8163715
+ *	Only attempts to match console command lines of the form:
8163715
+ *	    console=pl011,mmio|mmio32,<addr>[,<options>]
8163715
+ *	    console=pl011,0x<addr>[,<options>]
8163715
+ *	This form is used to register an initial earlycon boot console and
8163715
+ *	replace it with the amba_console at pl011 driver init.
8163715
+ *
8163715
+ *	Performs console setup for a match (as required by interface)
8163715
+ *	If no <options> are specified, then assume the h/w is already setup.
8163715
+ *
8163715
+ *	Returns 0 if console matches; otherwise non-zero to use default matching
8163715
+ */
8163715
+static int __init pl011_console_match(struct console *co, char *name, int idx,
8163715
+				      char *options)
8163715
+{
8163715
+	unsigned char iotype;
8163715
+	unsigned long addr;
8163715
+	int i;
8163715
+
8163715
+	if (strcmp(name, "pl011") != 0)
8163715
+		return -ENODEV;
8163715
+
8163715
+	if (uart_parse_earlycon(options, &iotype, &addr, &options))
8163715
+		return -ENODEV;
8163715
+
8163715
+	if (iotype != UPIO_MEM && iotype != UPIO_MEM32)
8163715
+		return -ENODEV;
8163715
+
8163715
+	/* try to match the port specified on the command line */
8163715
+	for (i = 0; i < ARRAY_SIZE(amba_ports); i++) {
8163715
+		struct uart_port *port;
8163715
+
8163715
+		if (!amba_ports[i])
8163715
+			continue;
8163715
+
8163715
+		port = &amba_ports[i]->port;
8163715
+
8163715
+		if (port->mapbase != addr)
8163715
+			continue;
8163715
+
8163715
+		co->index = i;
8163715
+		port->cons = co;
8163715
+		return pl011_console_setup(co, options);
8163715
+	}
8163715
+
8163715
+	return -ENODEV;
8163715
+}
8163715
+
8163715
 static struct uart_driver amba_reg;
8163715
 static struct console amba_console = {
8163715
 	.name		= "ttyAMA",
8163715
 	.write		= pl011_console_write,
8163715
 	.device		= uart_console_device,
8163715
 	.setup		= pl011_console_setup,
8163715
+	.match		= pl011_console_match,
8163715
 	.flags		= CON_PRINTBUFFER,
8163715
 	.index		= -1,
8163715
 	.data		= &amba_reg,