From patchwork Mon Feb 29 12:02:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 8452391 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A4341C0553 for ; Mon, 29 Feb 2016 12:06:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8520D2027D for ; Mon, 29 Feb 2016 12:05:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7645C201FA for ; Mon, 29 Feb 2016 12:05:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaMYo-0007X1-E7; Mon, 29 Feb 2016 12:04:22 +0000 Received: from mail-lb0-x235.google.com ([2a00:1450:4010:c04::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaMYO-0007Of-G1 for linux-arm-kernel@lists.infradead.org; Mon, 29 Feb 2016 12:04:00 +0000 Received: by mail-lb0-x235.google.com with SMTP id ed16so405067lbb.0 for ; Mon, 29 Feb 2016 04:03:35 -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=O3i5RYndqrI6wg1jAFMlPLepVlc7JZSDZeGtiaI9G2k=; b=V86fl8pDYgchHSQNzK61bFuvuWMZvpkEdmVdbcAgDB7Fl7ahsFQ5QLJOeUePQ650cc IJ39tnJF1TdDLpP8YJ5JDAzkyUBH6rRPsyqeFb5atlxdx1+trsCxJ+BqTJ6YCERaVIkW uQIR7jDyR68oQke5+xQAfW6U2Z1aswNfBjAKA= 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=O3i5RYndqrI6wg1jAFMlPLepVlc7JZSDZeGtiaI9G2k=; b=D306cjUMNAjYvIYvU0Rb8MxQo8CDm84q8z67q0cXxiZvP5je1ijOC7DNNrk5FrpWga fT1ONQuB+LndSpwJZ3Umj1shvHQ5FRyjMeTjESTQ82NZH/mSGmegjUWGrzYtmAEp7h9H Cta0+kMQ+sxTs6m2NNoR0VwHL20HiPPc4+uHa5MXEd3rabT0eL9Tn5/XlYSgFw2KV5Tv fvNwh+ewTLox7mRK6cbwj2UfHOXDOzv/S355sOMWTtOXorif4S9DVkHWn5LL3dZRp0Xx TBPc2dpUAnxatHcoyQAvcJA1f4tIZSG1fOCTjWJB6RdZxnKXFFkY0jf9OaZK3l10AekF ao/w== X-Gm-Message-State: AD7BkJLIdNOAcXP5y3/VOPm2LzDdVaFxM2CVGwe+oNcySt9au16jFLdZNdc1xRBuBSpCpeqS X-Received: by 10.112.16.168 with SMTP id h8mr5330756lbd.90.1456747413805; Mon, 29 Feb 2016 04:03:33 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id wj2sm3889456lbb.5.2016.02.29.04.03.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Feb 2016 04:03:33 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Subject: [PATCH v4 1/4] ACPI: parse SPCR and enable matching console Date: Mon, 29 Feb 2016 15:02:29 +0300 Message-Id: <1456747355-15692-2-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456747355-15692-1-git-send-email-aleksey.makarov@linaro.org> References: <1456747355-15692-1-git-send-email-aleksey.makarov@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160229_040357_161604_2FE188A3 X-CRM114-Status: GOOD ( 24.83 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell King , Peter Hurley , Graeme Gregory , Greg Kroah-Hartman , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Leif Lindholm , Aleksey Makarov , Yury Norov , Christopher Covington , linux-serial@vger.kernel.org, Jiri Slaby , Len Brown , Al Stone , linux-arm-kernel@lists.infradead.org, "Zheng, Lv" MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP '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 | 116 +++++++++++++++++++++++++++++++++++++++ drivers/tty/serial/serial_core.c | 14 ++++- include/linux/acpi.h | 10 ++++ 5 files changed, 142 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..c460cb1 --- /dev/null +++ b/drivers/acpi/spcr.c @@ -0,0 +1,116 @@ +/* + * 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 char *options; +static struct acpi_generic_address address; + +static int __init parse_spcr_init(void) +{ + struct acpi_table_spcr *table; + acpi_size table_size; + acpi_status status; + int err = 0; + + status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0, + (struct acpi_table_header **)&table, + &table_size); + + if (ACPI_FAILURE(status)) { + pr_err("could not get the table\n"); + return -ENOENT; + } + + if (table->header.revision < 2) { + err = -EINVAL; + pr_err("wrong table version\n"); + goto done; + } + + 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; + } + + address = table->serial_port; + +done: + early_acpi_os_unmap_memory((void __iomem *)table, table_size); + return err; +} + +/* + * This function calls __init parse_spcr_init() so it needs __ref. + * It is referenced by the arch_inicall() macros so it will be called + * at initialization and the 'parsed' variable will be set. + * So it's safe to make it __ref. + */ +static int __ref parse_spcr(void) +{ + static bool parsed; + static int parse_error; + + if (!parsed) { + parse_error = parse_spcr_init(); + parsed = true; + } + + return parse_error; +} + +arch_initcall(parse_spcr); + +/** + * 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 || parse_spcr() < 0) + return false; + + if ((address.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY && + address.address == (u64)uport->mapbase) || + (address.space_id == ACPI_ADR_SPACE_SYSTEM_IO && + address.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 true; + } + + return false; +} 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*/