From patchwork Wed Feb 24 17:10:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 8410011 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0A28D9F372 for ; Wed, 24 Feb 2016 17:14:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 03FEC202EB for ; Wed, 24 Feb 2016 17:14:25 +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 4C40E2034E for ; Wed, 24 Feb 2016 17:14:22 +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 1aYczO-0007p7-BA; Wed, 24 Feb 2016 17:12:38 +0000 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aYcyC-000784-1r for linux-arm-kernel@lists.infradead.org; Wed, 24 Feb 2016 17:11:30 +0000 Received: by mail-lf0-x232.google.com with SMTP id l143so16254426lfe.2 for ; Wed, 24 Feb 2016 09:11:05 -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=wXfXIA/H1MLOEJF42bPtnKdl6e1AHZKwI9D7O1HjWZU=; b=CVLq+J4Wrd3x/70IKVCuc9fbv1gLdLff3rjTpNhtgyTQY6mP2g6u1Mss45MYNlgsmr JaQoIpultm29FwBml7RnYtb2TM63JdHxkpU0vl+l4pKHZNQWRbO5MP6BKl+uY5VPUbqu /o8I4sZUaxpsWu+CQxpjYyXTHjSCozkCEQkaA= 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=wXfXIA/H1MLOEJF42bPtnKdl6e1AHZKwI9D7O1HjWZU=; b=gOXfdvcSAarHxG8KeEqdWc/CwgpglFfL4rWmr+gA0RQ5zsiSYmCPUP5E0Dq+Ysg+Xa MCROxgi4SSVXnkIMevVakxbGCQD0DpptKerGVXRz0ARMa1OhyzQiwG6qp7W+N69mBiyf HlqKxhmJU6zcoS1HGqTNpb/Gim4Deyks4III9ZOQTbajykpTKE3OSfm/G3R13GEufWId mjItzrrBcVjAcTzamvTqq5vNy/tO25bZfrzP6RBYnGmWVK1uN1Sa1LvkrCx0fVdQRCLW lbNiwoQxQFjQWCE9MObjU0E12oaRCy0hP8pDFFteET/L8P7rYObOFYf0pZPj/f3Hacx/ lbZg== X-Gm-Message-State: AG10YOTs4fHrfRR1gdSCQXfw/2PFecGS7AfYIJqOp2A1vGZBkaF0Nkx6V+j9bhN/x8m/X3UO X-Received: by 10.25.23.210 with SMTP id 79mr3703655lfx.37.1456333864653; Wed, 24 Feb 2016 09:11:04 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id ne8sm509556lbc.21.2016.02.24.09.11.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Feb 2016 09:11:04 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Subject: [PATCH v2 6/8] ACPI: serial: implement earlycon on ACPI DBG2 port Date: Wed, 24 Feb 2016 20:10:15 +0300 Message-Id: <1456333819-13482-7-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456333819-13482-1-git-send-email-aleksey.makarov@linaro.org> References: <1456333819-13482-1-git-send-email-aleksey.makarov@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160224_091124_895481_6C76F853 X-CRM114-Status: GOOD ( 17.95 ) 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 , Graeme Gregory , Jonathan Corbet , Greg Kroah-Hartman , linux-doc@vger.kernel.org, "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Leif Lindholm , Aleksey Makarov , Christopher Covington , linux-serial@vger.kernel.org, Jiri Slaby , Al Stone , linux-arm-kernel@lists.infradead.org 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 Add ACPI_DBG2_EARLYCON_DECLARE() macros that declares an earlycon on the serial port specified in the DBG2 ACPI table. Pass the string "earlycon=acpi_dbg2" to the kernel to activate it. Callbacks for EARLYCON_DECLARE() and OF_EARLYCON_DECLARE() can also be used for this macros. Signed-off-by: Aleksey Makarov --- Documentation/kernel-parameters.txt | 3 ++ drivers/tty/serial/earlycon.c | 60 +++++++++++++++++++++++++++++++++++++ include/linux/acpi_dbg2.h | 20 +++++++++++++ 3 files changed, 83 insertions(+) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 1fee970..22600e0 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -1069,6 +1069,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. A valid base address must be provided, and the serial port must already be setup and configured. + acpi_dbg2 + Use serial port specified by the DBG2 ACPI table. + earlyprintk= [X86,SH,BLACKFIN,ARM,M68k] earlyprintk=vga earlyprintk=efi diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c index d217366..9ba3a04 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 @@ -200,6 +201,8 @@ int __init setup_earlycon(char *buf) return -ENOENT; } +static bool setup_dbg2_earlycon; + /* early_param wrapper for setup_earlycon() */ static int __init param_setup_earlycon(char *buf) { @@ -212,6 +215,11 @@ static int __init param_setup_earlycon(char *buf) if (!buf || !buf[0]) return early_init_dt_scan_chosen_serial(); + if (!strcmp(buf, "acpi_dbg2")) { + setup_dbg2_earlycon = true; + return 0; + } + err = setup_earlycon(buf); if (err == -ENOENT || err == -EALREADY) return 0; @@ -286,3 +294,55 @@ int __init of_setup_earlycon(const struct earlycon_id *match, } #endif /* CONFIG_OF_EARLY_FLATTREE */ + +#ifdef CONFIG_ACPI_DBG2_TABLE + +int __init acpi_setup_earlycon(struct acpi_dbg2_device *device, void *d) +{ + int err; + struct uart_port *port = &early_console_dev.port; + int (*setup)(struct earlycon_device *, const char *) = d; + struct acpi_generic_address *reg; + + if (!setup_dbg2_earlycon) + return -ENODEV; + + if (device->register_count < 1) + return -ENODEV; + + if (device->base_address_offset >= device->length) + return -EINVAL; + + reg = (void *)device + device->base_address_offset; + + if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY && + reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO) + return -EINVAL; + + spin_lock_init(&port->lock); + port->uartclk = BASE_BAUD * 16; + + if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { + if (device->port_type == ACPI_DBG2_ARM_SBSA_32BIT) + port->iotype = UPIO_MEM32; + else + port->iotype = UPIO_MEM; + port->mapbase = reg->address; + port->membase = earlycon_map(reg->address, SZ_4K); + } else { + port->iotype = UPIO_PORT; + port->iobase = reg->address; + } + + early_console_dev.con->data = &early_console_dev; + err = setup(&early_console_dev, NULL); + if (err < 0) + return err; + if (!early_console_dev.con->write) + return -ENODEV; + + register_console(early_console_dev.con); + return 0; +} + +#endif /* CONFIG_ACPI_DBG2_TABLE */ diff --git a/include/linux/acpi_dbg2.h b/include/linux/acpi_dbg2.h index 125ae7e..b653752 100644 --- a/include/linux/acpi_dbg2.h +++ b/include/linux/acpi_dbg2.h @@ -37,12 +37,32 @@ int acpi_dbg2_setup(struct acpi_table_header *header, const void *data); ACPI_DECLARE_PROBE_ENTRY(dbg2, name, ACPI_SIG_DBG2, \ acpi_dbg2_setup, &__acpi_dbg2_data_##name) +int acpi_setup_earlycon(struct acpi_dbg2_device *device, void *d); + +/** + * ACPI_DBG2_EARLYCON_DECLARE() - Define handler for ACPI GDB2 serial port + * @name: Identifier to compose name of table data + * @subtype: Subtype of the port + * @console_setup: Function to be called to setup the port + * + * Type of the console_setup() callback is + * int (*setup)(struct earlycon_device *, const char *) + * It's the type of callback of of_setup_earlycon(). + */ +#define ACPI_DBG2_EARLYCON_DECLARE(name, subtype, console_setup) \ + ACPI_DBG2_DECLARE(name, ACPI_DBG2_SERIAL_PORT, subtype, \ + acpi_setup_earlycon, console_setup) + #else #define ACPI_DBG2_DECLARE(name, type, subtype, setup_fn, data_ptr) \ static const void *__acpi_dbg_data_##name[] \ __used __initdata = { (void *)setup_fn, (void *)data_ptr } +#define ACPI_DBG2_EARLYCON_DECLARE(name, subtype, console_setup) \ + static const void *__acpi_dbg_data_serial_##name[] \ + __used __initdata = { (void *)console_setup } + #endif #endif