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