From patchwork Wed Jul 13 17:53:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fu Wei Fu X-Patchwork-Id: 71951 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1130275qga; Wed, 13 Jul 2016 10:58:04 -0700 (PDT) X-Received: by 10.66.104.34 with SMTP id gb2mr15855794pab.12.1468432684747; Wed, 13 Jul 2016 10:58:04 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id d10si3340647pat.143.2016.07.13.10.58.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jul 2016 10:58:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org 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 1bNOP1-00086f-L5; Wed, 13 Jul 2016 17:56:55 +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 1bNONv-0006vB-0a for linux-arm-kernel@lists.infradead.org; Wed, 13 Jul 2016 17:55:51 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 DD92DC05972E; Wed, 13 Jul 2016 17:55:29 +0000 (UTC) Received: from rei-ayanami.redhat.com (vpn1-5-133.pek2.redhat.com [10.72.5.133]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6DHs3Np003742; Wed, 13 Jul 2016 13:55:19 -0400 From: fu.wei@linaro.org To: rjw@rjwysocki.net, lenb@kernel.org, daniel.lezcano@linaro.org, tglx@linutronix.de, marc.zyngier@arm.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, hanjun.guo@linaro.org Subject: [PATCH v7 7/9] acpi/arm64: Add memory-mapped timer support in GTDT driver Date: Thu, 14 Jul 2016 01:53:20 +0800 Message-Id: <1468432402-4872-8-git-send-email-fu.wei@linaro.org> In-Reply-To: <1468432402-4872-1-git-send-email-fu.wei@linaro.org> References: <1468432402-4872-1-git-send-email-fu.wei@linaro.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 13 Jul 2016 17:55:30 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160713_105547_424725_08DBD417 X-CRM114-Status: GOOD ( 17.84 ) X-Spam-Score: -6.3 (------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-6.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.132.183.28 listed in wl.mailspike.net] -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [209.132.183.28 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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: linaro-acpi@lists.linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, wim@iguana.be, jslaby@suse.cz, Fu Wei , wei@redhat.com, al.stone@linaro.org, timur@codeaurora.org, linux-acpi@vger.kernel.org, kvalo@codeaurora.org, linux@roeck-us.net, harba@codeaurora.org, julien.grall@arm.com, linux-watchdog@vger.kernel.org, arnd@arndb.de, jcm@redhat.com, cov@codeaurora.org, mchehab@kernel.org, linux-arm-kernel@lists.infradead.org, graeme.gregory@linaro.org, gregkh@linuxfoundation.org, rruigrok@codeaurora.org, leo.duran@amd.com, Suravee.Suthikulpanit@amd.com, akpm@linux-foundation.org, davem@davemloft.net, christoffer.dall@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org From: Fu Wei This driver adds support for parsing memory-mapped timer in GTDT: provide a kernel APIs to parse GT Block Structure in GTDT, export all the info by filling the struct which provided by parameter(pointer of the struct). By this driver, we can add ACPI support for memory-mapped timer in arm_arch_timer drivers, and separate the ACPI GTDT knowledge from it. Signed-off-by: Fu Wei Signed-off-by: Hanjun Guo --- drivers/acpi/arm64/acpi_gtdt.c | 90 ++++++++++++++++++++++++++++++++++++ include/clocksource/arm_arch_timer.h | 15 ++++++ include/linux/acpi.h | 1 + 3 files changed, 106 insertions(+) -- 2.5.5 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/acpi/arm64/acpi_gtdt.c b/drivers/acpi/arm64/acpi_gtdt.c index 9ee977d..ff62953 100644 --- a/drivers/acpi/arm64/acpi_gtdt.c +++ b/drivers/acpi/arm64/acpi_gtdt.c @@ -168,3 +168,93 @@ int __init gtdt_arch_timer_init(struct acpi_table_header *table) return -EINVAL; } + +/* + * Helper function for getting the pointer of a timer frame in GT block. + */ +static void __init *gtdt_gt_timer_frame(struct acpi_gtdt_timer_block *gt_block, + int index) +{ + void *timer_frame = (void *)gt_block + gt_block->timer_offset + + sizeof(struct acpi_gtdt_timer_entry) * index; + + if (timer_frame <= (void *)gt_block + gt_block->header.length - + sizeof(struct acpi_gtdt_timer_entry)) + return timer_frame; + + return NULL; +} + +static int __init gtdt_parse_gt_block(void *platform_timer, int index, + void *data) +{ + struct acpi_gtdt_timer_block *block; + struct acpi_gtdt_timer_entry *frame; + struct gt_block_data *block_data; + int i, j; + + if (!platform_timer || !data) + return -EINVAL; + + block = platform_timer; + block_data = data + sizeof(struct gt_block_data) * index; + + if (!block->block_address || !block->timer_count) { + pr_err(FW_BUG "invalid GT Block data.\n"); + return -EINVAL; + } + block_data->cntctlbase_phy = (phys_addr_t)block->block_address; + block_data->timer_count = block->timer_count; + + /* + * Get the GT timer Frame data for every GT Block Timer + */ + for (i = 0, j = 0; i < block->timer_count; i++) { + frame = gtdt_gt_timer_frame(block, i); + if (!frame || !frame->base_address || !frame->timer_interrupt) { + pr_err(FW_BUG "invalid GT Block Timer data.\n"); + return -EINVAL; + } + block_data->timer[j].frame_nr = frame->frame_number; + block_data->timer[j].cntbase_phy = frame->base_address; + block_data->timer[j].irq = map_generic_timer_interrupt( + frame->timer_interrupt, + frame->timer_flags); + if (frame->virtual_timer_interrupt) + block_data->timer[j].virt_irq = + map_generic_timer_interrupt( + frame->virtual_timer_interrupt, + frame->virtual_timer_flags); + j++; + } + + if (j) + return 0; + + block_data->cntctlbase_phy = (phys_addr_t)NULL; + block_data->timer_count = 0; + + return -EINVAL; +} + +/* + * Get the GT block info for memory-mapped timer from GTDT table. + * Please make sure we have called gtdt_arch_timer_init, because it helps to + * init the global variables. + */ +int __init gtdt_arch_timer_mem_init(struct gt_block_data *data) +{ + void *platform_timer; + int index = 0; + + for_each_platform_timer(platform_timer) { + if (is_timer_block(platform_timer) && + !gtdt_parse_gt_block(platform_timer, index, data)) + index++; + } + + if (index) + pr_info("found %d memory-mapped timer block.\n", index); + + return index; +} diff --git a/include/clocksource/arm_arch_timer.h b/include/clocksource/arm_arch_timer.h index 16dcd10..ece6b3b 100644 --- a/include/clocksource/arm_arch_timer.h +++ b/include/clocksource/arm_arch_timer.h @@ -56,6 +56,8 @@ enum spi_nr { #define ARCH_TIMER_MEM_PHYS_ACCESS 2 #define ARCH_TIMER_MEM_VIRT_ACCESS 3 +#define ARCH_TIMER_MEM_MAX_FRAME 8 + #define ARCH_TIMER_USR_PCT_ACCESS_EN (1 << 0) /* physical counter */ #define ARCH_TIMER_USR_VCT_ACCESS_EN (1 << 1) /* virtual counter */ #define ARCH_TIMER_VIRT_EVT_EN (1 << 2) @@ -71,6 +73,19 @@ struct arch_timer_kvm_info { int virtual_irq; }; +struct gt_timer_data { + int frame_nr; + phys_addr_t cntbase_phy; + int irq; + int virt_irq; +}; + +struct gt_block_data { + phys_addr_t cntctlbase_phy; + int timer_count; + struct gt_timer_data timer[ARCH_TIMER_MEM_MAX_FRAME]; +}; + #ifdef CONFIG_ARM_ARCH_TIMER extern u32 arch_timer_get_rate(void); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 8439579..b1cacbc 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -536,6 +536,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *); int __init gtdt_arch_timer_init(struct acpi_table_header *table); int __init acpi_gtdt_map_ppi(int type); int __init acpi_gtdt_c3stop(void); +int __init gtdt_arch_timer_mem_init(struct gt_block_data *data); #endif #else /* !CONFIG_ACPI */