From patchwork Thu May 21 08:32:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fu Wei Fu X-Patchwork-Id: 48852 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 459B921411 for ; Thu, 21 May 2015 08:34:44 +0000 (UTC) Received: by lbos2 with SMTP id s2sf4606356lbo.2 for ; Thu, 21 May 2015 01:34:43 -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=Nxn6VfW+Bi/LHzC3v5fx3/DIVe6KSwc5SGTSF8R5Ef4=; b=Tbv3pFgeiw22murwCNO5c30G5Oq7RNxPBu8e3aMS/p3Nm2rutWag1Vaw/dKaeXQqTI MoeSmPHWwVlF9NLBl2IHQGopTdc+1ywSTqkrfZSobk/WrWN4QFDeeozOqXs0DHzA2gx5 NhGM8IXMDgRVVVBrP1H6njKMP6tlbDyrg+AJdFZ1x7CsOpJ2C7MeVY1ihwZ0+p/QkwAV Wm7K99uWPZcPucv2PPkn/w05pcpguwIf6Onww+gjwrDteHBBO7mQ3BFXpb7qjUnLvZyh GeUbY3hzf14rrBqxghbthfAOQoGiZUjFUbw1qVJPxYxgGzgjsw40/8V/nP8oHIX7W+q3 Q6mA== X-Gm-Message-State: ALoCoQnmJHtFrAGq+LaHhSZzHJE9zxyDR5pyJFO7RquI+E5yBD+faxBr/d4E8MKQ7TY/YGXFXSPf X-Received: by 10.152.26.134 with SMTP id l6mr1632295lag.10.1432197283297; Thu, 21 May 2015 01:34:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.168 with SMTP id kz8ls257254lac.105.gmail; Thu, 21 May 2015 01:34:43 -0700 (PDT) X-Received: by 10.152.23.4 with SMTP id i4mr1231748laf.51.1432197283123; Thu, 21 May 2015 01:34:43 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id k5si9730650lag.119.2015.05.21.01.34.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 May 2015 01:34:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbbqq2 with SMTP id qq2so12661174lbb.3 for ; Thu, 21 May 2015 01:34:43 -0700 (PDT) X-Received: by 10.112.150.100 with SMTP id uh4mr1233858lbb.112.1432197283003; Thu, 21 May 2015 01:34:43 -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.108.230 with SMTP id hn6csp399319lbb; Thu, 21 May 2015 01:34:41 -0700 (PDT) X-Received: by 10.70.42.104 with SMTP id n8mr3437417pdl.88.1432197271867; Thu, 21 May 2015 01:34:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si30555742pbz.8.2015.05.21.01.34.30; Thu, 21 May 2015 01:34:31 -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 S1755703AbbEUIeP (ORCPT + 28 others); Thu, 21 May 2015 04:34:15 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:35369 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755015AbbEUIeF (ORCPT ); Thu, 21 May 2015 04:34:05 -0400 Received: by pdea3 with SMTP id a3so100566329pde.2 for ; Thu, 21 May 2015 01:34:04 -0700 (PDT) X-Received: by 10.70.91.37 with SMTP id cb5mr3334717pdb.151.1432197244684; Thu, 21 May 2015 01:34:04 -0700 (PDT) Received: from localhost.localdomain ([205.147.105.74]) by mx.google.com with ESMTPSA id zf1sm18415820pbc.43.2015.05.21.01.33.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 May 2015 01:34:03 -0700 (PDT) From: fu.wei@linaro.org To: Suravee.Suthikulpanit@amd.com, 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, hanjun.guo@linaro.org, timur@codeaurora.org, ashwin.chaugule@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, Fu Wei Subject: [PATCH v2 7/7] ACPI: import watchdog info of GTDT into platform device Date: Thu, 21 May 2015 16:32:36 +0800 Message-Id: <1432197156-16947-8-git-send-email-fu.wei@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432197156-16947-1-git-send-email-fu.wei@linaro.org> References: <=fu.wei@linaro.org> <1432197156-16947-1-git-send-email-fu.wei@linaro.org> 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.217.177 as permitted sender) smtp.mail=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 Parse SBSA Generic Watchdog Structure in GTDT table of ACPI, and create a platform device with that information. This platform device can be used by the ARM SBSA Generic Watchdog driver. Signed-off-by: Fu Wei --- arch/arm64/kernel/acpi.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index 8b83955..1ed11fd 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -343,3 +344,138 @@ void __init acpi_gic_init(void) early_acpi_os_unmap_memory((char *)table, tbl_size); } + +static int __init acpi_gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd, + int index) +{ + struct platform_device *pdev; + struct resource *res; + u32 gsi, flags; + int irq, trigger, polarity; + resource_size_t rf_base_phy, cf_base_phy; + int err = -ENOMEM; + + /* + * Get SBSA Generic Watchdog info + * from a Watchdog GT type structure in GTDT + */ + rf_base_phy = (resource_size_t)wd->refresh_frame_address; + cf_base_phy = (resource_size_t)wd->control_frame_address; + gsi = wd->timer_interrupt; + flags = wd->timer_flags; + + pr_info("GTDT: a Watchdog GT structure(0x%llx/0x%llx gsi:%u flags:0x%x)\n", + rf_base_phy, cf_base_phy, gsi, flags); + + if (!(rf_base_phy && cf_base_phy && gsi)) { + pr_err("GTDT: failed geting the device info.\n"); + return -EINVAL; + } + + trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE + : ACPI_LEVEL_SENSITIVE; + polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW + : ACPI_ACTIVE_HIGH; + irq = acpi_register_gsi(NULL, gsi, trigger, polarity); + if (irq < 0) { + pr_err("GTDT: failed to register GSI of the Watchdog GT.\n"); + return -EINVAL; + } + + pdev = platform_device_alloc("sbsa-gwdt", index); + if (!pdev) + goto err_unregister_gsi; + + res = kcalloc(3, sizeof(*res), GFP_KERNEL); + if (!res) + goto err_device_put; + + res[0].start = rf_base_phy; + res[0].end = rf_base_phy + SZ_4K - 1; + res[0].name = "refresh"; + res[0].flags = IORESOURCE_MEM; + + res[1].start = cf_base_phy; + res[1].end = cf_base_phy + SZ_4K - 1; + res[1].name = "control"; + res[1].flags = IORESOURCE_MEM; + + res[2].start = irq; + res[2].end = res[2].start; + res[2].name = "ws0"; + res[2].flags = IORESOURCE_IRQ; + + err = platform_device_add_resources(pdev, res, 3); + if (err) + goto err_free_res; + + err = platform_device_add(pdev); + if (err) + goto err_free_res; + + return 0; + +err_free_res: + kfree(res); +err_device_put: + platform_device_put(pdev); +err_unregister_gsi: + acpi_unregister_gsi(gsi); + + return err; +} + +/* Initialize SBSA generic Watchdog platform device info from GTDT */ +static int __init acpi_gtdt_sbsa_gwdt_init(struct acpi_table_header *table) +{ + struct acpi_table_gtdt *gtdt; + struct acpi_gtdt_header *header; + void *gtdt_subtable; + int i, gwdt_index; + int ret = 0; + + if (table->revision < 2) { + pr_info("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 = acpi_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; +} + +/* Initialize the SBSA Generic Watchdog presented in GTDT */ +static int __init acpi_gtdt_init(void) +{ + if (acpi_disabled) + return 0; + + return acpi_table_parse(ACPI_SIG_GTDT, acpi_gtdt_sbsa_gwdt_init); +} + +arch_initcall(acpi_gtdt_init);