From patchwork Fri Mar 3 13:36:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 63929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp412745wrd; Fri, 3 Mar 2023 05:39:59 -0800 (PST) X-Google-Smtp-Source: AK7set8LxjHaMJpulopuifJBXVk+9/PjrI108MziG2ptpe5DUDWEzS8e39edqVbgQCJd4blRKVQT X-Received: by 2002:a05:6a20:ba9d:b0:bf:6cd3:9510 with SMTP id fb29-20020a056a20ba9d00b000bf6cd39510mr1842606pzb.24.1677850799261; Fri, 03 Mar 2023 05:39:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677850799; cv=none; d=google.com; s=arc-20160816; b=j5fADl56ZcXlBzW1xKfRHNiLe7baPX1IjHHNQw+7QQSmnb7a7XhGIvlrPuW57AOTcW nVMH1GTQndI75UHuxnaTB4FAWrjQzQ9Ai5SVEWWHe/cgdv2K/4CjNqJvRx7ZwsPeLvd3 hHDg35sGgLOwDcnV75cs4SVAXOrCiFKmX5D0l2r2ojzHRIVaYYHZUH+Ew1B72wEJai0o YFzkwrU1xQLJGSPbtCwFBVD6lEmcp+cr445gyIYponKMBNOnLfQKiK20DIeb5Crnbqig cGcwxKn0XYbYfz+1B/jCjEucnLgX/i6d/8n4lBGkuSk/HRycETOOA9+ueTkcS03bmrDC xNTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7z6bEMhbWIxvIOeCxyJDoCOcsyBkr0Sn2VEh+xkIGVw=; b=YWkO8zruk76EEkoPae1OYkvru6Q5lu9eJLTl/xlAnTErXTYJkH3D/vOUp/jmTO5Uut ClrMM9Nn42QrxJd4zQids2k8tLsYzryw2MaMOaU3neyCxeiABNOXgO3V12gW6ZQR68ZH /lEy8UR29e2hhcBEOOFJKy2dMVTSReUuvi8I10kUpTxDlWCVnZP4y/XcCWQXHph5qG+L hko4cSJa97ZTBsppYk/NgMuES1zgaoPlQY/tJ4DCO0hNg3/lAmsQDPX4Ll4InBm18mRJ UzqNBSrWB+MP6fTXdd8kXyxsFI1ZsboKVEKvHtzumO8n4k4uqoUhNKtExE/xjSvg1o9n oVjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=L1+t7UFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs186-20020a6328c3000000b004fb83390415si2146167pgb.77.2023.03.03.05.39.45; Fri, 03 Mar 2023 05:39:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=L1+t7UFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231330AbjCCNjZ (ORCPT + 99 others); Fri, 3 Mar 2023 08:39:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231315AbjCCNit (ORCPT ); Fri, 3 Mar 2023 08:38:49 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9D93B850 for ; Fri, 3 Mar 2023 05:38:08 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id p3-20020a17090ad30300b0023a1cd5065fso2316776pju.0 for ; Fri, 03 Mar 2023 05:38:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1677850687; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7z6bEMhbWIxvIOeCxyJDoCOcsyBkr0Sn2VEh+xkIGVw=; b=L1+t7UFo1QNj1oAdW0bFVzjj23x0mZi3y5JmnPZsUX3cRp4O2HYqqoIiqSJh/jUA9s 1LZjAG67fu8riiuEWb8IPvAPcZhyM8aLEYMJmsVpbR0Xf1unTVMYawU57exAs88x7wEC V0cOUV2H2AXo7WUmlHqe/z1V19da76imaxJzIc09gXUnHPmTGi5EoJXgUjYZX1g20vxg Q6dM6OtoILQk4Z0gbXAKAzEVDpTnk3isgcKuK/TM0r4uGEkMF4+aaySbIOHvhJT5UGKp kyWuaJrVl45sT7LTPbNy6tZgQH1JFMxPSA5VSo7eeXckRrPoAEUr9SOGRqh06eIKSf3R 967w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677850687; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7z6bEMhbWIxvIOeCxyJDoCOcsyBkr0Sn2VEh+xkIGVw=; b=hlx8WQXIJLFumIytPYK0pSJrfNj/o6jNrv5Q2jDxQemW7aEpZ3ExpwMr5q3n/qXhkF oGvhaFIXFnlivivOtuAhtY1ZAWljvnyShD1WIg0m1+Zsrv7IRpKvKQeK7Tm8gpzY0v6A 99x6KuHbXsWnF/HHmeGp/0w83WKwlRzeVirqrEmJsMbjOknXwAbrAtsiPIbooKNIxg+b V9PLLtg/KnE67lmMog+aL/OUxoj5taMKmArralfCdD9ALG3OrsK3hc0oIWcpPxN7rsck LpTCrOeOe5UUC+v1t3D0GuDjH560mBesdYcnGCH52cTI2Hj47kt/vlv9DYx4oBwTHmdL KBfA== X-Gm-Message-State: AO0yUKXCyhJ4OElSX1L4ImE5xUK7hg9Vi8bJM+KZ+rFRzM6iPW1J/vKA DWz6LtXve433PP4onUuS6q/bMQ== X-Received: by 2002:a17:902:da90:b0:19a:a0d0:10f0 with SMTP id j16-20020a170902da9000b0019aa0d010f0mr2416786plx.23.1677850687560; Fri, 03 Mar 2023 05:38:07 -0800 (PST) Received: from localhost.localdomain ([49.206.14.226]) by smtp.gmail.com with ESMTPSA id m9-20020a170902768900b0019ac5d3ee9dsm1533125pll.157.2023.03.03.05.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 05:38:07 -0800 (PST) From: Sunil V L To: linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Palmer Dabbelt , Albert Ou , "Rafael J . Wysocki" , Len Brown , Thomas Gleixner , Marc Zyngier , Daniel Lezcano , Jonathan Corbet , Anup Patel , Andrew Jones , Atish Patra , 'Conor Dooley ' , Sunil V L , "Rafael J . Wysocki" Subject: [PATCH V3 15/20] clocksource/timer-riscv: Refactor riscv_timer_init_dt() Date: Fri, 3 Mar 2023 19:06:42 +0530 Message-Id: <20230303133647.845095-16-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230303133647.845095-1-sunilvl@ventanamicro.com> References: <20230303133647.845095-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759354079748720307?= X-GMAIL-MSGID: =?utf-8?q?1759354079748720307?= Refactor the timer init function such that few things can be shared by both DT and ACPI based platforms. Co-developed-by: Anup Patel Signed-off-by: Anup Patel Signed-off-by: Sunil V L Acked-by: Rafael J. Wysocki Reviewed-by: Andrew Jones Reviewed-by: Conor Dooley --- drivers/clocksource/timer-riscv.c | 81 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c index 5f0f10c7e222..cecc4662293b 100644 --- a/drivers/clocksource/timer-riscv.c +++ b/drivers/clocksource/timer-riscv.c @@ -124,61 +124,28 @@ static irqreturn_t riscv_timer_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static int __init riscv_timer_init_dt(struct device_node *n) +static int __init riscv_timer_init_common(void) { - int cpuid, error; - unsigned long hartid; - struct device_node *child; + int error; struct irq_domain *domain; + struct fwnode_handle *intc_fwnode = riscv_get_intc_hwnode(); - error = riscv_of_processor_hartid(n, &hartid); - if (error < 0) { - pr_warn("Not valid hartid for node [%pOF] error = [%lu]\n", - n, hartid); - return error; - } - - cpuid = riscv_hartid_to_cpuid(hartid); - if (cpuid < 0) { - pr_warn("Invalid cpuid for hartid [%lu]\n", hartid); - return cpuid; - } - - if (cpuid != smp_processor_id()) - return 0; - - child = of_find_compatible_node(NULL, NULL, "riscv,timer"); - if (child) { - riscv_timer_cannot_wake_cpu = of_property_read_bool(child, - "riscv,timer-cannot-wake-cpu"); - of_node_put(child); - } - - domain = NULL; - child = of_get_compatible_child(n, "riscv,cpu-intc"); - if (!child) { - pr_err("Failed to find INTC node [%pOF]\n", n); - return -ENODEV; - } - domain = irq_find_host(child); - of_node_put(child); + domain = irq_find_matching_fwnode(intc_fwnode, DOMAIN_BUS_ANY); if (!domain) { - pr_err("Failed to find IRQ domain for node [%pOF]\n", n); + pr_err("Failed to find irq_domain for INTC node [%pfwP]\n", + intc_fwnode); return -ENODEV; } riscv_clock_event_irq = irq_create_mapping(domain, RV_IRQ_TIMER); if (!riscv_clock_event_irq) { - pr_err("Failed to map timer interrupt for node [%pOF]\n", n); + pr_err("Failed to map timer interrupt for node [%pfwP]\n", intc_fwnode); return -ENODEV; } - pr_info("%s: Registering clocksource cpuid [%d] hartid [%lu]\n", - __func__, cpuid, hartid); error = clocksource_register_hz(&riscv_clocksource, riscv_timebase); if (error) { - pr_err("RISCV timer register failed [%d] for cpu = [%d]\n", - error, cpuid); + pr_err("RISCV timer registration failed [%d]\n", error); return error; } @@ -207,4 +174,36 @@ static int __init riscv_timer_init_dt(struct device_node *n) return error; } +static int __init riscv_timer_init_dt(struct device_node *n) +{ + int cpuid, error; + unsigned long hartid; + struct device_node *child; + + error = riscv_of_processor_hartid(n, &hartid); + if (error < 0) { + pr_warn("Invalid hartid for node [%pOF] error = [%lu]\n", + n, hartid); + return error; + } + + cpuid = riscv_hartid_to_cpuid(hartid); + if (cpuid < 0) { + pr_warn("Invalid cpuid for hartid [%lu]\n", hartid); + return cpuid; + } + + if (cpuid != smp_processor_id()) + return 0; + + child = of_find_compatible_node(NULL, NULL, "riscv,timer"); + if (child) { + riscv_timer_cannot_wake_cpu = of_property_read_bool(child, + "riscv,timer-cannot-wake-cpu"); + of_node_put(child); + } + + return riscv_timer_init_common(); +} + TIMER_OF_DECLARE(riscv_timer, "riscv", riscv_timer_init_dt);