Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5242729rwp; Sun, 16 Jul 2023 23:51:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGA5jH7L59+4fCHQqkzP1F+bLa6GD6WWa6eX/hWmB6jZqPhxFJgR75rYB00mdUav+yNqwB2 X-Received: by 2002:ac2:5924:0:b0:4fb:891f:165b with SMTP id v4-20020ac25924000000b004fb891f165bmr1944941lfi.3.1689576674442; Sun, 16 Jul 2023 23:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689576674; cv=none; d=google.com; s=arc-20160816; b=AddXStepGfciPy5Ef+KqKtAr2frMRG46lfErb0tf4x17PNLY3goN/s9e1ZO3yddGAI UwtCeWmDQj1U5U1et4uAHSCtgl6lMJ5bb4DJNBbk9yc96pPZFEUbG2dZzGEKZ5CfKaP/ SLvriLFf/IVsWqeSs9JVuKSxxpR1U9y03iF/xiW2j2Cp1/ACdfjLmtdqwT5wjpu30VGg bFnnTLjLleWKinLB/xciId+gRM7cK5OuNqMvHQ4ER40LxdAmql6N9uIqiLZyx5rORcsG qeus4onMV94zuc5fSQ2iF8HKb8o8VN4ph0MdJRCagUiZaqKErjkGN+A14FcqJhND3yMU dNSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ybENJY+zvZqFFXyYlFQfNam1MA92ybnOKuGRXBpZTAw=; fh=mAQoZ+q1BWtVvvWaNnjWB+0LOr2nya7L90zqq2gAyvg=; b=UNc4HvPvQY1U6UUq0bZheXCURiDH14dVARHGLr2lFsWyV4icwS0FT+u9foLokHY78v l+sTAOqB/rYP+c2Md1uElAuCluEpCItS0IQ3ccF5WOnlv1Ifkxp8VEaXgsnN6PPoDms8 vg6RTnBYZMGtl1JCS0Q6jvUgQr5fHoaqGibduh2uEcoo/PvQEviD8hLwzqLi3B47T84T AnG+xXNGTtndBeUPFIHIe11JhDCy1WDvnsYAANYAs+u8Bd+1Hhxx1qnjujBeE7j8G71v ZplOozgNqu0CZkQYIj1hKI6ignl6iHTSZrczeMaEEgAfxGQkXxkU6Y662A97NaOv2hts 1pNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=QCmRcSUR; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y6-20020aa7d506000000b0051e0d936760si13233576edq.14.2023.07.16.23.50.49; Sun, 16 Jul 2023 23:51:14 -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=QCmRcSUR; 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 S229634AbjGQGih (ORCPT + 99 others); Mon, 17 Jul 2023 02:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbjGQGig (ORCPT ); Mon, 17 Jul 2023 02:38:36 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 823C7E46 for ; Sun, 16 Jul 2023 23:38:34 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-55ba5bb0bf3so2445989a12.1 for ; Sun, 16 Jul 2023 23:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1689575914; x=1692167914; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ybENJY+zvZqFFXyYlFQfNam1MA92ybnOKuGRXBpZTAw=; b=QCmRcSURDxmA7WAhnDAKs9KEtswbEiK+GDi2sGhgm2sF4oVeEPotJXy7bchD52ZewX V+kcimAqmBH81vVGQUvF9N+/QkMu66QmZpsSJqzuSolr9jj11KNH+B9n/XLswhDmqr1W h+yKQdOrfglUzYqvAHSRLwmymEn0JqOJXy0z/W5jM8yFnFgBwZqITWakuLV8d6R9VPEn +ryLVL1/KZ/ZX4TrTBwOKhVQHHrFOYNVXWNQKK2Fs+41QOnlSpd08CNS9r7pd/g58L1v 4QXgJUhL7ZhA9X2yFhij4AZvoLDWt/Ttk2qNY22rYETOOnEVzc51NwUn8wrSK3golu6e t9qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689575914; x=1692167914; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ybENJY+zvZqFFXyYlFQfNam1MA92ybnOKuGRXBpZTAw=; b=jVpXBU8tTKuXE2mUKjJKF7fVw6nPbO60xj5X4SpSrjf4w4ibJL7g4HibWEtWoFbkrT riw75gnRp47EJFfl5OHWwPXrJmhnBOOxRGsiKY2KaCwnOJnT0gMrtUTGMYmTFPB8QMgE 1e9y0dA8oYDwGbYGJ8GOl779xzChQanVQCvsCs+0Y50lKtyXFOyR6wt6QgbqJI041JPg fkVXwjr1UAuwq0MhTOCqsk0cPs1DRN2oXDozklE/mNh/uZNRSV8KSFPSUFyvioU4liDp BKhgV8fRHYKOmtCnsAjjAcEvYYEtYRaSxOQJNNSXcenk6o1gWcWsNnVsf2vBdcD5cihO BFBg== X-Gm-Message-State: ABy/qLaBeDSzH5vZ567j6NuOivInHT82PsYzZboQu4jtatVcFk1hsfdC uYtNJrM243PQjTP/u19t0a6SIekR3+xBWgj/gpPwkw== X-Received: by 2002:a17:90b:3143:b0:263:e299:dff9 with SMTP id ip3-20020a17090b314300b00263e299dff9mr11555957pjb.23.1689575913782; Sun, 16 Jul 2023 23:38:33 -0700 (PDT) MIME-Version: 1.0 References: <20230710094321.1378351-1-apatel@ventanamicro.com> <20230710094321.1378351-3-apatel@ventanamicro.com> <20230711-df9211fcae3b67948896b77f@orel> In-Reply-To: <20230711-df9211fcae3b67948896b77f@orel> From: Anup Patel Date: Mon, 17 Jul 2023 12:08:21 +0530 Message-ID: Subject: Re: [PATCH v5 2/9] irqchip/riscv-intc: Add support for RISC-V AIA To: Andrew Jones Cc: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Atish Patra , Sunil V L , Conor Dooley , Saravana Kannan , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 On Tue, Jul 11, 2023 at 7:42=E2=80=AFPM Andrew Jones wrote: > > On Mon, Jul 10, 2023 at 03:13:14PM +0530, Anup Patel wrote: > > The RISC-V advanced interrupt architecture (AIA) extends the per-HART > > local interrupts in following ways: > > 1. Minimum 64 local interrupts for both RV32 and RV64 > > 2. Ability to process multiple pending local interrupts in same > > interrupt handler > > 3. Priority configuration for each local interrupts > > 4. Special CSRs to configure/access the per-HART MSI controller > > afaict, we're only doing (1) and (2) from this list in this patch. Okay, I will update the commit description. > > > > > This patch adds support for RISC-V AIA in the RISC-V intc driver. > > > > Signed-off-by: Anup Patel > > --- > > drivers/irqchip/irq-riscv-intc.c | 36 ++++++++++++++++++++++++++------ > > 1 file changed, 30 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-ris= cv-intc.c > > index 4adeee1bc391..e235bf1708a4 100644 > > --- a/drivers/irqchip/irq-riscv-intc.c > > +++ b/drivers/irqchip/irq-riscv-intc.c > > @@ -17,6 +17,7 @@ > > #include > > #include > > #include > > +#include > > > > static struct irq_domain *intc_domain; > > > > @@ -30,6 +31,15 @@ static asmlinkage void riscv_intc_irq(struct pt_regs= *regs) > > generic_handle_domain_irq(intc_domain, cause); > > } > > > > +static asmlinkage void riscv_intc_aia_irq(struct pt_regs *regs) > > +{ > > + unsigned long topi; > > + > > + while ((topi =3D csr_read(CSR_TOPI))) > > + generic_handle_domain_irq(intc_domain, > > + topi >> TOPI_IID_SHIFT); > > +} > > + > > /* > > * On RISC-V systems local interrupts are masked or unmasked by writin= g > > * the SIE (Supervisor Interrupt Enable) CSR. As CSRs can only be wri= tten > > @@ -39,12 +49,18 @@ static asmlinkage void riscv_intc_irq(struct pt_reg= s *regs) > > > > static void riscv_intc_irq_mask(struct irq_data *d) > > { > > - csr_clear(CSR_IE, BIT(d->hwirq)); > > + if (d->hwirq < BITS_PER_LONG) > > + csr_clear(CSR_IE, BIT(d->hwirq)); > > + else > > + csr_clear(CSR_IEH, BIT(d->hwirq - BITS_PER_LONG)); > > We can optimize rv64 by allowing the compiler to remove the branch > > if (IS_ENABLED(CONFIG_32BIT) && d->hwirq >=3D 32) > csr_clear(CSR_IEH, BIT(d->hwirq - 32)); > else > csr_clear(CSR_IE, BIT(d->hwirq)); > Makes sense, I will update. > > > } > > > > static void riscv_intc_irq_unmask(struct irq_data *d) > > { > > - csr_set(CSR_IE, BIT(d->hwirq)); > > + if (d->hwirq < BITS_PER_LONG) > > + csr_set(CSR_IE, BIT(d->hwirq)); > > + else > > + csr_set(CSR_IEH, BIT(d->hwirq - BITS_PER_LONG)); > > Same comment as above. Okay, I will update. > > > } > > > > static void riscv_intc_irq_eoi(struct irq_data *d) > > @@ -115,16 +131,22 @@ static struct fwnode_handle *riscv_intc_hwnode(vo= id) > > > > static int __init riscv_intc_init_common(struct fwnode_handle *fn) > > { > > - int rc; > > + int rc, nr_irqs =3D BITS_PER_LONG; > > + > > + if (riscv_isa_extension_available(NULL, SxAIA) && BITS_PER_LONG = =3D=3D 32) > > + nr_irqs =3D nr_irqs * 2; > > The AIA spec states sie and sip are explicitly 64, so how about writing > this as > > int rc, nr_irqs =3D BITS_PER_LONG; > > if (riscv_isa_extension_available(NULL, SxAIA)) > nr_irqs =3D 64; Okay, I will update. > > > > > - intc_domain =3D irq_domain_create_linear(fn, BITS_PER_LONG, > > + intc_domain =3D irq_domain_create_linear(fn, nr_irqs, > > &riscv_intc_domain_ops, NU= LL); > > if (!intc_domain) { > > pr_err("unable to add IRQ domain\n"); > > return -ENXIO; > > } > > > > - rc =3D set_handle_irq(&riscv_intc_irq); > > + if (riscv_isa_extension_available(NULL, SxAIA)) > > + rc =3D set_handle_irq(&riscv_intc_aia_irq); > > + else > > + rc =3D set_handle_irq(&riscv_intc_irq); > > nit: blank line here I prefer no blank line here because the "if (rc)" below checks for errors for the above calls. > > > if (rc) { > > pr_err("failed to set irq handler\n"); > > return rc; > > @@ -132,7 +154,9 @@ static int __init riscv_intc_init_common(struct fwn= ode_handle *fn) > > > > riscv_set_intc_hwnode_fn(riscv_intc_hwnode); > > > > - pr_info("%d local interrupts mapped\n", BITS_PER_LONG); > > + pr_info("%d local interrupts mapped%s\n", > > + nr_irqs, (riscv_isa_extension_available(NULL, SxAIA)) ? > > nit: unnecessary () Okay, I will update. > > > + " using AIA" : ""); > > > > return 0; > > } > > -- > > 2.34.1 > > > > Thanks, > drew Regards, Anup