From patchwork Tue Mar 22 10:46:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 8639881 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 D4F76C0553 for ; Tue, 22 Mar 2016 10:51:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C6E8B2039D for ; Tue, 22 Mar 2016 10:51:41 +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 6A21420390 for ; Tue, 22 Mar 2016 10:51:40 +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 1aiJss-00017M-Vn; Tue, 22 Mar 2016 10:49:59 +0000 Received: from mail-lb0-x234.google.com ([2a00:1450:4010:c04::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aiJs9-0008Q2-6t for linux-arm-kernel@lists.infradead.org; Tue, 22 Mar 2016 10:49:19 +0000 Received: by mail-lb0-x234.google.com with SMTP id qe11so101136769lbc.3 for ; Tue, 22 Mar 2016 03:48:55 -0700 (PDT) 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=J+C6ku86FZj4jZvdAI3fyp1z569ROqVt/VssHUzOYgg=; b=GOGbQNdPXl3tAmHvpvNCsGQ2wbnxgia5mVywXS+84HZTLCjFdPyJ+vUmnEgRIqXBPw cFR2tVQGOVI0ZN/ZG8HhyR2i5jY+IRndL90QUSRoT4XgaRmAKB0bG4e+b8ZNyFWQZkeX +MeV48UWItz6BVDEeGxmhFNJ9xiQdpDIbUSrg= 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=J+C6ku86FZj4jZvdAI3fyp1z569ROqVt/VssHUzOYgg=; b=REUu38MA69m/nw+2xvXVLpSNnfFcPdDVzREOZWolKBs0EdDzHYczCczWXgx4ciCq+T lOkRkRvrMW9xl/YNazl1ra69DM1AeZYzfHGum1gRah1qR1b28neC3QVST5JZleI0HySX 9iBHCuSY9sPh7xLV978V0laXi+MTJnBtwitv0GjEWiv4q+kK0Y5j5+uNwY6KAIJtxXx8 +86KTfG7qEIJuG+8KJAooUjcaDWxXq4ZwrOhp6wv0EprceCdvZ9ZS6gzbP7GrxkbNGwa cL8eK+nwefzOommhhibgSmV7jimyzdtl+zuiqcoVAMKVWTT/nXSU+FaK1d7c/r9PD1PY axKg== X-Gm-Message-State: AD7BkJLRDNbfihJurwSmzRLVdiGsiRyDpWWBscbxG4Le6/e0fXD/D7LWgyK1QYXf2rEPMMRw X-Received: by 10.25.30.73 with SMTP id e70mr12958397lfe.13.1458643734093; Tue, 22 Mar 2016 03:48:54 -0700 (PDT) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id l5sm5022910lfd.22.2016.03.22.03.48.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 03:48:53 -0700 (PDT) From: Aleksey Makarov To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Len Brown Subject: [PATCH v5 3/6] ACPI: parse SPCR and enable matching console Date: Tue, 22 Mar 2016 13:46:30 +0300 Message-Id: <1458643595-14719-4-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1458643595-14719-1-git-send-email-aleksey.makarov@linaro.org> References: <1458643595-14719-1-git-send-email-aleksey.makarov@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160322_034913_799105_366EB0D9 X-CRM114-Status: GOOD ( 20.80 ) 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 , linux-kernel@vger.kernel.org, Leif Lindholm , linux-acpi@vger.kernel.org, Aleksey Makarov , Yury Norov , Christopher Covington , linux-serial@vger.kernel.org, Jiri Slaby , 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, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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, setup earlycon and enable the specified console. 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 --- drivers/acpi/Kconfig | 3 ++ drivers/acpi/Makefile | 1 + drivers/acpi/spcr.c | 102 ++++++++++++++++++++++++++++++++++++++++++ drivers/tty/serial/earlycon.c | 13 ++++-- include/linux/acpi.h | 8 ++++ 5 files changed, 123 insertions(+), 4 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..1ec82f9 --- /dev/null +++ b/drivers/acpi/spcr.c @@ -0,0 +1,102 @@ +/* + * 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 bool init_earlycon; + +void __init init_spcr_earlycon(void) +{ + init_earlycon = true; +} + +int __init parse_spcr(void) +{ + static char opts[64]; + struct acpi_table_spcr *table; + acpi_size table_size; + acpi_status status; + char *uart; + char *iotype; + int baud_rate; + int err = 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; + } + + sprintf(opts, "%s,%s,0x%llx,%d", uart, iotype, + table->serial_port.address, baud_rate); + + pr_info("console: %s", opts); + + if (init_earlycon) + 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 d217366..ec030c9 100644 --- a/drivers/tty/serial/earlycon.c +++ b/drivers/tty/serial/earlycon.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef CONFIG_FIX_EARLYCON_MEM #include @@ -206,11 +207,15 @@ static int __init param_setup_earlycon(char *buf) int err; /* - * Just 'earlycon' is a valid param for devicetree earlycons; - * don't generate a warning from parse_early_params() in that case + * Just 'earlycon' is a valid param for devicetree and ACPI SPCR + * earlycons; don't generate a warning from parse_early_params() + * in that case */ - if (!buf || !buf[0]) - return early_init_dt_scan_chosen_serial(); + if (!buf || !buf[0]) { + init_spcr_earlycon(); + early_init_dt_scan_chosen_serial(); + return 0; + } err = setup_earlycon(buf); if (err == -ENOENT || err == -EALREADY) diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 06ed7e5..ebbb212 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 init_spcr_earlycon(void); +#else +static inline int parse_spcr(void) { return 0; } +static inline void init_spcr_earlycon(void) {} +#endif + #endif /*_LINUX_ACPI_H*/