Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1205078pxu; Sat, 24 Oct 2020 03:56:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxULSjJK5dForm1LiHd5rsM6TxOOBix2/xyORy+hkMts5EniBZPn8mJYx5ViQe7RV4bRh3i X-Received: by 2002:aa7:c608:: with SMTP id h8mr6464971edq.16.1603536989515; Sat, 24 Oct 2020 03:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603536989; cv=none; d=google.com; s=arc-20160816; b=qAKhxi79GXY/sFbUWXtPKCfTq/Fi+T9RmWmSDzbk7nTLHFk60GOFq7vp4232frrt0U s9ATJhTMD0RR3PYeTrK5W+naMlaunIydcZbsIPpyZ3oN9E63dCb6f95NYf0BgMHs/2jf 4vHxnVx1fCPHJFCmYLH6cVtBronqymkx51YZFycNq2AmIq8IY+aTsQ5LD45DQZx3sIeC Mc3GzStz0cRaINCjQ/gUIS0AFVB5NwYRN2COtiCGNDhHZ73xp+xlNUUQTGWC8XijdNxe 9N4/uAttQVABRZpp9/VFj5Q7pqOa+Bm9JIJhkjcqHn3DkAkTFXGtHCZ/f0r1p7nQTg0K AbEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GZpS1aNSOD7BICbL/NLEwXrnO3J9pN02gwztyVkT018=; b=l4q6KDkMz+a1at0de4Zj5xjYVLRaRsgOQJyZKye/8nZXm6w41pqeZLRwv6MfZSdKCm 28jH+ZBgLbIQNCsvtDVuMQQ2c3SGU9VZ1aloyzB5B3GqwqeN+yhdiBET95+rgg+iYdp8 uH4N0Qk4bNT2Hl4vRz/4AzRz6AWCKTh+7/fsvSgPhmRnVGW80QgTyl1q1/sdq0ww7o3e IZEHS+6SUBJiI/AzoQKvDMh9lE7dfourt0Tuzo2HLbq+7cTnfAoR5lWyH5IH/a6/Ezt7 wjW6xAc4mcNN866ONrT68dxtAP5tWNmibIYr5i0nkou0GXCVV30RcCCwNQ0R41uULB7y ZLwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lSEpSy2q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p25si3273503ejc.412.2020.10.24.03.56.07; Sat, 24 Oct 2020 03:56:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lSEpSy2q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759304AbgJXDKE (ORCPT + 99 others); Fri, 23 Oct 2020 23:10:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:58178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759300AbgJXDKC (ORCPT ); Fri, 23 Oct 2020 23:10:02 -0400 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F0F8D22272 for ; Sat, 24 Oct 2020 03:10:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603509001; bh=T2MY35WzTyMya24fc1ZRV/JbBaR5f7YTXksJCq7PiYg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lSEpSy2qpv44JkKtncmsE8Ns/GpLo+I5kNHv92N1+B/azneD2Bp3+1DPrvhxzpMCV qbNVXOrpmMjZUJPfORP7SLQy7i88IMOEcg81BdTP1FXQMjgPA3TPPPlVyKFLxvfkSQ RqmvAG1u6euo4PGB1FoeRyU/BZkCTZhDMktLyqxs= Received: by mail-lf1-f45.google.com with SMTP id c141so4452622lfg.5 for ; Fri, 23 Oct 2020 20:10:00 -0700 (PDT) X-Gm-Message-State: AOAM530WtCoOcSNw1LWWlBz3E0WEH/6ARLZHo8dfd+VTsj1JSnzHy/0Z faa84cxwUZZPc7buhIlbZlw1YFjHmJJBiWIo1nk= X-Received: by 2002:a19:e305:: with SMTP id a5mr1595530lfh.549.1603508999204; Fri, 23 Oct 2020 20:09:59 -0700 (PDT) MIME-Version: 1.0 References: <1603448245-79429-1-git-send-email-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Sat, 24 Oct 2020 11:09:47 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/3] irqchip/irq-sifive-plic: Fixup wrong size of xxx_PER_HART and reg base To: Anup Patel Cc: Palmer Dabbelt , Paul Walmsley , Greentime Hu , Zong Li , Atish Patra , Thomas Gleixner , Jason Cooper , Marc Zyngier , wesley@sifive.com, Yash Shah , Christoph Hellwig , linux-riscv , "linux-kernel@vger.kernel.org List" , Guo Ren Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 23, 2020 at 8:31 PM Anup Patel wrote: > > On Fri, Oct 23, 2020 at 3:48 PM wrote: > > > > From: Guo Ren > > > > ENABLE and CONTEXT registers contain M & S status for per-hart, so > > ref to the specification the correct definition is double to the > > current value. > > > > The value of hart_base and enable_base should be calculated by real > > physical hartid not software id. Sometimes the CPU node's > > from dts is not equal to the sequence index. > > > > Signed-off-by: Guo Ren > > --- > > drivers/irqchip/irq-sifive-plic.c | 12 ++++++------ > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > > index eaa3e9f..2e56576 100644 > > --- a/drivers/irqchip/irq-sifive-plic.c > > +++ b/drivers/irqchip/irq-sifive-plic.c > > @@ -44,16 +44,16 @@ > > * Each hart context has a vector of interrupt enable bits associated with it. > > * There's one bit for each interrupt source. > > */ > > -#define ENABLE_BASE 0x2000 > > -#define ENABLE_PER_HART 0x80 > > +#define ENABLE_BASE 0x2080 > > +#define ENABLE_PER_HART 0x100 > > > > /* > > * Each hart context has a set of control registers associated with it. Right > > * now there's only two: a source priority threshold over which the hart will > > * take an interrupt, and a register to claim interrupts. > > */ > > -#define CONTEXT_BASE 0x200000 > > -#define CONTEXT_PER_HART 0x1000 > > +#define CONTEXT_BASE 0x201000 > > +#define CONTEXT_PER_HART 0x2000 > > #define CONTEXT_THRESHOLD 0x00 > > #define CONTEXT_CLAIM 0x04 > > > > @@ -358,10 +358,10 @@ static int __init plic_init(struct device_node *node, > > cpumask_set_cpu(cpu, &priv->lmask); > > handler->present = true; > > handler->hart_base = > > - priv->regs + CONTEXT_BASE + i * CONTEXT_PER_HART; > > + priv->regs + CONTEXT_BASE + hartid * CONTEXT_PER_HART; > > raw_spin_lock_init(&handler->enable_lock); > > handler->enable_base = > > - priv->regs + ENABLE_BASE + i * ENABLE_PER_HART; > > + priv->regs + ENABLE_BASE + hartid * ENABLE_PER_HART; > > handler->priv = priv; > > done: > > for (hwirq = 1; hwirq <= nr_irqs; hwirq++) > > -- > > 2.7.4 > > > > There is no one-to-one mapping between PLIC context and HARTID. Instead, > we have many-to-one mapping between PLIC contexts and HARTID. In other > words, we have one PLIC context for each interrupt capable mode (i.e. > M/S-mode) of each HART. > > For example, on SiFive Unleashed we have 5 HARTs but HARTID=0 has > only M-mode capable of taking interrupts so we have total (1 + 2x4) = 9 > PLIC contexts. That's OK, but what the bug I want to point out is enable_base & context_base should be calculated by 'hartid' not 'i'. For example, how we deal with below dts configuration: cpus { #address-cells = <1>; #size-cells = <0>; timebase-frequency = <3000000>; cpu@0 { device_type = "cpu"; reg = <2>; //********* different from index status = "okay"; compatible = "riscv"; riscv,isa = "rv64imafdcsu"; mmu-type = "riscv,sv39"; cpu0_intc: interrupt-controller { #interrupt-cells = <1>; compatible = "riscv,cpu-intc"; interrupt-controller; }; }; cpu@1 { device_type = "cpu"; reg = <3>; //********* different from index status = "fail"; compatible = "riscv"; riscv,isa = "rv64imafdcsu"; mmu-type = "riscv,sv39"; cpu1_intc: interrupt-controller { #interrupt-cells = <1>; compatible = "riscv,cpu-intc"; interrupt-controller; }; }; } > > I would also like to highlight that this patch is forcing PLIC driver to always > use PLIC S-mode context for each HART which breaks the Linux RISC-V > NoMMU kernel. Yes, I forgot M-mode and I will correct it. > > There is no issue with the existing defines because these are aligned with > above and latest PLIC spec. > (Refer, https://github.com/riscv/riscv-plic-spec/blob/master/riscv-plic.adoc) > > NACK to this patch from my side. Here is my new patch which fixup m-mode linux: diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 4048657..e34e1d9 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -45,7 +45,13 @@ * There's one bit for each interrupt source. */ #define ENABLE_BASE 0x2000 -#define ENABLE_PER_HART 0x80 +#define ENABLE_PER_HART 0x100 +#ifdef CONFIG_RISCV_M_MODE +#define ENABLE_OFFSET 0 +#else +#define ENABLE_OFFSET 0x80 +#endif + /* * Each hart context has a set of control registers associated with it. Right @@ -53,9 +59,14 @@ * take an interrupt, and a register to claim interrupts. */ #define CONTEXT_BASE 0x200000 -#define CONTEXT_PER_HART 0x1000 +#define CONTEXT_PER_HART 0x2000 #define CONTEXT_THRESHOLD 0x00 #define CONTEXT_CLAIM 0x04 +#ifdef CONFIG_RISCV_M_MODE +#define CONTEXT_OFFSET 0 +#else +#define CONTEXT_OFFSET 0x1000 +#endif #define PLIC_DISABLE_THRESHOLD 0x7 #define PLIC_ENABLE_THRESHOLD 0 @@ -358,10 +369,10 @@ static int __init plic_init(struct device_node *node, cpumask_set_cpu(cpu, &priv->lmask); handler->present = true; handler->hart_base = - priv->regs + CONTEXT_BASE + i * CONTEXT_PER_HART; + priv->regs + CONTEXT_BASE + hartid * CONTEXT_PER_HART + CONTEXT_OFFSET; raw_spin_lock_init(&handler->enable_lock); handler->enable_base = - priv->regs + ENABLE_BASE + i * ENABLE_PER_HART; + priv->regs + ENABLE_BASE + hartid * ENABLE_PER_HART + ENABLE_OFFSET; handler->priv = priv; done: for (hwirq = 1; hwirq <= nr_irqs; hwirq++) -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/