From patchwork Mon Feb 22 13:46:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 62573 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1245327lbl; Mon, 22 Feb 2016 05:48:01 -0800 (PST) X-Received: by 10.98.10.149 with SMTP id 21mr38431448pfk.75.1456148881467; Mon, 22 Feb 2016 05:48:01 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e18si39955101pfj.30.2016.02.22.05.48.01; Mon, 22 Feb 2016 05:48:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755252AbcBVNrx (ORCPT + 7 others); Mon, 22 Feb 2016 08:47:53 -0500 Received: from mail-lf0-f43.google.com ([209.85.215.43]:35149 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755245AbcBVNrv (ORCPT ); Mon, 22 Feb 2016 08:47:51 -0500 Received: by mail-lf0-f43.google.com with SMTP id l143so93918465lfe.2 for ; Mon, 22 Feb 2016 05:47:50 -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=/Gi0YIFeYjPGiX968+GXEWI/862iGu4aO4gNfFgodUM=; b=KssjzSJjD1P0NywVK7JdrQLpw3DuvY6aYFO85jdjLf9q9CNmZmvwiJ9V8X+LVcaHxK 8g85VZN7lMY5+MVNX2G7Buc4wsSeHoAVUk2/EGYIyGeOqEC3dS+W1S0YOG/w1L1t0IMt HBVEZvwlp26I5LiyCzE80ahsPoyVrbdorv/Zw= 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=/Gi0YIFeYjPGiX968+GXEWI/862iGu4aO4gNfFgodUM=; b=Sp8TJDYPEeCafp5SE4d/1rfcxoAwZ3y4DinBd5wBYGeOaEMUkPw0qvtyyA/n/sOalc v+Pt6hrQskTT6YU4uOzos0xRnyy1Hyf1Moi0zrIENUKBgnwwJBuVrSXuEuOoNIuR6ftB w1kqR1tkTtbiho5i5BFKwO6S6dbYsGnJ96FgVZ4SD9Qww1onvxuKklo//S7aY1xfIHlP eap2b+BAY7o86lZfiTqD6E4zcLwiXJIDSOffBJEzCCKP0tUht1tN4F4JVqt5X8g94sPI 3CZpQDQKEnbumxxnFY1mmWjMW1LZIjyrFdeKxRvyBA9w6UaWo4L0muNyVhHL+2N+Ff4V rj/w== X-Gm-Message-State: AG10YOSbzqUBMbYW6eRnHcvAWi4hYa12EjZk3I7fl7gYC27nfhJbCoKpvv+kT0F62wDicPjg X-Received: by 10.25.152.135 with SMTP id a129mr8822913lfe.40.1456148869907; Mon, 22 Feb 2016 05:47:49 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id s5sm2564633lbr.12.2016.02.22.05.47.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 05:47:49 -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 , Jonathan Corbet , Jiri Slaby , linux-doc@vger.kernel.org Subject: [PATCH 6/8] ACPI: serial: implement earlycon on ACPI DBG2 port Date: Mon, 22 Feb 2016 16:46:54 +0300 Message-Id: <1456148818-26257-7-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456148818-26257-1-git-send-email-aleksey.makarov@linaro.org> References: <1456148818-26257-1-git-send-email-aleksey.makarov@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 | 56 +++++++++++++++++++++++++++++++++++++ include/linux/acpi_dbg2.h | 20 +++++++++++++ 3 files changed, 79 insertions(+) -- 2.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 9a53c92..4949ebb 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -1058,6 +1058,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 05f9e4b..3d11248 100644 --- a/drivers/tty/serial/earlycon.c +++ b/drivers/tty/serial/earlycon.c @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef CONFIG_FIX_EARLYCON_MEM #include @@ -186,6 +187,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) { @@ -198,6 +201,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; @@ -228,3 +236,51 @@ int __init of_setup_earlycon(unsigned long addr, register_console(early_console_dev.con); return 0; } + +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; +} diff --git a/include/linux/acpi_dbg2.h b/include/linux/acpi_dbg2.h index 465afcb..9b96de2 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 __init 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