From patchwork Fri Nov 30 08:02:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10705881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BF8E14BD for ; Fri, 30 Nov 2018 08:02:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E0C62F4C8 for ; Fri, 30 Nov 2018 08:02:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 516CE2F4D7; Fri, 30 Nov 2018 08:02:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E05812F4C8 for ; Fri, 30 Nov 2018 08:02:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vMt/R8qiaQKYuN+klNJZbjttu1qEiqj0nNRVIuk23Gg=; b=Nq83WOSYa5N50fltpq6FTKB4kS voLyyfjfppSbknjkzqk/w6+1GJmJU8aGoXMWHQ8vECRVBXmNBykTuTJs8KCYzw/ex9J8nestL1mfm wFAtXOoe7rNGywbnXvND9ErPg0gTGjPDy2+gctreu2E6uIUlnb/yKH3qDkhYa38t7lYuZxInquKns 7j+Zk6B8aMSUCIvF0dawPSOv6k23gQudlpLBu99lrg4Mf2QLGjyvp2lQDWf49PfQBmccuov7wBb3b DduD1r0Tt3scvZWK3ivjnpJR7Zlu0sUba4KIW7YZyTkA2AIAi4S2JxbahWrY544W1/phvPCxB3wM4 6c0hRI7A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdky-0003kI-28; Fri, 30 Nov 2018 08:02:36 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdkt-0003gR-Kc for linux-riscv@lists.infradead.org; Fri, 30 Nov 2018 08:02:33 +0000 Received: by mail-pg1-x542.google.com with SMTP id t13so2141246pgr.11 for ; Fri, 30 Nov 2018 00:02:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EWRMoEC/A0hBjLIZuy6KvNFGbEVqYyO/63HQJNeKmb0=; b=pX7HPyItHcvL7I8CcRC8mkwocrohyKK3alsWU9f5QyEhzn++uVl2rDF8JQpfm9Po0F RvisQ3PFP1wqGQSwcjnV8tCuC3mKVA9uMu8uWXVQBOn21iGnQ8Allzn8AQe2lHbp/62e feBUxcOG3gAN7bZ4qWxb16X3INMEg+S+2RUADXLR6M6nN/F2ynYc72Uq72DIH7DDgyjv ASJvyiIuzTZElpns+FNBtnwsOtszMI5AXDpxEs+QfpA5Wb08QOwPde2AQiT+KF4dWlP3 EcvsbREhGyd1RmsMANr3kyMngc7xJ+HG1y0kgCuBZCRzB9vfKKRVIg5KrgaCQhPfbI/d 9MuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EWRMoEC/A0hBjLIZuy6KvNFGbEVqYyO/63HQJNeKmb0=; b=iloyY30kXcOnq+9PWrwDltdo1LOk2Q9COvLHLo9WeF9R7SujGIjvp46Je0vvTnQ48T Dh9YHfFDkPizR9xKV+wdgcCHlB2JvQVSyRY6weG4aDrOF2DpjfYRQiBGGORxbfA/OCaR iCRm4bUsNP6ItLal33YARwLlonSnGtqhYuq1c7UrPfB02YPBFnrhfRpthhP3AthPY3vq ggxwYePiN1a2q7mJPVGfIwBp3UU0KZzmEKMyzs6BrUdOBl9c3EypAdEJBDGG7aRwNMPa sHxYYQLuA1VlaaAjoxpq6r7TAWmyjahmZggpb7+TAaZclQQIkygcMvOjHgv5ZTzmcsXC VsVA== X-Gm-Message-State: AA+aEWahP3Mtk7Q6ZDdjflNqxc32k87rJoZZVoDrl16C7Iq8jmLVchfM LiJuPhkclv8VEV7hAI/FbHaVdQ== X-Google-Smtp-Source: AFSGD/Ub6+Gy2QjoIjZVBIMAwBrw3VEeQrDAKyz5rAgWqgdnxHYwwjZIs/V44sgepk1OjgJblvIjpw== X-Received: by 2002:a62:2f06:: with SMTP id v6mr4722584pfv.216.1543564940610; Fri, 30 Nov 2018 00:02:20 -0800 (PST) Received: from anup-ubuntu64.qualcomm.com ([49.207.52.208]) by smtp.googlemail.com with ESMTPSA id q187sm19218333pfq.128.2018.11.30.00.02.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:02:19 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v3 1/6] irqchip: sifive-plic: Pre-compute context hart base and enable base Date: Fri, 30 Nov 2018 13:32:02 +0530 Message-Id: <20181130080207.20505-2-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130080207.20505-1-anup@brainfault.org> References: <20181130080207.20505-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181130_000231_700441_29BBE51C X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch does following optimizations: 1. Pre-compute hart base for each context handler 2. Pre-compute enable base for each context handler 3. Have enable lock for each context handler instead of global plic_toggle_lock Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 47 ++++++++++++++----------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 357e9daf94ae..c23a293a2aae 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -59,37 +59,28 @@ static void __iomem *plic_regs; struct plic_handler { bool present; - int ctxid; + void __iomem *hart_base; + /* + * Protect mask operations on the registers given that we can't + * assume atomic memory operations work on them. + */ + raw_spinlock_t enable_lock; + void __iomem *enable_base; }; static DEFINE_PER_CPU(struct plic_handler, plic_handlers); -static inline void __iomem *plic_hart_offset(int ctxid) -{ - return plic_regs + CONTEXT_BASE + ctxid * CONTEXT_PER_HART; -} - -static inline u32 __iomem *plic_enable_base(int ctxid) -{ - return plic_regs + ENABLE_BASE + ctxid * ENABLE_PER_HART; -} - -/* - * Protect mask operations on the registers given that we can't assume that - * atomic memory operations work on them. - */ -static DEFINE_RAW_SPINLOCK(plic_toggle_lock); - -static inline void plic_toggle(int ctxid, int hwirq, int enable) +static inline void plic_toggle(struct plic_handler *handler, + int hwirq, int enable) { - u32 __iomem *reg = plic_enable_base(ctxid) + (hwirq / 32); + u32 __iomem *reg = handler->enable_base + (hwirq / 32) * sizeof(u32); u32 hwirq_mask = 1 << (hwirq % 32); - raw_spin_lock(&plic_toggle_lock); + raw_spin_lock(&handler->enable_lock); if (enable) writel(readl(reg) | hwirq_mask, reg); else writel(readl(reg) & ~hwirq_mask, reg); - raw_spin_unlock(&plic_toggle_lock); + raw_spin_unlock(&handler->enable_lock); } static inline void plic_irq_toggle(struct irq_data *d, int enable) @@ -101,7 +92,7 @@ static inline void plic_irq_toggle(struct irq_data *d, int enable) struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); if (handler->present) - plic_toggle(handler->ctxid, d->hwirq, enable); + plic_toggle(handler, d->hwirq, enable); } } @@ -150,7 +141,7 @@ static struct irq_domain *plic_irqdomain; static void plic_handle_irq(struct pt_regs *regs) { struct plic_handler *handler = this_cpu_ptr(&plic_handlers); - void __iomem *claim = plic_hart_offset(handler->ctxid) + CONTEXT_CLAIM; + void __iomem *claim = handler->hart_base + CONTEXT_CLAIM; irq_hw_number_t hwirq; WARN_ON_ONCE(!handler->present); @@ -239,12 +230,16 @@ static int __init plic_init(struct device_node *node, cpu = riscv_hartid_to_cpuid(hartid); handler = per_cpu_ptr(&plic_handlers, cpu); handler->present = true; - handler->ctxid = i; + handler->hart_base = + plic_regs + CONTEXT_BASE + i * CONTEXT_PER_HART; + raw_spin_lock_init(&handler->enable_lock); + handler->enable_base = + plic_regs + ENABLE_BASE + i * ENABLE_PER_HART; /* priority must be > threshold to trigger an interrupt */ - writel(0, plic_hart_offset(i) + CONTEXT_THRESHOLD); + writel(0, handler->hart_base + CONTEXT_THRESHOLD); for (hwirq = 1; hwirq <= nr_irqs; hwirq++) - plic_toggle(i, hwirq, 0); + plic_toggle(handler, hwirq, 0); nr_mapped++; } From patchwork Fri Nov 30 08:02:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10705877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 338EE1057 for ; Fri, 30 Nov 2018 08:02:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24E75296DA for ; Fri, 30 Nov 2018 08:02:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 180CE2F4D2; Fri, 30 Nov 2018 08:02:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 92294296DA for ; Fri, 30 Nov 2018 08:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2ZERJSP+M/46rcj3J6ShHtuPgHeSDkUlg9583r8tQz4=; b=fVWFkgS/iDG2wNRBQgbUECKMOh E5p8xpbTknBl7VPbIEf3h+WZOTPbJZ4Qk2GTI0gfWqaC9k8tfGXVFffBMv/Lr4m2i0OhIwKq1Ru8J 1I20nFD3dJUa55EpUABHELGSRcSyHKAXkRuTxkDTGXIQ0bvmCJRR2ncqNuuMAfUUo4u3VdAinSzsm fZpLQzP+2F3WrvGjDk9ylHXCTE7XS58+HeJHcW702jdltDhnxQ/j+QWZKUjih9vZs6yiCgZp8fdjp 5nYwkPNbuBkTktFd7BZDSCu+Ac8NvaXX4TMftMMcDoCnHuWY7YPYVWMjSj4ixUQxGiiaDydgFojhF rqAk9yVg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdkw-0003jQ-Rc; Fri, 30 Nov 2018 08:02:34 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdkt-0003gr-KY for linux-riscv@lists.infradead.org; Fri, 30 Nov 2018 08:02:33 +0000 Received: by mail-pg1-x542.google.com with SMTP id d72so2151837pga.9 for ; Fri, 30 Nov 2018 00:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kkVGy4h7Z995lrFmqX6qHIt4h7IAkxhYZu3D8v9Oubs=; b=JKT1gLgUoLVHpe9nJxzu6L/bLqyFy9HwvwF4/VMPXxC+Cq8HGxblegWVPmLLauuWmW 0kZ3dr5XBp6AgrKZujchCgccSWQOFKdIjDTk5P/jvBtxCPEQbDzKH77TQeYRClI/4vnM Zwd0mpi4Z/APgXDB/nuM7Czu4jAEXJDqsD8jxC8aEunGP5MNvlgK5oFv8QXBlxbVdsm2 /9bYqt/FhuQ+WfiK8tTyn2yTasNGTqZwOAGbU3DCaSJ3j68hfo9KeJoftRFzig7OcGFA hZvlXw8moFu25WAQO+qAtYFrGW9AQnbwxg9V6m8spXgGd7R3D01ZxZuoYCss0mG2O5Fr EFKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kkVGy4h7Z995lrFmqX6qHIt4h7IAkxhYZu3D8v9Oubs=; b=FV9mAE9oGX5ratirmmAmTY4GnPjoO3uvha3l7Iayd5lDgx3bOn1OsuTU1ZyOx86eSq +BPP5LqywsrRvOhSZWuY1A49WQ7eerFx4o5VBuH0wVswH/hF69uNHqk+AX6l0Uz5nDgR cjJj/+NO1R3TXRtZN9SsU+UcaNc0poejw6ocAI5SHK8AmymxdLrOCOhEjVR8//z+7pqP zZzhwDozXMcDeRDJQxBW9/JPU4VljXmCF76bWDQy/WIJgtj4S7R88fJB+xPlgpV38tBC K8K1hxlQoLw1FPpZhNbX30r9a32cgtdNKzC+4Xgv3Raer2lgBri/7uRVhFaqCak0Bp3W uiew== X-Gm-Message-State: AA+aEWYJM1+uP2fi0MADtolmtUB5n5BQaVLIu3tBB919TUYjpS0aAUIS vO53Q6cL0zR7HinCVsGMCHgb2w== X-Google-Smtp-Source: AFSGD/UELnKSp4FfeQDOOOJa1A3b/H97XMHjOREzupDHSRM3KVvzwy/kAlWP5yoNIRCwEOA40Iw7OA== X-Received: by 2002:a63:5664:: with SMTP id g36mr3957567pgm.313.1543564945683; Fri, 30 Nov 2018 00:02:25 -0800 (PST) Received: from anup-ubuntu64.qualcomm.com ([49.207.52.208]) by smtp.googlemail.com with ESMTPSA id q187sm19218333pfq.128.2018.11.30.00.02.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:02:24 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v3 2/6] irqchip: sifive-plic: Add struct plic_hw for global PLIC HW details Date: Fri, 30 Nov 2018 13:32:03 +0530 Message-Id: <20181130080207.20505-3-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130080207.20505-1-anup@brainfault.org> References: <20181130080207.20505-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181130_000231_698648_2D208E8A X-CRM114-Status: GOOD ( 16.68 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds Add struct plic_hw to represent global PLIC HW details. Currently, these details are only used in plic_init() but in-future these will be useful in implementing PM suspend and resume callbacks. Further, these global details are good debug info about HW so let's not throw them away after use in plic_init(). Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 59 +++++++++++++++++-------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index c23a293a2aae..48bee877e0f1 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -55,8 +55,6 @@ #define CONTEXT_THRESHOLD 0x00 #define CONTEXT_CLAIM 0x04 -static void __iomem *plic_regs; - struct plic_handler { bool present; void __iomem *hart_base; @@ -67,8 +65,19 @@ struct plic_handler { raw_spinlock_t enable_lock; void __iomem *enable_base; }; + static DEFINE_PER_CPU(struct plic_handler, plic_handlers); +struct plic_hw { + u32 nr_irqs; + u32 nr_handlers; + u32 nr_mapped; + void __iomem *regs; + struct irq_domain *irqdomain; +}; + +static struct plic_hw plic; + static inline void plic_toggle(struct plic_handler *handler, int hwirq, int enable) { @@ -87,7 +96,7 @@ static inline void plic_irq_toggle(struct irq_data *d, int enable) { int cpu; - writel(enable, plic_regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); + writel(enable, plic.regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); for_each_cpu(cpu, irq_data_get_affinity_mask(d)) { struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); @@ -130,8 +139,6 @@ static const struct irq_domain_ops plic_irqdomain_ops = { .xlate = irq_domain_xlate_onecell, }; -static struct irq_domain *plic_irqdomain; - /* * Handling an interrupt is a two-step process: first you claim the interrupt * by reading the claim register, then you complete the interrupt by writing @@ -148,7 +155,7 @@ static void plic_handle_irq(struct pt_regs *regs) csr_clear(sie, SIE_SEIE); while ((hwirq = readl(claim))) { - int irq = irq_find_mapping(plic_irqdomain, hwirq); + int irq = irq_find_mapping(plic.irqdomain, hwirq); if (unlikely(irq <= 0)) pr_warn_ratelimited("can't find mapping for hwirq %lu\n", @@ -177,36 +184,35 @@ static int plic_find_hart_id(struct device_node *node) static int __init plic_init(struct device_node *node, struct device_node *parent) { - int error = 0, nr_handlers, nr_mapped = 0, i; - u32 nr_irqs; + int error = 0, i; - if (plic_regs) { + if (plic.regs) { pr_warn("PLIC already present.\n"); return -ENXIO; } - plic_regs = of_iomap(node, 0); - if (WARN_ON(!plic_regs)) + plic.regs = of_iomap(node, 0); + if (WARN_ON(!plic.regs)) return -EIO; error = -EINVAL; - of_property_read_u32(node, "riscv,ndev", &nr_irqs); - if (WARN_ON(!nr_irqs)) + of_property_read_u32(node, "riscv,ndev", &plic.nr_irqs); + if (WARN_ON(!plic.nr_irqs)) goto out_iounmap; - nr_handlers = of_irq_count(node); - if (WARN_ON(!nr_handlers)) + plic.nr_handlers = of_irq_count(node); + if (WARN_ON(!plic.nr_handlers)) goto out_iounmap; - if (WARN_ON(nr_handlers < num_possible_cpus())) + if (WARN_ON(plic.nr_handlers < num_possible_cpus())) goto out_iounmap; error = -ENOMEM; - plic_irqdomain = irq_domain_add_linear(node, nr_irqs + 1, - &plic_irqdomain_ops, NULL); - if (WARN_ON(!plic_irqdomain)) + plic.irqdomain = irq_domain_add_linear(node, plic.nr_irqs + 1, + &plic_irqdomain_ops, NULL); + if (WARN_ON(!plic.irqdomain)) goto out_iounmap; - for (i = 0; i < nr_handlers; i++) { + for (i = 0; i < plic.nr_handlers; i++) { struct of_phandle_args parent; struct plic_handler *handler; irq_hw_number_t hwirq; @@ -231,25 +237,26 @@ static int __init plic_init(struct device_node *node, handler = per_cpu_ptr(&plic_handlers, cpu); handler->present = true; handler->hart_base = - plic_regs + CONTEXT_BASE + i * CONTEXT_PER_HART; + plic.regs + CONTEXT_BASE + i * CONTEXT_PER_HART; raw_spin_lock_init(&handler->enable_lock); handler->enable_base = - plic_regs + ENABLE_BASE + i * ENABLE_PER_HART; + plic.regs + ENABLE_BASE + i * ENABLE_PER_HART; /* priority must be > threshold to trigger an interrupt */ writel(0, handler->hart_base + CONTEXT_THRESHOLD); - for (hwirq = 1; hwirq <= nr_irqs; hwirq++) + for (hwirq = 1; hwirq <= plic.nr_irqs; hwirq++) plic_toggle(handler, hwirq, 0); - nr_mapped++; + + plic.nr_mapped++; } pr_info("mapped %d interrupts to %d (out of %d) handlers.\n", - nr_irqs, nr_mapped, nr_handlers); + plic.nr_irqs, plic.nr_mapped, plic.nr_handlers); set_handle_irq(plic_handle_irq); return 0; out_iounmap: - iounmap(plic_regs); + iounmap(plic.regs); return error; } From patchwork Fri Nov 30 08:02:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10705879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C12414BD for ; Fri, 30 Nov 2018 08:02:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F05172F4C8 for ; Fri, 30 Nov 2018 08:02:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2DDA2F4D7; Fri, 30 Nov 2018 08:02:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 758F12F4C8 for ; Fri, 30 Nov 2018 08:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=uYpuWWGefuROWiY8GnseNI4mg6rD6/dO012VhTSC5uk=; b=iXWkWpF8wHpX3C5rZrtnTIJ7nq mBMiANY6Ed9Ka6ybK3vkxPdoASw3lp7Ni77iCfWxwPjTYXmr1/ankxo2FfmmUijX6xRr1HUFBISGD EFAAzT6uq/7fhuawIqrBpMnvtN9dGGAMHa104vGoOXlybYmjDQIWi64V2DXJw3fg4I5kWuNQ6mE03 qRKdASHvhsI3CAhPHtiiUlJV6A1hFIzysv87gZstvovmHi/ke9BQc2s5EkzgHsLU3AMyETV0C141q lRgInHN3Lr8uF5JdqfGqmrFzU1TCyTZViCvWNYh+OJ+kqy1osFtKTP53N+rqR0nM6a1qy9orjVZ9f xR/CNd1A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdl6-0003nk-0j; Fri, 30 Nov 2018 08:02:44 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdl3-0003iK-Mb for linux-riscv@lists.infradead.org; Fri, 30 Nov 2018 08:02:43 +0000 Received: by mail-pf1-x443.google.com with SMTP id c73so2383603pfe.13 for ; Fri, 30 Nov 2018 00:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T0WD9iFbcYcBF+9tnjwvFYL8QS9M8hvpmA7nOVXSSFo=; b=wjl1UJN5WECuRxVrxFO9Md5dOpl1rJKgaQyV8B7tM0/JjOOV/jLOt/XmZji9lZGs48 awFXpiHCYYrVS8Bi2booEEZuIE0iJ6XsosqhWClkw3OonRcuZ1r9PTfBckCsRpVSUJsV NzwlRA/e6RUUHH3h7ctHFjbtu/AmUFdcOaLT5enpMwaAJtHQ7PE7S1yUAHjnSN/NbMMU t6NbxUckG7WZe3/fwzN4rO1qurr8osenXi1Pqxn4mxlGBxt1+VOyg8eBu20/m1xP3ABV mwvBNYweGfVg74nXfCOtRsWt7WkxqbWMZD7XsynMBO/faOwBlZm/1NwdgifBLnqJCGyF 1p+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=T0WD9iFbcYcBF+9tnjwvFYL8QS9M8hvpmA7nOVXSSFo=; b=fH2HIM7SLj7ALyEOyTaIjcPIudqA6L8ktWKHoXi3zh1v6580y9iX41k8coLJPEUyjR /KBKWvetnSJcSW7d/3HMBsp2kmY3CCDd1iYdh4O9MzmaKAo4GvgdSSiRiHLX7SBnngkM vrYMYrEplurX7jkWFFdhbuhIX8dooD1nAWRfF7vV9irXX8Djb+2as30lw04htjk7XYPI mQG5jElOyfX03zG2zHVA/a6fgYJYfRjrC3ZN4GM55Oj+uCpMzb7mVbGdaZCU6iR44puL 1UGPkICVI89QLkgOlfO9b4VLp96iz8ZLPy3Qx2Io+kdoWjN/2ZcNK0d8T9As+ja29qrW EN6A== X-Gm-Message-State: AA+aEWZFRQ6Lx14YTvjIVYTJqSrwp01cOyaXoD2/icyyuFQySF/Y0GUC mPO+hnDCO9dWfHxSFL9zI8IYyQ== X-Google-Smtp-Source: AFSGD/UU/M4HBSQV/wbUYfbV4VJLosqQcHkSBmI/FPBg+p0zHXEzcPdn/OHc+YgH8fUfZ3CUYFRP7Q== X-Received: by 2002:a63:4e41:: with SMTP id o1mr2895034pgl.282.1543564950998; Fri, 30 Nov 2018 00:02:30 -0800 (PST) Received: from anup-ubuntu64.qualcomm.com ([49.207.52.208]) by smtp.googlemail.com with ESMTPSA id q187sm19218333pfq.128.2018.11.30.00.02.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:02:30 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v3 3/6] irqchip: sifive-plic: More flexible plic_irq_toggle() Date: Fri, 30 Nov 2018 13:32:04 +0530 Message-Id: <20181130080207.20505-4-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130080207.20505-1-anup@brainfault.org> References: <20181130080207.20505-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181130_000241_740610_218F9A7B X-CRM114-Status: GOOD ( 12.41 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We make plic_irq_toggle() more generic so that we can enable/disable hwirq for given cpumask. This generic plic_irq_toggle() will be eventually used to implement set_affinity for PLIC driver. Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 48bee877e0f1..d4433399eb89 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -78,8 +78,7 @@ struct plic_hw { static struct plic_hw plic; -static inline void plic_toggle(struct plic_handler *handler, - int hwirq, int enable) +static void plic_toggle(struct plic_handler *handler, int hwirq, int enable) { u32 __iomem *reg = handler->enable_base + (hwirq / 32) * sizeof(u32); u32 hwirq_mask = 1 << (hwirq % 32); @@ -92,27 +91,27 @@ static inline void plic_toggle(struct plic_handler *handler, raw_spin_unlock(&handler->enable_lock); } -static inline void plic_irq_toggle(struct irq_data *d, int enable) +static void plic_irq_toggle(const struct cpumask *mask, int hwirq, int enable) { int cpu; - writel(enable, plic.regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); - for_each_cpu(cpu, irq_data_get_affinity_mask(d)) { + writel(enable, plic.regs + PRIORITY_BASE + hwirq * PRIORITY_PER_ID); + for_each_cpu(cpu, mask) { struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); if (handler->present) - plic_toggle(handler, d->hwirq, enable); + plic_toggle(handler, hwirq, enable); } } static void plic_irq_enable(struct irq_data *d) { - plic_irq_toggle(d, 1); + plic_irq_toggle(irq_data_get_affinity_mask(d), d->hwirq, 1); } static void plic_irq_disable(struct irq_data *d) { - plic_irq_toggle(d, 0); + plic_irq_toggle(irq_data_get_affinity_mask(d), d->hwirq, 0); } static struct irq_chip plic_chip = { From patchwork Fri Nov 30 08:02:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10705883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 241691057 for ; Fri, 30 Nov 2018 08:02:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15FF22F4D7 for ; Fri, 30 Nov 2018 08:02:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A64D2F4DF; Fri, 30 Nov 2018 08:02:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 738E02F4D7 for ; Fri, 30 Nov 2018 08:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ec/5ahHQLJgPQZiVdExGnua+lMOFoZy3PWEtGxc6DsQ=; b=tUS0qnAlQiBXCkkyF6WxkMXSNI gEnXPAy5rEH/+9OF7oR0rbmS4hAV9QSCrX9C09Yg5o9my24XvcoG/48uOicOwhb8FBZIYLlIENsSf dKLzLbXXTkc47wClNhf3BIQIeCu8a3OwU1IyAHEZxjmTZZl2FwVYlKtGzPnh6iD+gRJt+UlxLWoeB +rl+i+bk/EpsNRzS3nx5KzZOLs3dSS51KNvyXqpwYvVIWRkHqxDI9xbrHreJKNkmeX5TO2GXNZIrK hBf8wpolNanD2X9lihU/kE89Z/4AzvP8ASQs1EdSTcHf2luxcR0+Krl6yuRCTwAR4z6wliJ5Pz2wV A73k2x7w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdlF-0003qh-Tp; Fri, 30 Nov 2018 08:02:53 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdl8-0003lA-SV for linux-riscv@lists.infradead.org; Fri, 30 Nov 2018 08:02:52 +0000 Received: by mail-pf1-x444.google.com with SMTP id h3so2410640pfg.1 for ; Fri, 30 Nov 2018 00:02:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lMAJpPkeXbFuvURRfJbfrtp/xBSKSRsVuvnhRc6stns=; b=SFxS6wu6QrPWQfl28NHZOLuzvYcc5IHvoKBoVzgU6Z+qFtN4IDpNxafnC+mj7ba1SQ KSqsDSPzg+mIvMwgwPdwA3VP3qwrbjBYOXP3NIqq0QaUqKiztCaedvteBp/mH26MBBrs oZjxmlPr8qu548LkXpr53hAmS762GB/mO4ULcgFEs6HyXltot17GZg5XNDwdGr+0KmHe e9JhjAnRfLFLVXDXSxFPwmqzCDQsJFdhFn2fXO34yVsBhtXrdnP9HYn82Wfmaw7wRgS3 DZpzvK8wASRgFZR41lhI9oNS5c1ZdQL2+LWcF9KpJs9OcsPEp/9KI0A7KrDtnwQ8a05J BErA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lMAJpPkeXbFuvURRfJbfrtp/xBSKSRsVuvnhRc6stns=; b=pzY2UnFX6GjSOZpZOKlEp4e0m7b93r7AStQgqVyvAtJBD6CpVyUY76bIM8AF1HEzOu YMvFzjRUEihNoF9irZwH4PTnzKc6v+JaV0rWF3Fd9LdYeSw6nLKiQR/7p5Lu8sStVg2h 6DQvxIhWpd+H1NlbSlHILDxtLABkvTMzSG+kbDJVVwD6pjYHPi6zQ+jG2ZSnMkV9OwvC 5tPbBdqFtayYxQYZKPx4eetk73ffOwJP4fXf8tgJyx9lwuaU+dJMGdD8l3b6jAB1N7sP VMDJv1ms7w1E9YMN1yuaFuRe70vDPEJo/YPXnU1XDJzRU2G+bTaoZEyhZvqrK5dI5uwu L0tA== X-Gm-Message-State: AA+aEWZmiCfF701wL2lE3xkN/vBgIjFaUOUh5iB4HSfb9J6VM8dvAKJh ZBBV5vHy8Oznufl3SPAQ06I87A== X-Google-Smtp-Source: AFSGD/UkXS06dwoA9Vc9rLmPQ8Dro3U/CzAEklnNoR3GBBxZQBrzULpEwg0QAav6T5dp2lppp4nFwg== X-Received: by 2002:a63:6704:: with SMTP id b4mr4048021pgc.100.1543564956124; Fri, 30 Nov 2018 00:02:36 -0800 (PST) Received: from anup-ubuntu64.qualcomm.com ([49.207.52.208]) by smtp.googlemail.com with ESMTPSA id q187sm19218333pfq.128.2018.11.30.00.02.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:02:35 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v3 4/6] irqchip: sifive-plic: Add warning in plic_init() if handler already present Date: Fri, 30 Nov 2018 13:32:05 +0530 Message-Id: <20181130080207.20505-5-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130080207.20505-1-anup@brainfault.org> References: <20181130080207.20505-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181130_000246_925072_3225AFF2 X-CRM114-Status: GOOD ( 12.70 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We have two enteries (one for M-mode and another for S-mode) in the interrupts-extended DT property of PLIC DT node for each HART. It is expected that firmware/bootloader will set M-mode HWIRQ line of each HART to 0xffffffff (i.e. -1) in interrupts-extended DT property because Linux runs in S-mode only. If firmware/bootloader is buggy then it will not correctly update interrupts-extended DT property which might result in a plic_handler configured twice. This patch adds a warning in plic_init() if a plic_handler is already marked present. This warning provides us a hint about incorrectly updated interrupts-extended DT property. Signed-off-by: Anup Patel Reviewed-by: Christoph Hellwig --- drivers/irqchip/irq-sifive-plic.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index d4433399eb89..3d4f205f8abe 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -234,6 +234,11 @@ static int __init plic_init(struct device_node *node, cpu = riscv_hartid_to_cpuid(hartid); handler = per_cpu_ptr(&plic_handlers, cpu); + if (handler->present) { + pr_warn("handler not available for context %d.\n", i); + continue; + } + handler->present = true; handler->hart_base = plic.regs + CONTEXT_BASE + i * CONTEXT_PER_HART; From patchwork Fri Nov 30 08:02:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10705885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFECD18B8 for ; Fri, 30 Nov 2018 08:02:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC66E2F4D7 for ; Fri, 30 Nov 2018 08:02:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A04422F4DF; Fri, 30 Nov 2018 08:02:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4A1092F4D7 for ; Fri, 30 Nov 2018 08:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=w+Fg1U8aw2dUQbkaBm0s96OdGD/D+9/Po5ezHoEZusA=; b=q9P+bLwu43NwSZCEkKl3EfPizm MO4ziq+Svu7EbqphAX8wzdwp5hlUa1XClssu47+9mEmF7iyVZI5voTon/FJt5xz/hIY7jWyISurGb h/3fkaLapZume/wG2UwLKpSNdhkJxVGDBCPPu7q5npVvoUjvfqTYXwXdRc1ssKgJ1sU+DgoY6d1Bl Db+ZuZR1QwRRBR9ZZgCiZDLhA/8YmQJrBuy1UBGfAC2CcCEOiy8H5nn2kWgOskmmHWPg0B0f8etEp s9JE0U1atiGt9k3nlE1oD4jFZZU6lcYU9McOdmPSjfwgVkqJKoXVd1fZ4hdqIKQs3KyBlwnPsCtrV PQbLSG1Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdlG-0003rC-Ji; Fri, 30 Nov 2018 08:02:54 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdlE-0003nR-72 for linux-riscv@lists.infradead.org; Fri, 30 Nov 2018 08:02:53 +0000 Received: by mail-pg1-x542.google.com with SMTP id w6so2154026pgl.6 for ; Fri, 30 Nov 2018 00:02:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y8woPMXFiJ/bqS4NqZSMmewmTRycAL+/cf63Vbbt8Og=; b=w/ILh2VVjIvb0OZr5mEthR5pDNyfJ4RqF0CC5updn9x+yUZ5JCQFeH9LK0n2Jlw+nG lavR/ssF/qZdGeBR53w55ygWWcx0zKOrmofHnjani0VuFFUKM3DYIqp/bqxUqbHK69OH XOWfF6MQK7mHVSn6PWLUOtpkUcCZy8GLQEdEvuAfbvDJCArAc8oYbFNdi9AOA8CbiRqf 6mVLYfVaUamIN6W+8xoqF3W+y4c4cY30gjd5fn0ARl0NK5Y9dJ7/vbHy/BdJ80/ZlJt/ Q79Rt96aih642QXCNkGIMgxFeKUsm6t5FM5vW3B3GiU0g9XPfwZMH2XSkeR16JskCWm2 Sk5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y8woPMXFiJ/bqS4NqZSMmewmTRycAL+/cf63Vbbt8Og=; b=o/oYf6y8NNESo74nzIsO2JkSe8lSNJBJT8FBbMvbLqnfAYpmSgzuZ7skjw8fTevGVg b0i/qFZmDgG17afLi0j5lkdXNYrKfflCNnoOA8h566PBdehWv6b2dMC8lTF1TjfdbVEP 1fCSEAkwe9wY8SJnctJiTN/k1RqLCCjgnG0GE9M6PfyG2fUJKJk0k0g5E/OZj9Pbvs6s Uw1MkAfCytNJ4IKkk4JgP9df0gPdGp8N48PT+78zDoT2djAAPToH/Tqc5MZ/A5mq+T/Q 4l9nuyysweyh0hlEDdTbj4ilucYHFoYeAoG+LKeQfbUazQl2uelHd7fyB92rVtf2XUbM hJig== X-Gm-Message-State: AA+aEWbYaMYrrgXw5ISskf8WXGfbr2kS0GYuqVes8ujyCs9G99pdUAno XGp4On0PvvuPTaj0ZpA5o3/RCw== X-Google-Smtp-Source: AFSGD/X4AHzSy9NqZFPoML2SPGN1tycQC1cBP094GX+P9vrmXoBVGeYoFWgsJk4IhYubWnVVYh6CNA== X-Received: by 2002:a62:5486:: with SMTP id i128mr4533509pfb.215.1543564961520; Fri, 30 Nov 2018 00:02:41 -0800 (PST) Received: from anup-ubuntu64.qualcomm.com ([49.207.52.208]) by smtp.googlemail.com with ESMTPSA id q187sm19218333pfq.128.2018.11.30.00.02.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:02:40 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v3 5/6] irqchip: sifive-plic: Differentiate between PLIC handler and context Date: Fri, 30 Nov 2018 13:32:06 +0530 Message-Id: <20181130080207.20505-6-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130080207.20505-1-anup@brainfault.org> References: <20181130080207.20505-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181130_000252_251885_58AA75D2 X-CRM114-Status: GOOD ( 12.44 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We explicitly differentiate between PLIC handler and context because PLIC context is for given mode of HART whereas PLIC handler is per-CPU software construct meant for handling interrupts from a particular PLIC context. To achieve this differentiation, we rename "nr_handlers" to "nr_contexts" and "nr_mapped" to "nr_handlers" in struct plic_hw. Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 3d4f205f8abe..17269622be21 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -70,8 +70,8 @@ static DEFINE_PER_CPU(struct plic_handler, plic_handlers); struct plic_hw { u32 nr_irqs; + u32 nr_contexts; u32 nr_handlers; - u32 nr_mapped; void __iomem *regs; struct irq_domain *irqdomain; }; @@ -199,10 +199,10 @@ static int __init plic_init(struct device_node *node, if (WARN_ON(!plic.nr_irqs)) goto out_iounmap; - plic.nr_handlers = of_irq_count(node); - if (WARN_ON(!plic.nr_handlers)) + plic.nr_contexts = of_irq_count(node); + if (WARN_ON(!plic.nr_contexts)) goto out_iounmap; - if (WARN_ON(plic.nr_handlers < num_possible_cpus())) + if (WARN_ON(plic.nr_contexts < num_possible_cpus())) goto out_iounmap; error = -ENOMEM; @@ -211,7 +211,7 @@ static int __init plic_init(struct device_node *node, if (WARN_ON(!plic.irqdomain)) goto out_iounmap; - for (i = 0; i < plic.nr_handlers; i++) { + for (i = 0; i < plic.nr_contexts; i++) { struct of_phandle_args parent; struct plic_handler *handler; irq_hw_number_t hwirq; @@ -251,11 +251,11 @@ static int __init plic_init(struct device_node *node, for (hwirq = 1; hwirq <= plic.nr_irqs; hwirq++) plic_toggle(handler, hwirq, 0); - plic.nr_mapped++; + plic.nr_handlers++; } - pr_info("mapped %d interrupts to %d (out of %d) handlers.\n", - plic.nr_irqs, plic.nr_mapped, plic.nr_handlers); + pr_info("mapped %d interrupts with %d handlers for %d contexts.\n", + plic.nr_irqs, plic.nr_handlers, plic.nr_contexts); set_handle_irq(plic_handle_irq); return 0; From patchwork Fri Nov 30 08:02:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10705887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEFC21057 for ; Fri, 30 Nov 2018 08:03:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0DE02F4DF for ; Fri, 30 Nov 2018 08:03:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D53012F4E3; Fri, 30 Nov 2018 08:03:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6FF6F2F4DF for ; Fri, 30 Nov 2018 08:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=lFyKMmBvJzV6uEsi3rj4y27i2Jya/A4m9ugD5DdrzUI=; b=gLDAGrVA88hi9BCc0/MwOrhZZT GfYugqkG8IXJZjIUJPGJ/ra5z+swnS0yP6Ac/pTCBRHOg+IPiQNrKdR3FxnNYgLKCfgIzCwfXpuaZ LulzHBosa/k1QuaHOVNuLNHTGoQ2ip+Bqmyh1uF4UdU2Xc8SRBmsZ6YyN0XLmRQX5juPFFUz/q6bn BeRX24q7WaXtWSAkANhvhvl+z7i8Vm8EVHbqAg3A+oXJCXU6j8pv/r6Bnbd9qXGgDCOD2FpfLn40h zLTMbRNkeZlvpo4ve5dDYDuvRZO2P29lqvw/mOOFD7iAnPdXM4my93B7sgP/t1pQVF6NijHp9EEUQ NRF5xN5g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdlM-0003uo-WB; Fri, 30 Nov 2018 08:03:01 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSdlJ-0003q0-Er for linux-riscv@lists.infradead.org; Fri, 30 Nov 2018 08:02:58 +0000 Received: by mail-pl1-x644.google.com with SMTP id p8so2426039plo.2 for ; Fri, 30 Nov 2018 00:02:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vvfSG98aNiXqSmgABJxQO+jhN81ElYo6VSgb9BxCS6Q=; b=yTXZdN85ZwFfIRh1qgNRjeFsJKWoxepZuxHlpZbdmay2uZ4LPGUS17QOI5fEb8RIVA +VMW0K/qzALTAekgIyXWtxC+Dheb5KM5+t/QqGIrTXPOsK/27eRj/k70dKhjICK53We4 jnhD5aRliWYYOdbUmiwEVkkCrzhHL/LK/9oOhc8hMqTQW2wJHZQdoR7GBs3XX0ExRRwJ hI4NyChD4BwPfTXTsoTHgYx+tHcWUHshM9+ExCJ7gRHutJ81gtW9m4QpWqEkY0eDefyb Iy/R2s/D0gkuYK90IhcQatA5BKrjmaI1nStvIPH+0AzC72RUjRdZuM38KIUaB2XeEYsK wclA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vvfSG98aNiXqSmgABJxQO+jhN81ElYo6VSgb9BxCS6Q=; b=N2n95pEMK8Dmo2dqopB1Qp030WSAe780hI5/G1C1f3Yexsq7NIsyo+f633SeJqfDxU yqxhhRNgIXWTZA9WYxWU0tbsiGIbRZSNQxcf3ayGHegKZ+D81Nz8/GWWf0ljJT3IPebT 6sjClQbC8UpamU2fu5MCiOw86CjHm+fqoDJXJc4dGbZm4BFlEoEzNDQnb/gQOsuQ6qAU GpWnf4P3t8vv+EupdIxOj9NXFP1VV/Ln41r+592AZ/1ADxKpdvmC4kurt5Fgdc8YfN+A ZimpyfZDy4vD9AtBaDXx4cyukMaKcZdJ58i2xFsvvTj7uZTxTz9NRfZAUIZFqu5Fl5PV 45pg== X-Gm-Message-State: AA+aEWatUWUUvkqt2KUuX87pJZSMZ2OvVutxSr/1fKf7GRisAeXDipP8 ugkGd0uyH1JLLzZPSCU/Mi26iQ== X-Google-Smtp-Source: AFSGD/Xoui3ezebGaCOi5/CYqeIairgBmj5UztDHX+apMQ33KkcwVugVt3KsDrNoDP5r/wC6hhdNbQ== X-Received: by 2002:a17:902:784d:: with SMTP id e13mr4792786pln.188.1543564966690; Fri, 30 Nov 2018 00:02:46 -0800 (PST) Received: from anup-ubuntu64.qualcomm.com ([49.207.52.208]) by smtp.googlemail.com with ESMTPSA id q187sm19218333pfq.128.2018.11.30.00.02.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:02:46 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v3 6/6] irqchip: sifive-plic: Implement irq_set_affinity() for SMP host Date: Fri, 30 Nov 2018 13:32:07 +0530 Message-Id: <20181130080207.20505-7-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130080207.20505-1-anup@brainfault.org> References: <20181130080207.20505-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181130_000257_543360_98FC896C X-CRM114-Status: GOOD ( 14.15 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently on SMP host, all CPUs take external interrupts routed via PLIC. All CPUs will try to claim a given external interrupt but only one of them will succeed while other CPUs would simply resume whatever they were doing before. This means if we have N CPUs then for every external interrupt N-1 CPUs will always fail to claim it and waste their CPU time. Instead of above, external interrupts should be taken by only one CPU and we should have provision to explicitly specify IRQ affinity from kernel-space or user-space. This patch provides irq_set_affinity() implementation for PLIC driver. It also updates irq_enable() such that PLIC interrupts are only enabled for one of CPUs specified in IRQ affinity mask. With this patch in-place, we can change IRQ affinity at any-time from user-space using procfs. Example: / # cat /proc/interrupts CPU0 CPU1 CPU2 CPU3 8: 44 0 0 0 SiFive PLIC 8 virtio0 10: 48 0 0 0 SiFive PLIC 10 ttyS0 IPI0: 55 663 58 363 Rescheduling interrupts IPI1: 0 1 3 16 Function call interrupts / # / # / # echo 4 > /proc/irq/10/smp_affinity / # / # cat /proc/interrupts CPU0 CPU1 CPU2 CPU3 8: 45 0 0 0 SiFive PLIC 8 virtio0 10: 160 0 17 0 SiFive PLIC 10 ttyS0 IPI0: 68 693 77 410 Rescheduling interrupts IPI1: 0 2 3 16 Function call interrupts Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 35 +++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 17269622be21..c5bbb12e74e0 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -106,14 +106,42 @@ static void plic_irq_toggle(const struct cpumask *mask, int hwirq, int enable) static void plic_irq_enable(struct irq_data *d) { - plic_irq_toggle(irq_data_get_affinity_mask(d), d->hwirq, 1); + unsigned int cpu = cpumask_any_and(irq_data_get_affinity_mask(d), + cpu_online_mask); + WARN_ON(cpu >= nr_cpu_ids); + plic_irq_toggle(cpumask_of(cpu), d->hwirq, 1); } static void plic_irq_disable(struct irq_data *d) { - plic_irq_toggle(irq_data_get_affinity_mask(d), d->hwirq, 0); + plic_irq_toggle(cpu_possible_mask, d->hwirq, 0); } +#ifdef CONFIG_SMP +static int plic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, + bool force) +{ + unsigned int cpu; + + if (!force) + cpu = cpumask_any_and(mask_val, cpu_online_mask); + else + cpu = cpumask_first(mask_val); + + if (cpu >= nr_cpu_ids) + return -EINVAL; + + if (!irqd_irq_disabled(d)) { + plic_irq_toggle(cpu_possible_mask, d->hwirq, 0); + plic_irq_toggle(cpumask_of(cpu), d->hwirq, 1); + } + + irq_data_update_effective_affinity(d, cpumask_of(cpu)); + + return IRQ_SET_MASK_OK_DONE; +} +#endif + static struct irq_chip plic_chip = { .name = "SiFive PLIC", /* @@ -122,6 +150,9 @@ static struct irq_chip plic_chip = { */ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, +#ifdef CONFIG_SMP + .irq_set_affinity = plic_set_affinity, +#endif }; static int plic_irqdomain_map(struct irq_domain *d, unsigned int irq,