Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1451170iog; Sat, 25 Jun 2022 09:38:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tSHM2aQZxS0XdLoWNP981PYqdhZ28aZQJD4nA1oYJms81gSmf1/4reC94Se1V8loKkN8Nl X-Received: by 2002:a17:90b:4d12:b0:1ed:3124:3ecf with SMTP id mw18-20020a17090b4d1200b001ed31243ecfmr7970464pjb.111.1656175110453; Sat, 25 Jun 2022 09:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656175110; cv=none; d=google.com; s=arc-20160816; b=qD1UzpshO68NwlxnI9RZnqL3p6T/cC+vKcpWVppBI0WCwUQT+rIXICRMhvIc7MT+RO ixvNdFilsLdNxQYfuACAo6lVCMYFRmr8R9uKXTu3UpY1SkeKTua7WwKqvfxMlmH9OMo8 2AxXrVw7N2qEUq4S2dlPavDJoc6pGgMRhmE0Yqy1ioM6pYDEbnU0b9Y1ECV0YkuTH848 dDL79R7ebRCEB0zZLTI+l2bwIZJJQeEpSuCeLVJa81MxxQ79lemNp0qUriohbEC+f47b AUg123XfohjZ+gcF4tjXK6MWekK+ztGNM4qpTrDx0euDuiJFohcwViqK705WAI+UdYhB urpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=2PEV+blPjccl0liBXxAh79DhLM0b5vbdSeC1NPcszRs=; b=kmCrD6bK/eSko1PIFu2QtdK1OcjHuMJQutXTD3N08JTOrl3Cvuc3fq6g34o9S//1C2 PWrnReoBHPmvxAoTvf5PyJOghxnYImVXUcjpYQgw29IZ7DrzHX1vZVr2Iqfrgxa18B77 x6cdYN8Ko/N7Js/iQMMoAKwUDA8A/TqRIPxY90aZA4CV947oR/H6itmRNJ0vbgfUD8ec RCR7dhRdqlsv4So72i5TE7dqkRnsspcwCYWI1Nn9uG1299Ki4GJ6S16BfMJgYKh+2PTu rfJFuEMO6ahuVWUzQPUwyE0YMXN+IXp8O/ITfg5Phb8dyg7+m5jFxRuBFutnx8BW63bK EtiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fGwapFIF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v62-20020a638941000000b003fcfdc99472si7306783pgd.739.2022.06.25.09.38.16; Sat, 25 Jun 2022 09:38:30 -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=@kernel.org header.s=k20201202 header.b=fGwapFIF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233255AbiFYQGC (ORCPT + 99 others); Sat, 25 Jun 2022 12:06:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233242AbiFYQGA (ORCPT ); Sat, 25 Jun 2022 12:06:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DB4B167F3; Sat, 25 Jun 2022 09:05:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B6851B80C2C; Sat, 25 Jun 2022 16:05:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61259C3411C; Sat, 25 Jun 2022 16:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656173156; bh=AToRdKG3QacktWi9IxW2BHWjWYtnPEVe84zJg54fJbA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fGwapFIFYQVzdVIiYmnOpMXFdnjqbX7gyB8aL6hlrOh+99RVXILoAKibc4r6AmJk1 W2V/iC/ytjfLhCPXtoWAx1T5i0Zn3cUBWsYueq3MBFUjMcR2MehYpSd4JbEEbmRQAv CQfhbX+NjKUTM7Bt79ck+4gj7H+MqrA5tCXwsOCPIrFHH9UXPyai2VXbX9z37KVEHU UeH5qkHiFsPbV+nB7K0zFgRf7vI+eW1Vk+sV6vQG6VTSBMDWkotVqPuMrWUC1EKmvj vLpfa6vmV3g/P2zkaLdqHTF0wfnar0Oo0+lh+yKeru11eGZGDeW0lcF0f0jeEWQl3v F4lw0It6clzXw== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1o58IE-0035Px-7I; Sat, 25 Jun 2022 17:05:54 +0100 Date: Sat, 25 Jun 2022 17:05:59 +0100 Message-ID: <87zgi0eniw.wl-maz@kernel.org> From: Marc Zyngier To: "Lad, Prabhakar" Cc: Lad Prabhakar , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Sagar Kadam , Palmer Dabbelt , Paul Walmsley , linux-riscv , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Geert Uytterhoeven , Linux-Renesas , LKML , Biju Das Subject: Re: [PATCH 2/2] irqchip/sifive-plic: Add support for Renesas RZ/Five SoC In-Reply-To: References: <20220624180311.3007-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20220624180311.3007-3-prabhakar.mahadev-lad.rj@bp.renesas.com> <8735ftf73p.wl-maz@kernel.org> <87h7492c58.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: prabhakar.csengg@gmail.com, prabhakar.mahadev-lad.rj@bp.renesas.com, tglx@linutronix.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, sagar.kadam@sifive.com, palmer@dabbelt.com, paul.walmsley@sifive.com, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, geert+renesas@glider.be, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, biju.das.jz@bp.renesas.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 25 Jun 2022 14:03:33 +0100, "Lad, Prabhakar" wrote: > > [1 ] > Hi Marc, > > On Sat, Jun 25, 2022 at 12:52 PM Marc Zyngier wrote: > > [...] > > You are just reinventing the wheel we are already have, except that > > yours is a bit square ;-). What really should happen is that the > > set_type method should set the correct flow depending on the trigger > > of the interrupt, and *never* have to check the configuration on the > > handling path. > > > A Bit lost here.. > > We have the below chained handler: > > static void plic_handle_irq(struct irq_desc *desc) > { > struct plic_handler *handler = this_cpu_ptr(&plic_handlers); > struct irq_chip *chip = irq_desc_get_chip(desc); > void __iomem *claim = handler->hart_base + CONTEXT_CLAIM; > irq_hw_number_t hwirq; > > WARN_ON_ONCE(!handler->present); > > chained_irq_enter(chip, desc); > > while ((hwirq = readl(claim))) { > int err = generic_handle_domain_irq(handler->priv->irqdomain, > hwirq); > if (unlikely(err)) > pr_warn_ratelimited("can't find mapping for hwirq %lu\n", > hwirq); > } > > chained_irq_exit(chip, desc); > } > > static void plic_irq_eoi(struct irq_data *d) > { > struct plic_handler *handler = this_cpu_ptr(&plic_handlers); > > if (irqd_irq_masked(d)) { > plic_irq_unmask(d); > writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); > plic_irq_mask(d); > } else { > writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); > } > } > > Where it's claiming -> handling interrupt -> interrupt completion in > eoi which is according to architecture. > > > Now with fasteoi_ack flow If I introduce the below ack callback to > issue interrupt completion. > > static void plic_irq_ack(struct irq_data *d) > { > struct plic_handler *handler = this_cpu_ptr(&plic_handlers); > > if (irqd_irq_masked(d)) { > plic_irq_unmask(d); > writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); > plic_irq_mask(d); > } else { > writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); > } > } > > Here we are issuing an interrupt completion first, and later in the > handler plic_handle_irq() we are claiming the interrupt by reading > the claim register. With this we are not following [0]. Whatever [0] says doesn't really matter, since the HW is totally busted. > Do you think this flow is OK (interrupt completion -> Interrupt claim > -> handle IRQ)? You keep missing my point. Edge and Level *must* have different flows and this also implies different callbacks. You can't just handle both at once. You should have something like this (untested): diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index bb87e4c3b88e..5e072be32d9f 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -176,16 +176,52 @@ static void plic_irq_eoi(struct irq_data *d) } } +static int broken_set_type(struct irq_data *d, unsigned int type); + static struct irq_chip plic_chip = { .name = "SiFive PLIC", .irq_mask = plic_irq_mask, .irq_unmask = plic_irq_unmask, .irq_eoi = plic_irq_eoi, + .irq_set_type = broken_set_type, +#ifdef CONFIG_SMP + .irq_set_affinity = plic_set_affinity, +#endif +}; + +static void broken_eoi(struct irq_data *data) {} + +static struct irq_chip plic_chip_edge = { + .name = "Edgy PLIC", + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask, + .irq_ack = plic_irq_eoi, + .irq_eoi = broken_eoi, + .irq_set_type = broken_set_type, #ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity, #endif }; +static int broken_set_type(struct irq_data *d, unsigned int type) +{ + if (!plic_is_totaly_broken()) + return 0; + + if (type == IRQ_TYPE_EDGE_RISING) + irq_set_chip_handler_name_locked(d, plic_chip_edge, + handle_fasteoi_ack_irq, + "Edge"); + else if (type == IRQ_TYPE_LEVEL_HIGH) + irq_set_chip_handler_name_locked(d, plic_chip, + handle_fasteoi_irq, + "Level"); + else + return -EINVAL; + + return 0; +} + static int plic_irqdomain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hwirq) { which applies the correct flow and chip depending on the trigger information. This also implies that for chained PLICs, the secondary PLIC output is handled as a level into the primary PLIC. M. -- Without deviation from the norm, progress is not possible.