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: 53265 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 71F6622B05 for ; Tue, 8 Sep 2015 12:44:37 +0000 (UTC) Received: by wisv5 with SMTP id v5sf36453238wis.0 for ; Tue, 08 Sep 2015 05:44:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=vvOIkEfTdgcczBGz/P193+qo/M4PYEPOyxgX42mx8So=; b=jsA2xoDVxxCv8XM/O7Q7+PlpsGAzSDI9wP7W56sxEVyTd+SQXYfGtDrtbek5XTkZj6 5Y59JrS59DQVkyffeCIJ7fRbqxFA5+QQm/x2U76xUIyYNXgeqsJo6YqvOK0KOSQl6Y+c 3CYIz5zcIZK/M197VsHFIDvyZfOs4AAWQKFTD8BRYxPIvE+PgnlMJ0CtM63Ityr4+io7 /Nj9phNt7Xdv/lVP7GeDFXth/IbLdbGZeqva3szKkgQ1RTi7EC0+x9b/qEEKmfvLvqom Zgo3pPfB3Fn9mwTIwTF9ET/owotBqRCov9Ee7uCRYx6QxbQxfQoBaVPs3f+I/EgNOexR qVzw== X-Gm-Message-State: ALoCoQmv4a5So7pFju/XgJtMK5RNIZ79PTQrAfIMzxXN7Rkw+U0UsHi0q14B4VnVE2Kyrf2N7BHg X-Received: by 10.152.21.233 with SMTP id y9mr6500797lae.5.1441716276729; Tue, 08 Sep 2015 05:44:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.137 with SMTP id d9ls230061laf.42.gmail; Tue, 08 Sep 2015 05:44:36 -0700 (PDT) X-Received: by 10.152.23.199 with SMTP id o7mr22065121laf.22.1441716276577; Tue, 08 Sep 2015 05:44:36 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id vs10si3116821lbb.102.2015.09.08.05.44.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2015 05:44:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbcao8 with SMTP id ao8so52351834lbc.3 for ; Tue, 08 Sep 2015 05:44:36 -0700 (PDT) X-Received: by 10.112.151.106 with SMTP id up10mr18343680lbb.106.1441716276409; Tue, 08 Sep 2015 05:44:36 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp951567lbq; Tue, 8 Sep 2015 05:44:35 -0700 (PDT) X-Received: by 10.107.31.72 with SMTP id f69mr42469864iof.105.1441716272031; Tue, 08 Sep 2015 05:44:32 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cl7si5315459pdb.169.2015.09.08.05.44.31; Tue, 08 Sep 2015 05:44:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754696AbbIHMoJ (ORCPT + 8 others); Tue, 8 Sep 2015 08:44:09 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:35840 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754606AbbIHMnw (ORCPT ); Tue, 8 Sep 2015 08:43:52 -0400 Received: by wicgb1 with SMTP id gb1so76663396wic.1 for ; Tue, 08 Sep 2015 05:43:50 -0700 (PDT) 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 Cc: mark.rutland@arm.com, al.stone@linaro.org, torez@redhat.com, jcm@redhat.com, graeme.gregory@linaro.org, linaro-acpi@lists.linaro.org, lv.zheng@intel.com 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> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: leif.lindholm@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 \