Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1516702ybv; Thu, 20 Feb 2020 22:16:13 -0800 (PST) X-Google-Smtp-Source: APXvYqyh26pedu+kXHmMSVZDGvMyLtasmtfA4VVRrxi2yPsGLyJnzJmgmptn15odHbh69GgrXnAF X-Received: by 2002:aca:ed94:: with SMTP id l142mr742302oih.58.1582265773609; Thu, 20 Feb 2020 22:16:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582265773; cv=none; d=google.com; s=arc-20160816; b=T5XmSyuxmNdkUL4sElQLFDFSrfRxFeH4xy9/abWfByo+qfvcJXGncumkWo5nWBjibA R2IErh5FQF1BLwEaQbfdJ9Uq0LrcM3fYK0onKZ5YaHNpY2X5DoN80xn8hZgUJgZnxX/d HMj+EOFSojJvBR21OQuWY7oZ2lCYofgffRq4ZhLlUPfpFir4ZOdgPPxGLwFtodOR9Gip t+QW78agS/DzCUmINXPNJxlzPPutZmkmE1Taiy4iFQUCiYlshdyYE7vFNKGXs9wdgfJy AnS4UVl6x6zAdfmj9nGq/qKrvDjdCVwCnQxdskSr2OVY9k6N7DFG/Tojyp3kZlJ89LBe 14Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=9NPzj0GacQ93xagAlNK8LgngBMkJMj6Y7tJEVRY8XPM=; b=cbtf++mBvnElQIJSn0raLHcIhvAzdJY40P5vyN0fHN5C1ZvXByyzJoWtNUdrMg0u+p FakZa4ftALoH9X4uqwItsVOO5glbLhdyl9i+DdRECvUHPw3ZDpN6QCitchObvQQgzjhp aPVEArXm1BbxHo8Raw7PSmAJGujr8fP7Fd3Kp8ePdsdG46IzgU3iIMFjCU/tPFNq0eq7 /tVa6gyJOIHs+pMUN8QPej1Yu5V3iN+jVDZHe48iLfdQSps2ruKyUJp8jbVUpihHSTA2 qXDeeeaCWzgZDJxTH9v8Ld29NVXKh8WJDFqcG6yV+UI5UnPF7xDTBX968OrxrwXmdtwZ LMPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=IFrjxLAf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u25si276534oic.160.2020.02.20.22.16.00; Thu, 20 Feb 2020 22:16:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=IFrjxLAf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726834AbgBUGOW (ORCPT + 99 others); Fri, 21 Feb 2020 01:14:22 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37138 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbgBUGOV (ORCPT ); Fri, 21 Feb 2020 01:14:21 -0500 Received: by mail-wm1-f68.google.com with SMTP id a6so434043wme.2 for ; Thu, 20 Feb 2020 22:14:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9NPzj0GacQ93xagAlNK8LgngBMkJMj6Y7tJEVRY8XPM=; b=IFrjxLAfYapdU82d5FN6Qpsf+Ekh+12KMYjkVEpMNW7/82DoOy8WVlYlz+Rzqoo34M JaoqTfkCCsbEeHTvN9kVq97rWd2e2Eygj+xOjfwThwCc/oD0gaqh7d+LTvjjKTjK000G 07hI03SrOmtad3wAPZaSYI+Mll+T+Of2cb7W7o/cZKBwVc6byUMAdIZocZ/FFIj1h+b5 UU/JAVH66iBb5kU+SjOB8BHk0vBXOZ2q2IN9PX4SSejcWucMniJO25FshU0UDI/u/QcC /MC/vrICzX4QuZc21dWcDs0hYHqKHSeNXxreulhqmbWe1g+axscyL9sWWuWceHf/Lsfs NKHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9NPzj0GacQ93xagAlNK8LgngBMkJMj6Y7tJEVRY8XPM=; b=WWxljIZFEyquVWmzzKmdEHaGytwr4Xwe556G/A/eLLz6n0FZzkb5Tn2PKHjazRHWoW 0I0kpPFqE7/1/M91gh3KezRdSH0mT8nXObnabg1YlbbioNalrVu8K0c0pSbNZGV+HFe+ ABakjQMA3jQ9SeA+CGxgNRk8JD5lOBDpu4K435oibeeE5RPuIXeVaRyrW9IzjtJlgTlK W7uMKyIgVGflQKMzfrBJFMrv2hR04by6XJB/NIKEIVxsIyUC8aDmjVDeje+PAN5N3YHg WieEJcwxBEhM53l4ZDLYtZAaPbKy+UXRzLsl5JvZbnpZG3Tn65jV1AzL44FCvlU7XAL/ 2/oA== X-Gm-Message-State: APjAAAV+d+RzU2Szl3iyPJJIG+4JjN00m0EoF40MS/3kBwlYjjZiHheN UZZkfgOocR2DT6AOQ0At3ksJ5mXq95fDBGLssbtZQA== X-Received: by 2002:a05:600c:285:: with SMTP id 5mr1535010wmk.120.1582265658118; Thu, 20 Feb 2020 22:14:18 -0800 (PST) MIME-Version: 1.0 References: <20200221004413.12869-1-atish.patra@wdc.com> <20200221004413.12869-13-atish.patra@wdc.com> In-Reply-To: <20200221004413.12869-13-atish.patra@wdc.com> From: Anup Patel Date: Fri, 21 Feb 2020 11:44:06 +0530 Message-ID: Subject: Re: [PATCH v9 12/12] irqchip/sifive-plic: Initialize the plic handler when cpu comes online To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Albert Ou , Borislav Petkov , Daniel Lezcano , "Eric W. Biederman" , Geert Uytterhoeven , Greg Kroah-Hartman , Heiko Carstens , Jason Cooper , Kees Cook , linux-riscv , Mao Han , Marc Zyngier , Mike Rapoport , Nick Hu , Palmer Dabbelt , Paul Walmsley , "Rafael J. Wysocki" , Thomas Gleixner , Vincent Chen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 21, 2020 at 6:14 AM Atish Patra wrote: > > Currently, plic threshold and priority are only initialized once in the > beginning. However, threshold can be set to disabled if cpu is marked > offline with cpu hotplug feature. This will not allow to change the > irq affinity to a cpu that just came online. > > Add plic specific cpu hotplug callback and initialize the per cpu handler > when cpu comes online. > > Signed-off-by: Atish Patra > --- > arch/riscv/kernel/traps.c | 2 +- > drivers/irqchip/irq-sifive-plic.c | 38 +++++++++++++++++++++++++++---- > include/linux/cpuhotplug.h | 1 + > 3 files changed, 36 insertions(+), 5 deletions(-) > > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > index 8e13ad45ccaa..16c59807da6a 100644 > --- a/arch/riscv/kernel/traps.c > +++ b/arch/riscv/kernel/traps.c > @@ -157,5 +157,5 @@ void trap_init(void) > /* Set the exception vector address */ > csr_write(CSR_TVEC, &handle_exception); > /* Enable interrupts */ > - csr_write(CSR_IE, IE_SIE | IE_EIE); > + csr_write(CSR_IE, IE_SIE); > } > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > index aa4af886e43a..7c7f37393f99 100644 > --- a/drivers/irqchip/irq-sifive-plic.c > +++ b/drivers/irqchip/irq-sifive-plic.c > @@ -4,6 +4,7 @@ > * Copyright (C) 2018 Christoph Hellwig > */ > #define pr_fmt(fmt) "plic: " fmt > +#include > #include > #include > #include > @@ -55,6 +56,9 @@ > #define CONTEXT_THRESHOLD 0x00 > #define CONTEXT_CLAIM 0x04 > > +#define PLIC_DISABLE_THRESHOLD 0xf > +#define PLIC_ENABLE_THRESHOLD 0 > + > static void __iomem *plic_regs; > > struct plic_handler { > @@ -230,6 +234,32 @@ static int plic_find_hart_id(struct device_node *node) > return -1; > } > > +static void plic_set_threshold(struct plic_handler *handler, u32 threshold) > +{ > + /* priority must be > threshold to trigger an interrupt */ > + writel(threshold, handler->hart_base + CONTEXT_THRESHOLD); > +} > + > +static int plic_dying_cpu(unsigned int cpu) > +{ > + struct plic_handler *handler = this_cpu_ptr(&plic_handlers); > + > + csr_clear(CSR_IE, IE_EIE); > + plic_set_threshold(handler, PLIC_DISABLE_THRESHOLD); > + > + return 0; > +} > + > +static int plic_starting_cpu(unsigned int cpu) > +{ > + struct plic_handler *handler = this_cpu_ptr(&plic_handlers); > + > + csr_set(CSR_IE, IE_EIE); > + plic_set_threshold(handler, PLIC_ENABLE_THRESHOLD); > + > + return 0; > +} > + > static int __init plic_init(struct device_node *node, > struct device_node *parent) > { > @@ -267,7 +297,6 @@ static int __init plic_init(struct device_node *node, > struct plic_handler *handler; > irq_hw_number_t hwirq; > int cpu, hartid; > - u32 threshold = 0; > > if (of_irq_parse_one(node, i, &parent)) { > pr_err("failed to parse parent for context %d.\n", i); > @@ -301,7 +330,7 @@ static int __init plic_init(struct device_node *node, > handler = per_cpu_ptr(&plic_handlers, cpu); > if (handler->present) { > pr_warn("handler already present for context %d.\n", i); > - threshold = 0xffffffff; > + plic_set_threshold(handler, PLIC_DISABLE_THRESHOLD); > goto done; > } > > @@ -313,13 +342,14 @@ static int __init plic_init(struct device_node *node, > plic_regs + ENABLE_BASE + i * ENABLE_PER_HART; > > done: > - /* priority must be > threshold to trigger an interrupt */ > - writel(threshold, handler->hart_base + CONTEXT_THRESHOLD); > for (hwirq = 1; hwirq <= nr_irqs; hwirq++) > plic_toggle(handler, hwirq, 0); > nr_handlers++; > } > > + cpuhp_setup_state(CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING, > + "irqchip/sifive/plic:starting", > + plic_starting_cpu, plic_dying_cpu); > pr_info("mapped %d interrupts with %d handlers for %d contexts.\n", > nr_irqs, nr_handlers, nr_contexts); > set_handle_irq(plic_handle_irq); > diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h > index d37c17e68268..77d70b633531 100644 > --- a/include/linux/cpuhotplug.h > +++ b/include/linux/cpuhotplug.h > @@ -102,6 +102,7 @@ enum cpuhp_state { > CPUHP_AP_IRQ_ARMADA_XP_STARTING, > CPUHP_AP_IRQ_BCM2836_STARTING, > CPUHP_AP_IRQ_MIPS_GIC_STARTING, > + CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING, > CPUHP_AP_ARM_MVEBU_COHERENCY, > CPUHP_AP_MICROCODE_LOADER, > CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING, > -- > 2.25.0 > Looks good to me. Reviewed-by: Anup Patel I will rebase my RISC-V local interrupt controller driver patches upon this patch series. Regards, Anup