Message ID | 20230802150018.327079-2-apatel@ventanamicro.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp550932vqx; Wed, 2 Aug 2023 08:49:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHrbYRJrowLvkN+zB/twF4lx5LBa5PJTzGmYMksbJSzMkbsU2TPcz5fI1fRuu8kkHMACtty X-Received: by 2002:a05:6808:2a59:b0:3a7:17b6:3501 with SMTP id fa25-20020a0568082a5900b003a717b63501mr12530232oib.23.1690991358449; Wed, 02 Aug 2023 08:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690991358; cv=none; d=google.com; s=arc-20160816; b=PbDWhANuWUm7hyginG83tnY+bzxeH3qQAnhAzeCn51FzrdamNiVwLqITriilkE49VU WcXaJQKpTHHuALPc0BP/mTHyO01DwF2uNqY/djJ7xpK8yq3/zfaB5gm98yZgf3u8Nv1k xnwCvU8+/RDqyjPOY9aEFBHko0AnTnt0HOb7r4R0u/nqFXjYsFFg1dIJQcJGsqWa6dkw BAi64yPueqZp97gCeQ+V6szbXlLBjgyUQPmV6PWBpJCA7kIdEfq6VP7+qM0HV07J3QxE +DR9HfkmhLchgCfgLlRS9KkN39EN6UJXdJsyUpRoReDAdUcYn4/d3JQJ9ShThmgnIiVc 1zGw== 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=MFifZoeBHO5EvFOj+ZbSo7s64eoTFIfH2fAZl0Owb5c=; fh=f+ph7VIwhX7iLJOrfHJ1YQ1ojo0XBG5+jaAb/hL4mCY=; b=flOLAy95w72JykK0Iql+ToHY4y9ofAt22hvitO1gMyVVFFBUiosobk/g8YPue1lduM UpRn/KuUr6ipo0yD+4zVQCIP9jSEdC6J6eSZbA1pq4+h0KDMM2Q7E4L59eGeXldxzWB9 lIa9oo2DUV3V1kO5+RH6kAe5cFjt57AdyiGysB4fb0zD/PEt5RFVblOJe8JBxxnxg7An k7dMlu9V4vIJeauLokDKU57xvtD73OzbB+180GVoxQlPXVkPqRDEyC/Jag/K5lOznLnB 1sTXP3s1HUd0x7zPbvTTWn0lOBJPjXyaHE/divcJChifJK9XxyhDg8Js7jy/yC6Gs4eQ BpIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=n+5956oQ; 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 d187-20020a6336c4000000b0051b90567f99si7742469pga.690.2023.08.02.08.49.00; Wed, 02 Aug 2023 08:49:18 -0700 (PDT) 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=n+5956oQ; 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 S234753AbjHBPA6 (ORCPT <rfc822;maxi.paulin@gmail.com> + 99 others); Wed, 2 Aug 2023 11:00:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234700AbjHBPAq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Aug 2023 11:00:46 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B64B42D4B for <linux-kernel@vger.kernel.org>; Wed, 2 Aug 2023 08:00:41 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bc02bd4eafso34473455ad.1 for <linux-kernel@vger.kernel.org>; Wed, 02 Aug 2023 08:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690988441; x=1691593241; 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=MFifZoeBHO5EvFOj+ZbSo7s64eoTFIfH2fAZl0Owb5c=; b=n+5956oQdCieWbAT985RXUNhoICmFY5KgB5CPz+S1dAzLwHhVtlyrfMhzuDo1pgn5i I103huNg2rg1eFNtxP09qVmV4M9cz0zRaxFYZIPK0OqcXkIU9Dt/P0PFXjWbQa/hw2rv RaCOvHsBCOWQU0SDy2Lqy9tQe2CXWRs6S80S5zHd08NkAn6DwYNV3Vor7TT+0tCdFdCK 1cVGYmc6eX1EDceYb8v21y2D2EHcvaKFA0ZXexb1GyirZ7/kPmYXud67u+RtWKlWSBSB V1KtS5XIQHaRMOmI3fq+ZfRDvwmRzNvzUhj8hr1t7ITYJqLbsoVsp8ouE9ruzOm+9Fxa gv1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690988441; x=1691593241; 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=MFifZoeBHO5EvFOj+ZbSo7s64eoTFIfH2fAZl0Owb5c=; b=ENDKtLQZRVwiNIwFJUfU4vr1ShHR5KGiFdjmieWidg2McRKTRKmMzP29hT4UU4nGuT mYAdrwX8MAhCE+WkKcSNRNdBlvgkZXiez29YLi+7QP8vmSeOB760vlRHbuN4hj62DHJS pj3qKtbJx8uYE7lcAEu1M4NBpD11M2sFIsOQXrVjv438HbeCgusju9TcTr8OoM77XYx/ z1SI0okdE1Z/kMEJiuPak31zsGnZsG2wStgQ3DB1NEl/dW8fjF5qCfdCtQmEETm+urAj 4If42/vtGaJPjTdVnNGLfQekEhqLwxVDtyCLxal3v0xiNKRMtNRPKBtSdQ2sCOfqhjs3 aa/Q== X-Gm-Message-State: ABy/qLZQH4WnBI0fVyGHrpZqIRqFZDs/Wh1kHbctKANn4u7JyEUy1gJb r3ItdrmNBCbKy8B51zLSO16PjOHeF8zpDqA6fmXyaA== X-Received: by 2002:a17:903:41cf:b0:1b8:a65f:b49d with SMTP id u15-20020a17090341cf00b001b8a65fb49dmr19389598ple.12.1690988441018; Wed, 02 Aug 2023 08:00:41 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id v11-20020a1709028d8b00b001bb99e188fcsm12503963plo.194.2023.08.02.08.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 08:00:40 -0700 (PDT) From: Anup Patel <apatel@ventanamicro.com> To: Palmer Dabbelt <palmer@dabbelt.com>, Paul Walmsley <paul.walmsley@sifive.com>, Thomas Gleixner <tglx@linutronix.de>, Marc Zyngier <maz@kernel.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Frank Rowand <frowand.list@gmail.com>, Conor Dooley <conor+dt@kernel.org> Cc: Atish Patra <atishp@atishpatra.org>, Andrew Jones <ajones@ventanamicro.com>, Sunil V L <sunilvl@ventanamicro.com>, Saravana Kannan <saravanak@google.com>, Anup Patel <anup@brainfault.org>, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Anup Patel <apatel@ventanamicro.com> Subject: [PATCH v7 01/15] RISC-V: Add riscv_get_intc_hartid() function Date: Wed, 2 Aug 2023 20:30:04 +0530 Message-Id: <20230802150018.327079-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230802150018.327079-1-apatel@ventanamicro.com> References: <20230802150018.327079-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773132954327841359 X-GMAIL-MSGID: 1773132954327841359 |
Series |
Linux RISC-V AIA Support
|
|
Commit Message
Anup Patel
Aug. 2, 2023, 3 p.m. UTC
We add a common riscv_get_intc_hartid() which help device drivers to
get hartid of the HART associated with a INTC (i.e. local interrupt
controller) fwnode. This new function is more generic compared to
the existing riscv_of_parent_hartid() function hence we also replace
use of riscv_of_parent_hartid() with riscv_get_intc_hartid().
Also, while we are here let us update riscv_of_parent_hartid() to
always return the hartid irrespective whether the CPU/HART DT node
is disabled or not.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
arch/riscv/include/asm/processor.h | 4 +++-
arch/riscv/kernel/cpu.c | 26 ++++++++++++++++++++------
drivers/irqchip/irq-riscv-intc.c | 2 +-
drivers/irqchip/irq-sifive-plic.c | 3 ++-
4 files changed, 26 insertions(+), 9 deletions(-)
Comments
On Wed, Aug 02, 2023 at 08:30:04PM +0530, Anup Patel wrote: > We add a common riscv_get_intc_hartid() which help device drivers to > get hartid of the HART associated with a INTC (i.e. local interrupt > controller) fwnode. This new function is more generic compared to > the existing riscv_of_parent_hartid() function hence we also replace > use of riscv_of_parent_hartid() with riscv_get_intc_hartid(). > > Also, while we are here let us update riscv_of_parent_hartid() to > always return the hartid irrespective whether the CPU/HART DT node > is disabled or not. This change should probably be a separate patch with its own justification in its commit message. > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > --- > arch/riscv/include/asm/processor.h | 4 +++- > arch/riscv/kernel/cpu.c | 26 ++++++++++++++++++++------ > drivers/irqchip/irq-riscv-intc.c | 2 +- > drivers/irqchip/irq-sifive-plic.c | 3 ++- > 4 files changed, 26 insertions(+), 9 deletions(-) > > diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h > index c950a8d9edef..662da1e112dd 100644 > --- a/arch/riscv/include/asm/processor.h > +++ b/arch/riscv/include/asm/processor.h > @@ -79,7 +79,9 @@ static inline void wait_for_interrupt(void) > struct device_node; > int riscv_of_processor_hartid(struct device_node *node, unsigned long *hartid); > int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *hartid); > -int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid); > + > +struct fwnode_handle; > +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid); Do we want a function that is named in a way that appears to be intc-specific in processor.h? > > extern void riscv_fill_hwcap(void); > extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); > diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c > index a2fc952318e9..c3eaa8a55bbe 100644 > --- a/arch/riscv/kernel/cpu.c > +++ b/arch/riscv/kernel/cpu.c > @@ -81,21 +81,35 @@ int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *har > * To achieve this, we walk up the DT tree until we find an active > * RISC-V core (HART) node and extract the cpuid from it. > */ > -int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid) > +static int riscv_of_parent_hartid(struct device_node *node, > + unsigned long *hartid) > { > - int rc; > - > for (; node; node = node->parent) { > if (of_device_is_compatible(node, "riscv")) { > - rc = riscv_of_processor_hartid(node, hartid); > - if (!rc) > - return 0; > + *hartid = (unsigned long)of_get_cpu_hwid(node, 0); Shouldn't we still do something like if (*hartid == ~0UL) { pr_warn_once("Found CPU without hart ID\n"); return -ENODEV; } > + return 0; > } > } > > return -1; > } > > +/* Find hart ID of the INTC fwnode. */ > +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid) > +{ > + int rc; > + u64 temp; > + > + if (!is_of_node(node)) { > + rc = fwnode_property_read_u64_array(node, "hartid", &temp, 1); This fwnode property read call seems premature, since we don't have any way to know that "hartid" will be a property of the intc since it's not a property documented in the DT binding. (I know Sunil has a series in progress which will introduce "hartid" for ACPI, but, even then, it seems like we need some documentation to point at that says '"hartid" is the name to use'. > + if (!rc) > + *hartid = temp; > + } else > + rc = riscv_of_parent_hartid(to_of_node(node), hartid); > + > + return rc; > +} > + > DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); > > unsigned long riscv_cached_mvendorid(unsigned int cpu_id) > diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c > index 4adeee1bc391..65f4a2afb381 100644 > --- a/drivers/irqchip/irq-riscv-intc.c > +++ b/drivers/irqchip/irq-riscv-intc.c > @@ -143,7 +143,7 @@ static int __init riscv_intc_init(struct device_node *node, > int rc; > unsigned long hartid; > > - rc = riscv_of_parent_hartid(node, &hartid); > + rc = riscv_get_intc_hartid(of_fwnode_handle(node), &hartid); > if (rc < 0) { > pr_warn("unable to find hart id for %pOF\n", node); > return 0; > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > index e1484905b7bd..56b0544b1f27 100644 > --- a/drivers/irqchip/irq-sifive-plic.c > +++ b/drivers/irqchip/irq-sifive-plic.c > @@ -477,7 +477,8 @@ static int __init __plic_init(struct device_node *node, > continue; > } > > - error = riscv_of_parent_hartid(parent.np, &hartid); > + error = riscv_get_intc_hartid(of_fwnode_handle(parent.np), > + &hartid); > if (error < 0) { > pr_warn("failed to parse hart ID for context %d.\n", i); > continue; > -- > 2.34.1 > Thanks, drew
On Wed, Aug 02, 2023 at 08:09:18PM +0300, Andrew Jones wrote: > On Wed, Aug 02, 2023 at 08:30:04PM +0530, Anup Patel wrote: > > We add a common riscv_get_intc_hartid() which help device drivers to > > get hartid of the HART associated with a INTC (i.e. local interrupt > > controller) fwnode. This new function is more generic compared to > > the existing riscv_of_parent_hartid() function hence we also replace > > use of riscv_of_parent_hartid() with riscv_get_intc_hartid(). > > > > Also, while we are here let us update riscv_of_parent_hartid() to > > always return the hartid irrespective whether the CPU/HART DT node > > is disabled or not. > > This change should probably be a separate patch with its own > justification in its commit message. Yeah, it certainly needs a justification, not just an "oh, btw I did this". It also invalidates the comment above the function, so that would need to be changed too. > > diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c > > index a2fc952318e9..c3eaa8a55bbe 100644 > > --- a/arch/riscv/kernel/cpu.c > > +++ b/arch/riscv/kernel/cpu.c > > @@ -81,21 +81,35 @@ int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *har > > * To achieve this, we walk up the DT tree until we find an active ^^^^^^ > > * RISC-V core (HART) node and extract the cpuid from it. > > */ > > -int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid) > > +static int riscv_of_parent_hartid(struct device_node *node,
On Wed, Aug 02, 2023 at 08:30:04PM +0530, Anup Patel wrote: > +/* Find hart ID of the INTC fwnode. */ > +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid) > +{ > + int rc; > + u64 temp; > + > + if (!is_of_node(node)) { > + rc = fwnode_property_read_u64_array(node, "hartid", &temp, 1); > + if (!rc) > + *hartid = temp; > + } else > + rc = riscv_of_parent_hartid(to_of_node(node), hartid); This branch needs to be enclosed in braces too. > + > + return rc; > +} > + > DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
On Wed, Aug 2, 2023 at 10:41 PM Andrew Jones <ajones@ventanamicro.com> wrote: > > On Wed, Aug 02, 2023 at 08:30:04PM +0530, Anup Patel wrote: > > We add a common riscv_get_intc_hartid() which help device drivers to > > get hartid of the HART associated with a INTC (i.e. local interrupt > > controller) fwnode. This new function is more generic compared to > > the existing riscv_of_parent_hartid() function hence we also replace > > use of riscv_of_parent_hartid() with riscv_get_intc_hartid(). > > > > Also, while we are here let us update riscv_of_parent_hartid() to > > always return the hartid irrespective whether the CPU/HART DT node > > is disabled or not. > > This change should probably be a separate patch with its own > justification in its commit message. Okay, I will move this into a separate patch in the next revision. > > > > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > > --- > > arch/riscv/include/asm/processor.h | 4 +++- > > arch/riscv/kernel/cpu.c | 26 ++++++++++++++++++++------ > > drivers/irqchip/irq-riscv-intc.c | 2 +- > > drivers/irqchip/irq-sifive-plic.c | 3 ++- > > 4 files changed, 26 insertions(+), 9 deletions(-) > > > > diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h > > index c950a8d9edef..662da1e112dd 100644 > > --- a/arch/riscv/include/asm/processor.h > > +++ b/arch/riscv/include/asm/processor.h > > @@ -79,7 +79,9 @@ static inline void wait_for_interrupt(void) > > struct device_node; > > int riscv_of_processor_hartid(struct device_node *node, unsigned long *hartid); > > int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *hartid); > > -int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid); > > + > > +struct fwnode_handle; > > +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid); > > Do we want a function that is named in a way that appears to be > intc-specific in processor.h? Yes, this is intended to be only for intc because only intc fwnode can have "hartid" property. > > > > > extern void riscv_fill_hwcap(void); > > extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); > > diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c > > index a2fc952318e9..c3eaa8a55bbe 100644 > > --- a/arch/riscv/kernel/cpu.c > > +++ b/arch/riscv/kernel/cpu.c > > @@ -81,21 +81,35 @@ int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *har > > * To achieve this, we walk up the DT tree until we find an active > > * RISC-V core (HART) node and extract the cpuid from it. > > */ > > -int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid) > > +static int riscv_of_parent_hartid(struct device_node *node, > > + unsigned long *hartid) > > { > > - int rc; > > - > > for (; node; node = node->parent) { > > if (of_device_is_compatible(node, "riscv")) { > > - rc = riscv_of_processor_hartid(node, hartid); > > - if (!rc) > > - return 0; > > + *hartid = (unsigned long)of_get_cpu_hwid(node, 0); > > Shouldn't we still do something like > > if (*hartid == ~0UL) { > pr_warn_once("Found CPU without hart ID\n"); > return -ENODEV; > } Sure, I will add it in the next revision. > > > + return 0; > > } > > } > > > > return -1; > > } > > > > +/* Find hart ID of the INTC fwnode. */ > > +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid) > > +{ > > + int rc; > > + u64 temp; > > + > > + if (!is_of_node(node)) { > > + rc = fwnode_property_read_u64_array(node, "hartid", &temp, 1); > > This fwnode property read call seems premature, since we don't have any > way to know that "hartid" will be a property of the intc since it's not a > property documented in the DT binding. (I know Sunil has a series in > progress which will introduce "hartid" for ACPI, but, even then, it seems > like we need some documentation to point at that says '"hartid" is the > name to use'. Sure, I will return a failure if it is not an OF node and Sunil can include a patch to extend this function for ACPI. The idea here is that we create SW fwnodes for static ACPI tables and the irqchip driver only uses fwnode APIs as an abstraction over DT and ACPI. This way irqchip drivers work for both DT and ACPI with minimal modifications. Almost all properties of SW fwnodes are exactly same as defined by the DT bindings except two synthetic properties: 1) "hartid" in INTC fwnode created only for ACPI 2) "gsi-base" in the APLIC fwnode created only for ACPI. I suggest we should document both of these synthetic fwnode properties in Documentation/riscv/acpi.rst since these are only for ACPI. > > > + if (!rc) > > + *hartid = temp; > > + } else > > + rc = riscv_of_parent_hartid(to_of_node(node), hartid); > > + > > + return rc; > > +} > > + > > DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); > > > > unsigned long riscv_cached_mvendorid(unsigned int cpu_id) > > diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c > > index 4adeee1bc391..65f4a2afb381 100644 > > --- a/drivers/irqchip/irq-riscv-intc.c > > +++ b/drivers/irqchip/irq-riscv-intc.c > > @@ -143,7 +143,7 @@ static int __init riscv_intc_init(struct device_node *node, > > int rc; > > unsigned long hartid; > > > > - rc = riscv_of_parent_hartid(node, &hartid); > > + rc = riscv_get_intc_hartid(of_fwnode_handle(node), &hartid); > > if (rc < 0) { > > pr_warn("unable to find hart id for %pOF\n", node); > > return 0; > > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > > index e1484905b7bd..56b0544b1f27 100644 > > --- a/drivers/irqchip/irq-sifive-plic.c > > +++ b/drivers/irqchip/irq-sifive-plic.c > > @@ -477,7 +477,8 @@ static int __init __plic_init(struct device_node *node, > > continue; > > } > > > > - error = riscv_of_parent_hartid(parent.np, &hartid); > > + error = riscv_get_intc_hartid(of_fwnode_handle(parent.np), > > + &hartid); > > if (error < 0) { > > pr_warn("failed to parse hart ID for context %d.\n", i); > > continue; > > -- > > 2.34.1 > > > > Thanks, > drew Regards, Anup
On Wed, Aug 2, 2023 at 10:51 PM Conor Dooley <conor@kernel.org> wrote: > > On Wed, Aug 02, 2023 at 08:30:04PM +0530, Anup Patel wrote: > > > +/* Find hart ID of the INTC fwnode. */ > > +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid) > > +{ > > + int rc; > > + u64 temp; > > + > > + if (!is_of_node(node)) { > > + rc = fwnode_property_read_u64_array(node, "hartid", &temp, 1); > > + if (!rc) > > + *hartid = temp; > > + } else > > + rc = riscv_of_parent_hartid(to_of_node(node), hartid); > > This branch needs to be enclosed in braces too. Okay, I will update in the next revision. > > > + > > + return rc; > > +} > > + > > DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); > Regards, Anup
diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index c950a8d9edef..662da1e112dd 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -79,7 +79,9 @@ static inline void wait_for_interrupt(void) struct device_node; int riscv_of_processor_hartid(struct device_node *node, unsigned long *hartid); int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *hartid); -int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid); + +struct fwnode_handle; +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid); extern void riscv_fill_hwcap(void); extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index a2fc952318e9..c3eaa8a55bbe 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -81,21 +81,35 @@ int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *har * To achieve this, we walk up the DT tree until we find an active * RISC-V core (HART) node and extract the cpuid from it. */ -int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid) +static int riscv_of_parent_hartid(struct device_node *node, + unsigned long *hartid) { - int rc; - for (; node; node = node->parent) { if (of_device_is_compatible(node, "riscv")) { - rc = riscv_of_processor_hartid(node, hartid); - if (!rc) - return 0; + *hartid = (unsigned long)of_get_cpu_hwid(node, 0); + return 0; } } return -1; } +/* Find hart ID of the INTC fwnode. */ +int riscv_get_intc_hartid(struct fwnode_handle *node, unsigned long *hartid) +{ + int rc; + u64 temp; + + if (!is_of_node(node)) { + rc = fwnode_property_read_u64_array(node, "hartid", &temp, 1); + if (!rc) + *hartid = temp; + } else + rc = riscv_of_parent_hartid(to_of_node(node), hartid); + + return rc; +} + DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); unsigned long riscv_cached_mvendorid(unsigned int cpu_id) diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index 4adeee1bc391..65f4a2afb381 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -143,7 +143,7 @@ static int __init riscv_intc_init(struct device_node *node, int rc; unsigned long hartid; - rc = riscv_of_parent_hartid(node, &hartid); + rc = riscv_get_intc_hartid(of_fwnode_handle(node), &hartid); if (rc < 0) { pr_warn("unable to find hart id for %pOF\n", node); return 0; diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index e1484905b7bd..56b0544b1f27 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -477,7 +477,8 @@ static int __init __plic_init(struct device_node *node, continue; } - error = riscv_of_parent_hartid(parent.np, &hartid); + error = riscv_get_intc_hartid(of_fwnode_handle(parent.np), + &hartid); if (error < 0) { pr_warn("failed to parse hart ID for context %d.\n", i); continue;