From patchwork Wed Jun 29 18:15:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fu.wei@linaro.org X-Patchwork-Id: 9205989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCB2960752 for ; Wed, 29 Jun 2016 18:19:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1BFA284B8 for ; Wed, 29 Jun 2016 18:19:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B67E328673; Wed, 29 Jun 2016 18:19:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 4D6A5284B8 for ; Wed, 29 Jun 2016 18:19:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIK3m-0000gU-Hh; Wed, 29 Jun 2016 18:18:02 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIK2p-0007oI-8z for linux-arm-kernel@lists.infradead.org; Wed, 29 Jun 2016 18:17:05 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0EA758E751; Wed, 29 Jun 2016 18:16:47 +0000 (UTC) Received: from rei-ayanami.redhat.com (vpn1-4-13.pek2.redhat.com [10.72.4.13]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5TIG89d019803; Wed, 29 Jun 2016 14:16:39 -0400 From: fu.wei@linaro.org To: rjw@rjwysocki.net, lenb@kernel.org, daniel.lezcano@linaro.org, tglx@linutronix.de, marc.zyngier@arm.com, hanjun.guo@linaro.org Subject: [PATCH v6 04/10] acpi: Add some basic struct and functions in GTDT driver Date: Thu, 30 Jun 2016 02:15:47 +0800 Message-Id: <1467224153-22873-5-git-send-email-fu.wei@linaro.org> In-Reply-To: <1467224153-22873-1-git-send-email-fu.wei@linaro.org> References: <1467224153-22873-1-git-send-email-fu.wei@linaro.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 29 Jun 2016 18:16:47 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160629_111703_503836_B5868275 X-CRM114-Status: GOOD ( 17.47 ) 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: wei@redhat.com, harba@codeaurora.org, Fu Wei , al.stone@linaro.org, graeme.gregory@linaro.org, linaro-acpi@lists.linaro.org, jcm@redhat.com, timur@codeaurora.org, will.deacon@arm.com, rruigrok@codeaurora.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, wim@iguana.be, arnd@arndb.de, cov@codeaurora.org, Suravee.Suthikulpanit@amd.com, catalin.marinas@arm.com, leo.duran@amd.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fu Wei Signed-off-by: Fu Wei --- drivers/acpi/acpi_gtdt.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/acpi/acpi_gtdt.c b/drivers/acpi/acpi_gtdt.c new file mode 100644 index 0000000..54d7644e --- /dev/null +++ b/drivers/acpi/acpi_gtdt.c @@ -0,0 +1,85 @@ +/* + * ARM Specific GTDT table Support + * + * Copyright (C) 2015, Linaro Ltd. + * Author: Daniel Lezcano + * 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 + +#undef pr_fmt +#define pr_fmt(fmt) "GTDT: " fmt + +typedef struct { + struct acpi_table_gtdt *gtdt; + void *platform_timer_start; + void *gtdt_end; +} acpi_gtdt_desc_t; + +static acpi_gtdt_desc_t acpi_gtdt_desc __initdata; + +static inline void *gtdt_next(void *platform_timer, void *end, int type) +{ + struct acpi_gtdt_header *gh = platform_timer; + + while ((void *)(gh += gh->length) < end) + if (gh->type == type) + return (void *)gh; + return NULL; +} + +#define for_each_gtdt_type(_g, _t) \ + for (_g = acpi_gtdt_desc.platform_timer_start; _g; \ + _g = gtdt_next(_g, acpi_gtdt_desc.gtdt_end, _t)) + +#define for_each_gtdt_timer(_g) \ + for_each_gtdt_type(_g, ACPI_GTDT_TYPE_TIMER_BLOCK) + +#define for_each_gtdt_watchdog(_g) \ + for_each_gtdt_type(_g, ACPI_GTDT_TYPE_WATCHDOG) + +/* + * Get some basic info from GTDT table, and init the global variables above + * for all timers initialization of Generic Timer. + * This function does some validation on GTDT table. + */ +static int __init acpi_gtdt_desc_init(struct acpi_table_header *table) +{ + struct acpi_table_gtdt *gtdt = container_of(table, + struct acpi_table_gtdt, + header); + + acpi_gtdt_desc.gtdt = gtdt; + acpi_gtdt_desc.gtdt_end = (void *)table + table->length; + + if (table->revision < 2) { + pr_info("Revision:%d doesn't support Platform Timers.\n", + table->revision); + return 0; + } + + if (!gtdt->platform_timer_count) { + pr_info("No Platform Timer.\n"); + return 0; + } + + acpi_gtdt_desc.platform_timer_start = (void *)gtdt + + gtdt->platform_timer_offset; + if (acpi_gtdt_desc.platform_timer_start < + (void *)table + sizeof(struct acpi_table_gtdt)) { + pr_err(FW_BUG "Platform Timer pointer error.\n"); + acpi_gtdt_desc.platform_timer_start = NULL; + return -EINVAL; + } + + return gtdt->platform_timer_count; +}