From patchwork Thu Feb 16 18:20:37 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: 58196 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp457440wrn; Thu, 16 Feb 2023 10:24:16 -0800 (PST) X-Google-Smtp-Source: AK7set+orSC4LvDVP0fv9gEK+dj/uJJgDaP4Ll4MAJs3RTXI019Njlo5x050FGHTcF7r/aO1MMfJ X-Received: by 2002:a05:6a20:12d1:b0:be:da1c:df7a with SMTP id v17-20020a056a2012d100b000beda1cdf7amr7551242pzg.40.1676571855953; Thu, 16 Feb 2023 10:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676571855; cv=none; d=google.com; s=arc-20160816; b=TMDnEXD99R6HDSP0s4UFn9gGggcTHrw55JbO23RSJNdOcpMnJfsYISNUsDmb1AfDc7 yBI+NJ3ojSmHBUw8YUpRyZM9WUrLispOuv/MMw8vsin7qW9vuVoUqkQ9haWKg0TGZEpx YcRL8nFbYLroxY/OMOO/tU6aPxjWJ8FHS+KOXoHHPJ2yZDEbcnexOLJwl0Gyg6WAUjve rtpzvrCEetpsRSSiIf05hN8Wu32hEkVeZcQB3b+tvX7fVtOK4vz4KwGDJVfzTurAZHjL rjM7seS7KidOndbbkHF1WgVNskU2EoEkzGJrdoImBO1rV6wbMcS72sus00kn72U81YT/ VA5Q== 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=4phaq6quaw8OEd5i/LKAI0eg66LQgH0oflAjuJIR3hM=; b=Xohjxk4TJhRs8MRT228odjjqYjjhxJS7OgDrTzhobW1G6Ak/nGSO8eKWkwjznxiEhN vWRBxcbZXQbu94w9povSD2ATWJyxNLDRpjgr4Yj4f9QricwA0WfKp7r35f6YwqekLhxQ Y8KJHrg3nEk5qDXL2ewkgyBRhmZ1JGPUwvlsv5ClvsTrW5Z4b12mv/Gf1cdUDmvo88C3 7SAspfxpjcE6xXfWGDE68NGitxDcW+RQWx2xcQhStkJxguhejQCwpiLd3Cb1PyCUyAai ZdM/JD/4EugW8266ttcYRxLyZb/CYxQJ6/+K3YNBz7/XdgUZXHBM/Es75psUNtiv63CL wHtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=assdfSn7; 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 d4-20020a633604000000b004fb760561a3si2363033pga.595.2023.02.16.10.24.03; Thu, 16 Feb 2023 10:24:15 -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=assdfSn7; 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 S230338AbjBPSXV (ORCPT + 99 others); Thu, 16 Feb 2023 13:23:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230284AbjBPSWe (ORCPT ); Thu, 16 Feb 2023 13:22:34 -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 2F7BE5036E for ; Thu, 16 Feb 2023 10:22:07 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id z14-20020a17090abd8e00b00233bb9d6bdcso2958097pjr.4 for ; Thu, 16 Feb 2023 10:22:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=4phaq6quaw8OEd5i/LKAI0eg66LQgH0oflAjuJIR3hM=; b=assdfSn79vHm0/djewQo2bAQqyjoTdSiGlBucWz/vkwhlh0gcU4AzKvvNGpbvajSzo pyLddLDI91C5MOJAqpvr+uIMgruD0aMCS5ZkzhicFmN14+x8C7nDK2QPkEwxAZY0cHrN njQ2zJIhkyPA0oCk8owapfaEaiAVm/jFqJqZHUtqhNpdOsJj6oyEzlmxzG7BmxRHGnTl 010zIM+wIuONTlBkSYFy/AXiy57JLHaoy1nGIKW/GgvturAOhwh37d7TDfwp1XJZOcol NymKVNVqiyDZoXLOoFLIZsBv8PZxexq/CRxJGVCU0XPdAsT0x8D1+iC3ghJYaXGI5Q0c l0hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=4phaq6quaw8OEd5i/LKAI0eg66LQgH0oflAjuJIR3hM=; b=uYcze6KUU1xk3RF0gwDBnz4XLhn5VHHvhY54seNQKYymNc91lRfeGbtWBL9Bofv9ai KaWU9E0GjUOD51OrBNE2jrq0dHDyWaHYt8AK/YM3Nr47/M0ByBvas8EDj7YYwbws7I4I iPha21Bme3k6xH1blD9Xlu23mJYUonVUeefCJQx48lQgkV31Cj0KQqqxelWAgQCNn/9W NQNXYhXuif5d2whfopIZ8aJw/OCvlGIsv+UZOrZZWQNHe2RvcrQZ5dOYpbZp5Mkg6vVt qVEJv2+3NhIMa5Zc/ZjMJumGUq+KFYWEHsTjavI4XMdrf1cSv8VMVFGk6+QHaeJ8baDB cu4w== X-Gm-Message-State: AO0yUKX/JF9kzEehCAQLXzP4f2J5r+YdsYImAJNBlNJgxHLR4lNqXuJE jNNWp9RjDygl6qsMSUwb86yV0w== X-Received: by 2002:a05:6a20:7350:b0:bc:80bd:462d with SMTP id v16-20020a056a20735000b000bc80bd462dmr8512373pzc.46.1676571724598; Thu, 16 Feb 2023 10:22:04 -0800 (PST) Received: from kerodi.Dlink ([49.206.14.226]) by smtp.gmail.com with ESMTPSA id n21-20020a637215000000b004dff15fc121sm1517574pgc.36.2023.02.16.10.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 10:22:04 -0800 (PST) From: Sunil V L To: Palmer Dabbelt , Albert Ou , Paul Walmsley , "Rafael J . Wysocki" , Len Brown , Thomas Gleixner , Marc Zyngier , Jonathan Corbet Cc: linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Conor Dooley , Andrew Jones , Anup Patel , Atish Patra , Sunil V L , "Rafael J . Wysocki" Subject: [PATCH V2 15/21] clocksource/timer-riscv: Refactor riscv_timer_init_dt() Date: Thu, 16 Feb 2023 23:50:37 +0530 Message-Id: <20230216182043.1946553-16-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216182043.1946553-1-sunilvl@ventanamicro.com> References: <20230216182043.1946553-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?1758013010641610560?= X-GMAIL-MSGID: =?utf-8?q?1758013010641610560?= 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 --- drivers/clocksource/timer-riscv.c | 82 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c index 1b4b36df5484..2ae8e300d303 100644 --- a/drivers/clocksource/timer-riscv.c +++ b/drivers/clocksource/timer-riscv.c @@ -119,61 +119,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; - struct irq_domain *domain; + int error; + struct irq_domain *domain = NULL; + 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; } @@ -202,4 +169,35 @@ 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);