From patchwork Tue Feb 20 06:07:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13563418 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 01501C48BC3 for ; Tue, 20 Feb 2024 06:08:29 +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=a5l/MDpzUiI2wiTTaPw5aoSg++N8GmToPqExqEnYvs4=; b=WPg3DMdVkC8VJC ziCllqifiyCLxVmklc/7kN2oqt2jD0xcrD0kRfxb+qyfPYDXFzeUBwX47MoqnFJTgJZW77dmq9Y81 G4t+X3Pg738rgDz1zaDEbFYXJBXqMJEglBg/LnOd6crI0gn8f7LW2SuzUh1PmsVqTm9qW+A3greb0 POi6esx3eArgpNTb1Wd61e27snD4WyAHSORtDzuz70eT+eXYSwJNkzHEefiYpgzvGPwCJBhJV8qoP gSwAs+RpWoOXBU4lRaIImUJmFNkb3+mXZxwRMcq1GBOXOIkj7C6zw8DwPQ0f8w/lmULKH+8icEysf b1jDQxlVXpKRxVpUQHcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcJIe-0000000DHoH-2id0; Tue, 20 Feb 2024 06:08:16 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcJIT-0000000DHfI-3NYC for linux-arm-kernel@lists.infradead.org; Tue, 20 Feb 2024 06:08:07 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc139ed11fso3090595ad.0 for ; Mon, 19 Feb 2024 22:08:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708409284; x=1709014084; 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=2RNpF/CWjVyq2jAidq9g4JrMuQdRaRtl2xGmvH6ydPA=; b=ilA5poR5AiFnPzbQNReXjasgEUALkzBEDY0Ep/GcOF621YSVB4r9I+oktN6iPa8k7K Yxj0Ib04BjPGaMOF03eKoTCc7QVXh80O92G5TIcdKulfUS0nmCN4zPvcwb5vv5NlPWMc NmNuffcSiLpGTWW9eLey82la3zfYQ0vu7HM8s4VWkXk3pfScrqSJW39ooBfMdgBu1Ea1 NQr62IfyNbaw6VBjDzs0nWNfgdtmNDWABceb/gceEtidAq6y3Bav4NnI21XHb+OTrHC7 2gWb15kMjx9jr/c02b9M1pwnhJTy1Hzq61MtMZTRQLKxQVBOa9JSZjjD12P/tZHyTAba AZxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708409284; x=1709014084; 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=2RNpF/CWjVyq2jAidq9g4JrMuQdRaRtl2xGmvH6ydPA=; b=SgxnZyclO+SxH1kCZFyPvikGWuRY6m8ZfdXvcLJF6sg4nRUIbQp8r3T+tcUOAM7ffA bC4G/Bnvlln2CNvih4wU6+oUIetcTL/gU7z9fwAHrIbQkVc2N2Em2fC14s34mkkkuCSX xMOE83ZwJ1HOd5GDJmvaVBVJwqEcA1WatKVwZj+Fo63ZB8K24iwglhiHIGQE8aM+wlpz oi3kGSqlL7ulBEHuR6zVrQC8EKsHqR2Msw/4O4ozbMQ0Bn4Y3dcMi+g77o2LnJsThmQE 8fUpCZgtUbhgU0WyrxCz8EpJHtBXdkkPYTFYyXH1VJy9HW6vRsWfntpHk7jpKHVCxyz5 z5Sg== X-Forwarded-Encrypted: i=1; AJvYcCWfTCGvw87k4tFEH9ZHiQiwmiqZLw8IkYF0NvcinE3RcsMPE5VMi/tVbytm4+pA/v/sfaKU7WRGK17xaeUWEJJUbp+ur1qiAtA5Wse+ggTLhwL0Gro= X-Gm-Message-State: AOJu0YzsmnqbTx6RSCfDc9/GFIX7yNCWT9akYbau3vsut+UJRTEAisOv vs97J7xGO3ahAoIwpDJ8tQOJ4UnA9qwHVFcaiFwYrtDgKVYGZjYawuo/z6psfnk= X-Google-Smtp-Source: AGHT+IHE347dDU9aO1yM5GxfMUmUFQla/Fhk4fIeEilyp6hgetGifJxkk866esqcxA3POxZZ3TvgEQ== X-Received: by 2002:a17:902:e545:b0:1db:ecf1:3b83 with SMTP id n5-20020a170902e54500b001dbecf13b83mr7080645plf.23.1708409284467; Mon, 19 Feb 2024 22:08:04 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.80.86]) by smtp.gmail.com with ESMTPSA id j6-20020a17090276c600b001db4c89aea5sm5368114plt.158.2024.02.19.22.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:08:04 -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 v13 03/13] irqchip/riscv-intc: Add support for RISC-V AIA Date: Tue, 20 Feb 2024 11:37:08 +0530 Message-Id: <20240220060718.823229-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220060718.823229-1-apatel@ventanamicro.com> References: <20240220060718.823229-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240219_220805_914181_942C61D4 X-CRM114-Status: GOOD ( 16.03 ) 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 We 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 | 34 ++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index e8d01b14ccdd..bab536bbaf2c 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 = 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 +49,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 +131,20 @@ 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, + 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 +152,9 @@ 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; }