From patchwork Mon Feb 15 18:05:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 61958 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1218572lbl; Mon, 15 Feb 2016 10:13:37 -0800 (PST) X-Received: by 10.66.220.162 with SMTP id px2mr25352517pac.15.1455560017212; Mon, 15 Feb 2016 10:13:37 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pz7si44733237pab.216.2016.02.15.10.13.36; Mon, 15 Feb 2016 10:13:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752554AbcBOSNf (ORCPT + 30 others); Mon, 15 Feb 2016 13:13:35 -0500 Received: from mail-lb0-f179.google.com ([209.85.217.179]:33600 "EHLO mail-lb0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752344AbcBOSLW (ORCPT ); Mon, 15 Feb 2016 13:11:22 -0500 Received: by mail-lb0-f179.google.com with SMTP id x4so82942803lbm.0 for ; Mon, 15 Feb 2016 10:11:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s5xz3l7kKh8gSiqG2gbn1ypen/D1A7Cu0JbJ2AKv+4Y=; b=ZJSHIZJGets68bUIz/4HioHZbZ8XKik1V+UjUHqMMmmcfrvrWE9fklCukmcaWJpOyV KaY/GyuV5qzdiqQvKW/mrxPNhDhm+Kq5HF31Dl4XDltyIFyON2daDhUHAYFBTmkN7x98 ck97LhUAMYx5UbJfa9zBO6z1L1IGUmQqLUVN8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s5xz3l7kKh8gSiqG2gbn1ypen/D1A7Cu0JbJ2AKv+4Y=; b=c51lPMo2oTzBiVUDBO9ZMYM5Szoc5t0Td4SqWvoBvIFp/h2W7SVa/yggcttF9gN4qr 3M6FFbZWeJ9WwRuNJG+ajAl1x+7xDO/GNsXZdbDleoDP71TqdyYvXlKgVPZ4VPo1c45A 6u9qOD8ECP0NcRZy2O1EQjr2PZ8BYneWPy6no+WsMNss98dpGwSY/YVOzSeK4kI0/QZ3 22aWiZCjcgMxNwvhixD2qIzKvb7PCu8e9ve+4S3DNJFl/JRQpBmJZMzy1s25Bt00rfD3 0qCrsu97+MjeI3zTwzc270cuZJQPlQxnSCYco2jzn6gwTRd+hoU5w3ftyXNY+kpuC1Cn z/cQ== X-Gm-Message-State: AG10YOQFEPbNxxpbtIMMtrDMPVU4k2cxc7jZqJnSFEmolF6wSiLfUXim1+YVsqzSQvrwrkBF X-Received: by 10.112.209.99 with SMTP id ml3mr7228939lbc.26.1455559880946; Mon, 15 Feb 2016 10:11:20 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id i66sm3818526lfg.4.2016.02.15.10.11.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Feb 2016 10:11:20 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aleksey Makarov , Russell King , Greg Kroah-Hartman , "Rafael J . Wysocki" , Leif Lindholm , Graeme Gregory , Al Stone , Christopher Covington , Len Brown , Jiri Slaby Subject: [PATCH v3 2/5] ACPI: parse SPCR and enable matching console Date: Mon, 15 Feb 2016 21:05:26 +0300 Message-Id: <1455559532-8305-3-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1455559532-8305-1-git-send-email-aleksey.makarov@linaro.org> References: <1455559532-8305-1-git-send-email-aleksey.makarov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org '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. Parse this table and check if any registered console match the description. If it does, enable that console. Introduce a new function acpi_console_check(). At the uart port registration, this function checks if the ACPI SPCR table specifies its argument of type struct uart_port to be a console and if so calls add_preferred_console(). [1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0044a/index.html [2] http://msdn.microsoft.com/en-us/library/windows/hardware/dn639131(v=vs.85).aspx Signed-off-by: Aleksey Makarov --- drivers/acpi/Kconfig | 3 ++ drivers/acpi/Makefile | 1 + drivers/acpi/spcr.c | 97 ++++++++++++++++++++++++++++++++++++++++ drivers/tty/serial/serial_core.c | 14 +++++- include/linux/acpi.h | 10 +++++ 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 drivers/acpi/spcr.c -- 2.7.1 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 346101c..708b143 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -81,6 +81,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..a1eca91 --- /dev/null +++ b/drivers/acpi/spcr.c @@ -0,0 +1,97 @@ +/* + * 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 +#include +#include +#include + +static int acpi_table_parse_spcr(int (*handler)(struct acpi_table_spcr *table, + void *data), void *data) +{ + struct acpi_table_spcr *table = NULL; + acpi_size table_size; + acpi_status status; + int err; + + status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0, + (struct acpi_table_header **)&table, + &table_size); + + if (ACPI_FAILURE(status)) + return -ENODEV; + + err = handler(table, data); + + early_acpi_os_unmap_memory(table, table_size); + + return err; +} + +static int spcr_table_handler_check(struct acpi_table_spcr *table, void *data) +{ + struct uart_port *uport = data; + char *options; + + if (table->header.revision < 2) + return -EOPNOTSUPP; + + switch (table->baud_rate) { + case 3: + options = "9600"; + break; + case 4: + options = "19200"; + break; + case 6: + options = "57600"; + break; + case 7: + options = "115200"; + break; + default: + options = ""; + break; + } + + if ((table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY && + table->serial_port.address == (u64)uport->mapbase) || + (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_IO && + table->serial_port.address == (u64)uport->iobase)) { + pr_info("adding preferred console [%s%d]\n", uport->cons->name, + uport->line); + add_preferred_console(uport->cons->name, uport->line, options); + return 1; + + } + + return 0; +} + +/** + * acpi_console_check - Check if uart matches the console specified by SPCR. + * + * @uport: uart port to check + * + * This function checks if the ACPI SPCR table specifies @uport to be a console + * and if so calls add_preferred_console() + * + * Return: a non-error value if the console matches. + */ +bool acpi_console_check(struct uart_port *uport) +{ + if (acpi_disabled || console_set_on_cmdline) + return false; + + return acpi_table_parse_spcr(spcr_table_handler_check, uport) > 0; +} diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index a126a60..459ab54 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -2654,8 +2655,17 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) spin_lock_init(&uport->lock); lockdep_set_class(&uport->lock, &port_lock_key); } - if (uport->cons && uport->dev) - of_console_check(uport->dev->of_node, uport->cons->name, uport->line); + + /* + * Support both open FW and ACPI access to console definitions. + * Both of_console_check() and acpi_console_check() will call + * add_preferred_console() if a console definition is found. + */ + if (uport->cons && uport->dev) { + if (!acpi_console_check(uport)) + of_console_check(uport->dev->of_node, uport->cons->name, + uport->line); + } uart_configure_port(drv, state, uport); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 06ed7e5..ea0c297 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1004,4 +1004,14 @@ static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev, #define acpi_probe_device_table(t) ({ int __r = 0; __r;}) #endif +struct uart_port; +#ifdef CONFIG_ACPI_SPCR_TABLE +bool acpi_console_check(struct uart_port *uport); +#else +static inline bool acpi_console_check(struct uart_port *uport) +{ + return FALSE; +} +#endif + #endif /*_LINUX_ACPI_H*/