From patchwork Mon Aug 24 17:01:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fu Wei Fu X-Patchwork-Id: 52642 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id DEF9122E9E for ; Mon, 24 Aug 2015 17:04:09 +0000 (UTC) Received: by lbbpd10 with SMTP id pd10sf42615433lbb.3 for ; Mon, 24 Aug 2015 10:04:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Ld9eypAS3TNRXl8Jn1H9h9ZtSi7AM075Z6hLsBKtMTg=; b=CzH/RGaHhWihYq18nrpEmEQys903imb4CC/PE+BpyCteBRB/cC1IguZq304jAV2EGE GU2EgXo1xAY52vMYQr0SxO4cGP8Dg6/V7ReMWfNHs+ZCM2EW8LMV1yP5pLT4A9EtmJBY 6M0slQKnVgGv4Kd68xjARMG2kLZwaCcQQ0ymZmtxFvNsLwmFBwcyYI3OQYBMdmAnSSPf ZOhbQFam4ImXZYGTAweEgk7InELuVR/6y2JvoXdKRjIsjOuQzMegHgsJXZeGeNlKYTJP ufwT+WZ3CH1OYt493GFTWWtdYWUWpI25OwsF7Th0arz2RD7eiSscMeXo7Yx2BXfpWMPl xiNw== X-Gm-Message-State: ALoCoQmcCHQRElXKPeClc841U6hmKRDP1Otjou5i9kzRsBbx0NUxkMPG0Md3u5e7N379ibFk6fZh X-Received: by 10.112.16.200 with SMTP id i8mr7114424lbd.20.1440435848875; Mon, 24 Aug 2015 10:04:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.242.2 with SMTP id wm2ls526825lac.38.gmail; Mon, 24 Aug 2015 10:04:08 -0700 (PDT) X-Received: by 10.112.160.98 with SMTP id xj2mr21735138lbb.124.1440435848701; Mon, 24 Aug 2015 10:04:08 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id o7si13668873lbw.36.2015.08.24.10.04.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Aug 2015 10:04:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by lalv9 with SMTP id v9so81668689lal.0 for ; Mon, 24 Aug 2015 10:04:08 -0700 (PDT) X-Received: by 10.112.168.100 with SMTP id zv4mr20905892lbb.117.1440435848255; Mon, 24 Aug 2015 10:04:08 -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.162.200 with SMTP id yc8csp2610002lbb; Mon, 24 Aug 2015 10:04:05 -0700 (PDT) X-Received: by 10.70.47.232 with SMTP id g8mr47303235pdn.67.1440435845727; Mon, 24 Aug 2015 10:04:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fi2si28320638pbd.80.2015.08.24.10.03.35; Mon, 24 Aug 2015 10:04:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 S1755314AbbHXRDU (ORCPT + 28 others); Mon, 24 Aug 2015 13:03:20 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34675 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755297AbbHXRDQ (ORCPT ); Mon, 24 Aug 2015 13:03:16 -0400 Received: by pabzx8 with SMTP id zx8so10678928pab.1 for ; Mon, 24 Aug 2015 10:03:15 -0700 (PDT) X-Received: by 10.68.69.70 with SMTP id c6mr47405934pbu.28.1440435795091; Mon, 24 Aug 2015 10:03:15 -0700 (PDT) Received: from localhost.localdomain (li400-65.members.linode.com. [106.187.50.65]) by smtp.googlemail.com with ESMTPSA id fu4sm17997515pbb.59.2015.08.24.10.03.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Aug 2015 10:03:14 -0700 (PDT) From: fu.wei@linaro.org To: Suravee.Suthikulpanit@amd.com, hanjun.guo@linaro.org, linaro-acpi@lists.linaro.org, linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: tekkamanninja@gmail.com, graeme.gregory@linaro.org, al.stone@linaro.org, arnd@arndb.de, linux@roeck-us.net, vgandhi@codeaurora.org, wim@iguana.be, jcm@redhat.com, leo.duran@amd.com, corbet@lwn.net, mark.rutland@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, rjw@rjwysocki.net, dyoung@redhat.com, panand@redhat.com, Fu Wei Subject: [PATCH v7 6/8] ACPI: add GTDT table parse driver into ACPI driver Date: Tue, 25 Aug 2015 01:01:21 +0800 Message-Id: <1440435683-7343-7-git-send-email-fu.wei@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440435683-7343-1-git-send-email-fu.wei@linaro.org> References: <=fu.wei@linaro.org> <1440435683-7343-1-git-send-email-fu.wei@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: fu.wei@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.215.52 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: , From: Fu Wei This driver adds support for parsing SBSA Generic Watchdog Structure in GTDT, and creating a platform device with that information. This allows the operating system to obtain device data from the resource of platform device. The platform device named "sbsa-gwdt" can be used by the ARM SBSA Generic Watchdog driver. Signed-off-by: Fu Wei Signed-off-by: Hanjun Guo --- drivers/acpi/Kconfig | 9 ++++ drivers/acpi/Makefile | 1 + drivers/acpi/gtdt.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 114cf48..2e7e162 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -479,4 +479,13 @@ config XPOWER_PMIC_OPREGION endif +config ACPI_GTDT + bool "ACPI GTDT Support" + depends on ARM64 + help + GTDT (Generic Timer Description Table) provides information + for per-processor timers and Platform (memory-mapped) timers + for ARM platforms. Select this option to provide information + needed for the timers init. + endif # ACPI diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 8321430..9a7966e 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -93,5 +93,6 @@ obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o +obj-$(CONFIG_ACPI_GTDT) += gtdt.o video-objs += acpi_video.o video_detect.o diff --git a/drivers/acpi/gtdt.c b/drivers/acpi/gtdt.c new file mode 100644 index 0000000..bbe3a2e --- /dev/null +++ b/drivers/acpi/gtdt.c @@ -0,0 +1,135 @@ +/* + * ARM Specific GTDT table Support + * + * Copyright (C) 2015, Linaro Ltd. + * Author: Fu Wei + * Hanjun Guo + * + * 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. + */ + +#include +#include +#include +#include +#include +#include + +static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags) +{ + int trigger, polarity; + + if (!interrupt) + return 0; + + trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE + : ACPI_LEVEL_SENSITIVE; + + polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW + : ACPI_ACTIVE_HIGH; + + return acpi_register_gsi(NULL, interrupt, trigger, polarity); +} + +/* + * Initialize a SBSA generic Watchdog platform device info from GTDT + * According to SBSA specification the size of refresh and control + * frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF). + */ +static int __init gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd, + int index) +{ + struct platform_device *pdev; + int irq = map_generic_timer_interrupt(wd->timer_interrupt, + wd->timer_flags); + struct resource res[] = { + DEFINE_RES_IRQ(irq), + DEFINE_RES_MEM(wd->control_frame_address, SZ_4K), + DEFINE_RES_MEM(wd->refresh_frame_address, SZ_4K), + }; + + pr_debug("GTDT: a Watchdog GT(0x%llx/0x%llx gsi:%u flags:0x%x)\n", + wd->refresh_frame_address, wd->control_frame_address, + wd->timer_interrupt, wd->timer_flags); + + if (!(wd->refresh_frame_address && + wd->control_frame_address && + wd->timer_interrupt)) { + pr_err("GTDT: failed geting the device info.\n"); + return -EINVAL; + } + + if (irq < 0) { + pr_err("GTDT: failed to register GSI of the Watchdog GT.\n"); + return -EINVAL; + } + + /* + * Add a platform device named "sbsa-gwdt" to match the platform driver. + * "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog + * The platform driver (like drivers/watchdog/sbsa_gwdt.c)can get device + * info below by matching this name. + */ + pdev = platform_device_register_simple("sbsa-gwdt", index, res, + ARRAY_SIZE(res)); + if (IS_ERR(pdev)) { + acpi_unregister_gsi(wd->timer_interrupt); + return PTR_ERR(pdev); + } + + return 0; +} + +static int __init gtdt_platform_timer_parse(struct acpi_table_header *table) +{ + struct acpi_gtdt_header *header; + struct acpi_table_gtdt *gtdt; + void *gtdt_subtable; + int i, gwdt_index; + int ret = 0; + + if (table->revision < 2) { + pr_warn("GTDT: Revision:%d doesn't support Platform Timers.\n", + table->revision); + return 0; + } + + gtdt = container_of(table, struct acpi_table_gtdt, header); + if (!gtdt->platform_timer_count) { + pr_info("GTDT: No Platform Timer structures.\n"); + return 0; + } + + gtdt_subtable = (void *)gtdt + gtdt->platform_timer_offset; + + for (i = 0, gwdt_index = 0; i < gtdt->platform_timer_count; i++) { + if (gtdt_subtable > (void *)table + table->length) { + pr_err("GTDT: subtable pointer overflows, bad table\n"); + return -EINVAL; + } + header = (struct acpi_gtdt_header *)gtdt_subtable; + if (header->type == ACPI_GTDT_TYPE_WATCHDOG) { + ret = gtdt_import_sbsa_gwdt(gtdt_subtable, gwdt_index); + if (ret) + pr_err("GTDT: failed to import subtable %d\n", + i); + else + gwdt_index++; + } + gtdt_subtable += header->length; + } + + return ret; +} + +static int __init gtdt_platform_timer_init(void) +{ + if (acpi_disabled) + return 0; + + return acpi_table_parse(ACPI_SIG_GTDT, gtdt_platform_timer_parse); +} + +device_initcall(gtdt_platform_timer_init);