From patchwork Wed Sep 28 18:17:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: fu.wei@linaro.org X-Patchwork-Id: 9354503 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 976C560757 for ; Wed, 28 Sep 2016 18:22:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 862CA29688 for ; Wed, 28 Sep 2016 18:22:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AAB4297A4; Wed, 28 Sep 2016 18:22:54 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham 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 1356329688 for ; Wed, 28 Sep 2016 18:22:54 +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 1bpJTs-00081d-VG; Wed, 28 Sep 2016 18:21:21 +0000 Received: from mail-pf0-x22b.google.com ([2607:f8b0:400e:c00::22b]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bpJRg-0005VC-LQ for linux-arm-kernel@lists.infradead.org; Wed, 28 Sep 2016 18:19:07 +0000 Received: by mail-pf0-x22b.google.com with SMTP id 21so19922846pfy.0 for ; Wed, 28 Sep 2016 11:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B4+4wKozhoyAHl2viiCszjSYR3DgCKYAbJjKSmXAu/8=; b=AXi6O9w35bxW5f7WAnYAsK7Dx5146WEHzcbmOZLyZpxBCeHH28TUzEkUACdVxRtt0Z 90tx1EfdWED1suW4mPgHEzdUsIc+WRGNAGFV3S8iVhwZAJNZc9jzQA+3OaTG0J1MnFIa lRIgbOA7J8v4sQ3qGc77QvcVTGrkfvebnVBmQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B4+4wKozhoyAHl2viiCszjSYR3DgCKYAbJjKSmXAu/8=; b=hHLEOpdYVQn+oOTydtuvWuwz0sOyXgvdpEBxCqhEjyp7B3UvbHnQAMHKoHmAg3OoPm dgqa/MstnilgfmvaSxBpDsQJxIERdYdgrDyVemO0wu8G/wc8BSRV96WjjF73WqdGRhsH MukJlL5zO+3ejdVYKAdhQcr7smGZUL2xpZ25jAtt2Ir5TbfIcY4KFjq3whLgoLplGYln GPDEZqHSdLNbWc/dtLywzC8UoDJdjzCFdX2hbahPTQ4IPH9EsJ1DH7iQzTJJANNuJV5C i0gZr8ZDFBqIbLsw9NhlfGC42HbhCdr2dHK6Fy1AMZOZ0KtlhgRxNMCwIsvXr/EeAWwt J6HQ== X-Gm-Message-State: AE9vXwP0k1uug3DAdIHu2Ovd/3yhWXd9vQJlQJmqZIbbOWZjCkYo3PMo+2aWl0znZ04yxoyM X-Received: by 10.98.104.71 with SMTP id d68mr59706323pfc.163.1475086725947; Wed, 28 Sep 2016 11:18:45 -0700 (PDT) Received: from Rei-Ayanami.localdomain.localdomain ([67.238.99.186]) by smtp.googlemail.com with ESMTPSA id ak3sm14226365pad.19.2016.09.28.11.18.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Sep 2016 11:18:45 -0700 (PDT) From: fu.wei@linaro.org To: rjw@rjwysocki.net, lenb@kernel.org, daniel.lezcano@linaro.org, tglx@linutronix.de, marc.zyngier@arm.com, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, hanjun.guo@linaro.org Subject: [PATCH v14 8/9] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer Date: Thu, 29 Sep 2016 02:17:16 +0800 Message-Id: <1475086637-1914-9-git-send-email-fu.wei@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475086637-1914-1-git-send-email-fu.wei@linaro.org> References: <1475086637-1914-1-git-send-email-fu.wei@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160928_111904_834947_4DA0BB94 X-CRM114-Status: GOOD ( 18.89 ) 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, Fu Wei , wei@redhat.com, al.stone@linaro.org, tn@semihalf.com, timur@codeaurora.org, linux-acpi@vger.kernel.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, linux-arm-kernel@lists.infradead.org, graeme.gregory@linaro.org, rruigrok@codeaurora.org, leo.duran@amd.com, Suravee.Suthikulpanit@amd.com, christoffer.dall@linaro.org 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 The patch add memory-mapped timer register support by using the information provided by the new GTDT driver of ACPI. Signed-off-by: Fu Wei --- drivers/clocksource/arm_arch_timer.c | 92 +++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 7 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index e78095f..8482fba 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -660,6 +660,7 @@ out: static int __init arch_timer_mem_register(struct device_node *np, void *frame) { struct device_node *frame_node = NULL; + struct gt_timer_data *frame_data = NULL; struct arch_timer *t; void __iomem *base; irq_handler_t func; @@ -678,8 +679,17 @@ static int __init arch_timer_mem_register(struct device_node *np, void *frame) else irq = irq_of_parse_and_map(frame_node, PHYS_SPI); } else { - pr_err("Device node is missing.\n"); - return -EINVAL; + frame_data = (struct gt_timer_data *)frame; + /* + * According to ARMv8 Architecture Reference Manual(ARM), + * the size of CNTBaseN frames of memory-mapped timer + * is SZ_4K(Offset 0x000 – 0xFFF). + */ + base = ioremap(frame_data->cntbase_phy, SZ_4K); + if (arch_timer_mem_use_virtual) + irq = frame_data->virtual_irq; + else + irq = frame_data->irq; } if (!base) { @@ -840,13 +850,16 @@ static int __init arch_timer_of_init(struct device_node *np) CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init); CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init); -static int __init get_cnttidr(struct device_node *np, u32 *cnttidr) +static int __init get_cnttidr(struct device_node *np, + struct gt_block_data *gt_block, u32 *cnttidr) { if (!cnttidr) return -EINVAL; if (np) cntctlbase = of_iomap(np, 0); + else if (gt_block) + cntctlbase = ioremap(gt_block->cntctlbase_phy, SZ_4K); else return -EINVAL; @@ -885,7 +898,7 @@ static int __init arch_timer_mem_init(struct device_node *np) arch_timers_present |= ARCH_MEM_TIMER; - ret = get_cnttidr(np, &cnttidr); + ret = get_cnttidr(np, NULL, &cnttidr); if (ret) return ret; @@ -921,7 +934,72 @@ CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem", arch_timer_mem_init); #ifdef CONFIG_ACPI_GTDT -/* Initialize per-processor generic timer */ +static struct gt_timer_data __init *arch_timer_mem_get_timer( + struct gt_block_data *gt_blocks) +{ + struct gt_block_data *gt_block = gt_blocks; + struct gt_timer_data *best_frame = NULL; + u32 cnttidr; + int i; + + if (get_cnttidr(NULL, gt_block, &cnttidr)) + return NULL; + /* + * Try to find a virtual capable frame. Otherwise fall back to a + * physical capable frame. + */ + for (i = 0; i < gt_block->timer_count; i++) { + if (is_best_frame(cnttidr, gt_block->timer[i].frame_nr)) { + best_frame = >_block->timer[i]; + if (arch_timer_mem_use_virtual) + break; + } + } + iounmap(cntctlbase); + + return best_frame; +} + +static int __init arch_timer_mem_acpi_init(size_t timer_count) +{ + struct gt_block_data *gt_blocks; + struct gt_timer_data *gt_timer; + int ret = -EINVAL; + + /* + * If we don't have any Platform Timer Structures, just return. + */ + if (!timer_count) + return 0; + + /* + * before really check all the Platform Timer Structures, + * we assume they are GT block, and allocate memory for them. + * We will free these memory once we finish the initialization. + */ + gt_blocks = kcalloc(timer_count, sizeof(*gt_blocks), GFP_KERNEL); + if (!gt_blocks) + return -ENOMEM; + + if (gtdt_arch_timer_mem_init(gt_blocks) > 0) { + gt_timer = arch_timer_mem_get_timer(gt_blocks); + if (!gt_timer) { + pr_err("Failed to get mem timer info.\n"); + goto error; + } + ret = arch_timer_mem_register(NULL, gt_timer); + if (ret) { + pr_err("Failed to register mem timer.\n"); + goto error; + } + } + arch_timers_present |= ARCH_MEM_TIMER; +error: + kfree(gt_blocks); + return ret; +} + +/* Initialize per-processor generic timer and memory-mapped timer(if present) */ static int __init arch_timer_acpi_init(struct acpi_table_header *table) { int timer_count; @@ -945,8 +1023,8 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table) /* Get the frequency from CNTFRQ */ arch_timer_detect_rate(NULL, NULL); - if (timer_count < 0) - pr_err("Failed to get platform timer info.\n"); + if (timer_count < 0 || arch_timer_mem_acpi_init((size_t)timer_count)) + pr_err("Failed to initialize memory-mapped timer.\n"); return arch_timer_init(); }