From patchwork Tue Sep 8 12:43:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 7140841 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 688A39F1D5 for ; Tue, 8 Sep 2015 12:47:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5BBEE20628 for ; Tue, 8 Sep 2015 12:47:14 +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 3816920626 for ; Tue, 8 Sep 2015 12:47:13 +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 1ZZIGK-0003Zk-4O; Tue, 08 Sep 2015 12:44:36 +0000 Received: from mail-wi0-f182.google.com ([209.85.212.182]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZZIFw-0003Lv-TC for linux-arm-kernel@lists.infradead.org; Tue, 08 Sep 2015 12:44:14 +0000 Received: by wicfx3 with SMTP id fx3so118714210wic.1 for ; Tue, 08 Sep 2015 05:43:51 -0700 (PDT) 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=b2MVzTb+fOGRkPJy5BjKfdbcYdeZR5ITzFOp1PkKmdo=; b=DkMZvPhB8OJEGB7Z6V9d8uavzKCAXFD+/paVZ9albdYh5C0d0ab3ojTr2OJQ3pKlJW ej5Lj/sGAC6df3jTuMMbQnQidUElOfSgrlbsyWKzfVL6nhQPITnd4xV3lb72zBegbZeD HojCP7fshk3nzYjhYUodK7sD/kOUhNQWKPrxrqQl8BrCuYAQO1gZgs8/bBVKWkHO/tPz jP8mESp1yPsOt1TpAeoy+k5gQ4Thhq3xv9YTDAvH0zq3q9HIjsUEer170g/v5ROPqPk+ fFYW1V/En9QfVOkYDOIdKkc0GdPVv6PP/h1wkxyZusYyxwKsra+xXoIDeoopT8hoKLWy hp+Q== X-Gm-Message-State: ALoCoQnMGgF3KtnFrPRm04dJcVPWtYbyCZvUiuT6AiVBjvT9/JNDiqtKfC2nSmPXHwiLxysv/udY X-Received: by 10.180.74.52 with SMTP id q20mr45499955wiv.94.1441716230572; Tue, 08 Sep 2015 05:43:50 -0700 (PDT) Received: from mohikan.mushroom.smurfnet.nu (cpc4-cmbg17-2-0-cust71.5-4.cable.virginm.net. [86.14.224.72]) by smtp.gmail.com with ESMTPSA id i7sm4696047wib.15.2015.09.08.05.43.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Sep 2015 05:43:50 -0700 (PDT) From: Leif Lindholm To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-serial@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC 3/5] acpi/serial: add DBG2 earlycon support Date: Tue, 8 Sep 2015 13:43:35 +0100 Message-Id: <1441716217-23786-4-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441716217-23786-1-git-send-email-leif.lindholm@linaro.org> References: <1441716217-23786-1-git-send-email-leif.lindholm@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150908_054413_244276_65EDBAA4 X-CRM114-Status: GOOD ( 27.62 ) X-Spam-Score: -2.6 (--) 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: mark.rutland@arm.com, al.stone@linaro.org, graeme.gregory@linaro.org, linaro-acpi@lists.linaro.org, jcm@redhat.com, torez@redhat.com, lv.zheng@intel.com 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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 The ACPI DBG2 table defines a debug console. Add support for parsing it and using it to select earlycon destination when no arguments provided. Signed-off-by: Leif Lindholm --- arch/arm64/kernel/acpi.c | 2 + drivers/acpi/Makefile | 1 + drivers/acpi/console.c | 103 ++++++++++++++++++++++++++++++++++++++++++ drivers/of/fdt.c | 2 +- drivers/tty/serial/earlycon.c | 16 ++++--- include/linux/acpi.h | 4 ++ include/linux/serial_core.h | 9 ++-- 7 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 drivers/acpi/console.c diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index b9a5623..be7600a 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -207,6 +207,8 @@ void __init acpi_boot_table_init(void) if (!param_acpi_force) disable_acpi(); } + + acpi_early_console_probe(); } void __init acpi_gic_init(void) diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index b5e7cd8..a89587d 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -10,6 +10,7 @@ ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT # obj-y += tables.o obj-$(CONFIG_X86) += blacklist.o +obj-y += console.o # # ACPI Core Subsystem (Interpreter) diff --git a/drivers/acpi/console.c b/drivers/acpi/console.c new file mode 100644 index 0000000..a985890 --- /dev/null +++ b/drivers/acpi/console.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2012, Intel Corporation + * Copyright (c) 2015, 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 DEBUG +#define pr_fmt(fmt) "ACPI: " KBUILD_MODNAME ": " fmt + +#include +#include +#include + +#define NUM_ELEMS(x) (sizeof(x) / sizeof(*x)) + +#ifdef CONFIG_SERIAL_EARLYCON +static int use_earlycon __initdata; +static int __init setup_acpi_earlycon(char *buf) +{ + if (!buf) + use_earlycon = 1; + + return 0; +} +early_param("earlycon", setup_acpi_earlycon); + +extern struct earlycon_id __earlycon_table[]; + +static __initdata struct { + int id; + const char *name; +} subtypes[] = { + {0, "uart8250"}, + {1, "uart8250"}, + {2, NULL}, + {3, "pl011"}, +}; + +static int __init acpi_setup_earlycon(unsigned long addr, const char *driver) +{ + const struct earlycon_id *match; + + for (match = __earlycon_table; match->name[0]; match++) + if (strcmp(driver, match->name) == 0) + return setup_earlycon_driver(addr, match->setup); + + return -ENODEV; +} + +static int __init acpi_parse_dbg2(struct acpi_table_header *table) +{ + struct acpi_table_dbg2 *dbg2; + struct acpi_dbg2_device *entry; + void *tbl_end; + + dbg2 = (struct acpi_table_dbg2 *)table; + if (!dbg2) { + pr_debug("DBG2 not present.\n"); + return -ENODEV; + } + + tbl_end = (void *)table + table->length; + + entry = (struct acpi_dbg2_device *)((void *)dbg2 + dbg2->info_offset); + + while (((void *)entry) + sizeof(struct acpi_dbg2_device) < tbl_end) { + struct acpi_generic_address *addr; + + if (entry->revision != 0) { + pr_debug("DBG2 revision %d not supported.\n", + entry->revision); + return -ENODEV; + } + + addr = (void *)entry + entry->base_address_offset; + + pr_debug("DBG2 PROBE - console (%04x:%04x).\n", + entry->port_type, entry->port_subtype); + + if (use_earlycon && + (entry->port_type == ACPI_DBG2_SERIAL_PORT) && + (entry->port_subtype < NUM_ELEMS(subtypes))) + acpi_setup_earlycon(addr->address, + subtypes[entry->port_subtype].name); + + entry = (struct acpi_dbg2_device *) + ((void *)entry + entry->length); + } + + return 0; +} + +int __init acpi_early_console_probe(void) +{ + acpi_table_parse(ACPI_SIG_DBG2, acpi_parse_dbg2); + + return 0; +} +#endif /* CONFIG_SERIAL_EARLYCON */ diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index fcfc4c7..a96209f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -829,7 +829,7 @@ int __init early_init_dt_scan_chosen_serial(void) if (!addr) return -ENXIO; - of_setup_earlycon(addr, match->data); + setup_earlycon_driver(addr, match->data); return 0; } return -ENODEV; diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c index 2bda09a..c063cbb 100644 --- a/drivers/tty/serial/earlycon.c +++ b/drivers/tty/serial/earlycon.c @@ -13,6 +13,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -184,12 +185,16 @@ 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 or ACPI earlycons; + * ACPI cannot be parsed yet, so return without action if enabled. + * Otherwise, attempt initialization using DT. */ - if (!buf || !buf[0]) - if (IS_ENABLED(CONFIG_OF_FLATTREE)) + if (!buf || !buf[0]) { + if (!acpi_disabled) + return 0; + else if (IS_ENABLED(CONFIG_OF_FLATTREE)) return early_init_dt_scan_chosen_serial(); + } err = setup_earlycon(buf); if (err == -ENOENT || err == -EALREADY) @@ -198,8 +203,7 @@ static int __init param_setup_earlycon(char *buf) } early_param("earlycon", param_setup_earlycon); -int __init of_setup_earlycon(unsigned long addr, - int (*setup)(struct earlycon_device *, const char *)) +int __init setup_earlycon_driver(unsigned long addr, earlycon_initfunc_t setup) { int err; struct uart_port *port = &early_console_dev.port; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 7235c48..88cb9c1 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -811,4 +811,8 @@ static inline struct acpi_device *acpi_get_next_child(struct device *dev, #endif +#if defined(CONFIG_ACPI) && defined(CONFIG_SERIAL_EARLYCON) +int __init acpi_early_console_probe(void); +#endif + #endif /*_LINUX_ACPI_H*/ diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 297d4fa..39e99b0 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -339,14 +339,15 @@ struct earlycon_device { unsigned int baud; }; +typedef int (*earlycon_initfunc_t)(struct earlycon_device *, const char *); + struct earlycon_id { - char name[16]; - int (*setup)(struct earlycon_device *, const char *options); + char name[16]; + earlycon_initfunc_t setup; } __aligned(32); extern int setup_earlycon(char *buf); -extern int of_setup_earlycon(unsigned long addr, - int (*setup)(struct earlycon_device *, const char *)); +extern int setup_earlycon_driver(unsigned long addr, earlycon_initfunc_t setup); #define EARLYCON_DECLARE(_name, func) \ static const struct earlycon_id __earlycon_##_name \