From patchwork Thu Feb 22 09:39:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13566957 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97369C48BEB for ; Thu, 22 Feb 2024 09:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EF0MjOTUoaAH4GBsR1fnlRdfcYP0iiXGIK6tw4fjOx4=; b=YZAczlqdEEfn2f MNm9XHZefn7MQlGTM4Mv5zcFiLXTqL5NGEZ7RHBnzJL4a0ELVJgiKZCDjjtsCH+izc123j6bK5y8T 2qyaNj3I3etTyj4PTEBuyzdQDXNAgm+rU9IelKQ+Y3dK5ADjEskAAc3Rv3f7Woo513tbjNv+Gy8nC l4UNFIu8qGVD2dXVfRmT8e42mZcg6IKqBT97ClB/pR+mnRMi7cG/gZydxboZEzdoZ7Ga+lRXGimy9 yaNufcXc1MFbkUX0X2W82cvoXP3lwixXmZlRJ52XyMEovPVzkh/oWiBMxqtUDNnil3L7sp+CM4VCD 5xF0yQWIHERnXnBbAJJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5av-00000004JCI-1x3y; Thu, 22 Feb 2024 09:42:21 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5Zx-00000004IPs-2pWE for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2024 09:41:23 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3c03b92998eso5663038b6e.3 for ; Thu, 22 Feb 2024 01:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708594881; x=1709199681; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Dw8y24wZWNZ04w7x8csHkLTJ35ivq17oSt9+7/D12iY=; b=mRJxLRhdBtDLePh31fEhQ+wv1s5PiqXg7TnXV4YMJm1GESE8UjAxm8k7kas7uwHAHi rXKHiMY20YQm8xJYd2oDpuw9cMNJ62OXZ3c0WRNQmqEt4IcjFmhlWv8LjxgP+/iWbUX5 1iUnFypDQaI9eTNFdiv9VcExNRGKVahqhSAXaBdbhvGlCnjySt+0jswGSITb2YW5xv8B VT1fmaoOZLFkWH6ydEYWuoYv+MgWtsPtSyKrd6CEwhBtQf9z/hFXlTPyawcfnQifIDBB LUDM60s9W503XWjIyV5eNkGELd7VYGT2rLbUVuSltcFUVt9q2wThbEVujLph60o2TDqa 8eag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708594881; x=1709199681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dw8y24wZWNZ04w7x8csHkLTJ35ivq17oSt9+7/D12iY=; b=vSR7YJdHo+gEtn/3J+6M2b88BNtIUb/wox7RhYyX9BznYtvYQNinF0cYmbDXfBlBIy 0CsRulEMDRB1bsB3foPlcbhBQB0D40ob63sNK2rIvL0Lq4Oe7ZOE5e9+ES1vEgoNxOoX /bE5WOcy5u0cF0BWLxlQl0ECuKFo7om72WrfI6LWqKBOPbD6tVnVBPE9RmM2zZJM4t5b 80fcSvJeVZ+RTvluLakEWvvrU6Xs1ip7qQNyw3o548C924RGoRzKvii45dvylbQaXKSJ ZnZPHInxmI6awIOoofqBG8wXFaUzqZ9qMQDjVM85w+QJl2skr0hxyysRQxnJgqN/un/n 3gRg== X-Forwarded-Encrypted: i=1; AJvYcCVnYloNxsoSNZYZv23taqhnk6h8rnROHhwH4AKCS6xIT50F3w/jToKp8ryzBTYCv+AcHFAag9KGHsaB/vrB2UE6Um23NemUi0I0qFLbwb4VichKW4s= X-Gm-Message-State: AOJu0YwkMjmpzgID+cmoVRE0JtVtegAMwuhO72Q8lYH4kK1cx4r+6zOj xNJ/nKsSkbqc/kOvYTf4ZTapkbGdDq4PH5oMn6e5XyYlLVp1Jp4/aL/UO8txN9Q= X-Google-Smtp-Source: AGHT+IEOb1Yx2hf7SfgFjAX4PLImkj9wNrlWxC26sYi3FIjcQ1SGd91HFyROaXeS/Zjiup30flFeDw== X-Received: by 2002:a05:6808:d47:b0:3c1:8039:f8b9 with SMTP id w7-20020a0568080d4700b003c18039f8b9mr408375oik.21.1708594880741; Thu, 22 Feb 2024 01:41:20 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n15-20020a05680803af00b003c17c2b8d09sm130699oie.31.2024.02.22.01.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:41:20 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley Cc: Marc Zyngier , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Atish Patra , Andrew Jones , Sunil V L , Saravana Kannan , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Anup Patel Subject: [PATCH v14 08/18] irqchip/riscv-intc: Add support for RISC-V AIA Date: Thu, 22 Feb 2024 15:09:56 +0530 Message-Id: <20240222094006.1030709-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222094006.1030709-1-apatel@ventanamicro.com> References: <20240222094006.1030709-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_014121_810782_80FEA2CE X-CRM114-Status: GOOD ( 14.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Add support for #1 and #2 described above in the RISC-V intc driver. Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-intc.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index e8d01b14ccdd..8997f6986f89 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,14 @@ 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 = 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 writing * the SIE (Supervisor Interrupt Enable) CSR. As CSRs can only be written @@ -39,12 +48,18 @@ static asmlinkage void riscv_intc_irq(struct pt_regs *regs) static void riscv_intc_irq_mask(struct irq_data *d) { - csr_clear(CSR_IE, BIT(d->hwirq)); + if (IS_ENABLED(CONFIG_32BIT) && d->hwirq >= BITS_PER_LONG) + csr_clear(CSR_IEH, BIT(d->hwirq - BITS_PER_LONG)); + else + csr_clear(CSR_IE, BIT(d->hwirq)); } static void riscv_intc_irq_unmask(struct irq_data *d) { - csr_set(CSR_IE, BIT(d->hwirq)); + if (IS_ENABLED(CONFIG_32BIT) && d->hwirq >= BITS_PER_LONG) + csr_set(CSR_IEH, BIT(d->hwirq - BITS_PER_LONG)); + else + csr_set(CSR_IE, BIT(d->hwirq)); } static void riscv_intc_irq_eoi(struct irq_data *d) @@ -115,16 +130,18 @@ static struct fwnode_handle *riscv_intc_hwnode(void) static int __init riscv_intc_init_common(struct fwnode_handle *fn) { - int rc; + int rc, nr_irqs = riscv_isa_extension_available(NULL, SxAIA) ? 64 : BITS_PER_LONG; - intc_domain = irq_domain_create_linear(fn, BITS_PER_LONG, - &riscv_intc_domain_ops, NULL); + intc_domain = irq_domain_create_linear(fn, nr_irqs, &riscv_intc_domain_ops, NULL); if (!intc_domain) { pr_err("unable to add IRQ domain\n"); return -ENXIO; } - rc = set_handle_irq(&riscv_intc_irq); + if (riscv_isa_extension_available(NULL, SxAIA)) + rc = set_handle_irq(&riscv_intc_aia_irq); + else + rc = set_handle_irq(&riscv_intc_irq); if (rc) { pr_err("failed to set irq handler\n"); return rc; @@ -132,7 +149,8 @@ static int __init riscv_intc_init_common(struct fwnode_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) ? " using AIA" : ""); return 0; }