From patchwork Thu Sep 28 06:11:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 146063 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3258292vqu; Thu, 28 Sep 2023 05:05:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuWVc822oWjNzK7o0kGq4GCUMZ5YVi0FR2E7bY3bV5pxQk1gmyvg+sgAk306rnCXokpGpM X-Received: by 2002:a17:90b:1254:b0:268:2500:b17e with SMTP id gx20-20020a17090b125400b002682500b17emr903154pjb.23.1695902716665; Thu, 28 Sep 2023 05:05:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695902716; cv=none; d=google.com; s=arc-20160816; b=Z4CK22VGwXqZmhABLazo2JtR9bAL1DUpiuOO5OGtq5ZDxeWj5l3Ldm0KchtltVfDAJ x1L+agOhbC9VJLVXDnIOvn18dU5ozZ8nDvRp7W84xoX1ex8YYVWV3wzbYzlq2YjC2pHj JHaDnIi7nxuVo/xMvU9tcciQjowXWgbmIFio9uf+oboJJXuKtTZ5sqjUSxZd3jrbkl39 qrqAvKJzlaYkBf1+3YR5bHhHUGacShL/nQv4aNCdFAr6Ef7tg2g34uOTIcW+eRkZrqE9 UK2sIB9LwrZZDgCOT8rtP/IB14CGdGVrZzvv38K+s1tkyJL2QFT0aD9OYq0Dx2b9MT+o 6ifA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2RNpF/CWjVyq2jAidq9g4JrMuQdRaRtl2xGmvH6ydPA=; fh=ZYtQOaPQ3bv/nEoeNBBJi+8gjEgXnsUn5nizHK4ZU74=; b=p1l3Nw6lOPQvAobhAydQwx9IGdUfEEhnlqO6UFnBjxE/6Pjh7b8K3S6CZoXQARkMGO XflQS2UEfPaMKVoGqghb4L+m+1vIolQPn3PYrPq3rDL49osWC4TcAAsrwQzReNQUJ3iP 7zVo+ckhgkhE/+ZRO0jHqe5WIyTPawZqa7IjsniajvYbT2ivJrqVSTuoT8psJaJlj0zq hD20HOExgGFoZPBWnXgntw1eZWEgu8G7pDf45SQhMlhgwBSqd8Q70YxuFWgLf8fvSzMP di9MfTnh4ByUQx+NqpKCc7qkYwBFy2yXGZsX4M4hb9Fs56o+7jlQMb5THbFfSIBFAPLB fb/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=JJJIj228; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id mm14-20020a17090b358e00b0027760c30acfsi10128283pjb.4.2023.09.28.05.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:05:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=JJJIj228; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C5CF88100219; Wed, 27 Sep 2023 23:13:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230310AbjI1GNW (ORCPT + 20 others); Thu, 28 Sep 2023 02:13:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbjI1GNO (ORCPT ); Thu, 28 Sep 2023 02:13:14 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D51CC8 for ; Wed, 27 Sep 2023 23:13:09 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-34fcd361e91so40292505ab.3 for ; Wed, 27 Sep 2023 23:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695881588; x=1696486388; darn=vger.kernel.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=JJJIj228h3I63YzUl5CpR1kZCAw2t5ZVK9s5fEZqautPwLVZQsnhe9bWsIP9xFx8u9 yRRAsM3d458XQBfEL12NVQkwvrlB+pYF/GqzdGl36bidlDtLKEZCrJ8d+Gm7J9uoTXPf 1Ew+YsQ/z/oi1V1rbPm1HmSgch/cmt9tXGUA+To8qCC9vygPPQBojp+cKtABnvjoMpLI J4GrPNWI7W8TYDAdaFXuYgijPBTS0b1gWyzAleVQlcj5Y7k+SSjzMDoqPziLDnc77Zy0 UVFxxu6I5yqSRqskyeEd0QadWtWn1vTUhezBV3gZBc8i6FFp5YYOiJ84gRmKEd9pR02p j94Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695881588; x=1696486388; 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=m6hw8H+CjeTUcWVXer/hfoE3mgnEdnQY3ugNkFH37zOyT5AUw+o3D9MwqxdKJHgib7 PD1De55N1dXJrFEuvk2RfCdVpARxqQsgcaELWBgW2hcUmSnFlKbW7cFXFQVBw/qm4c+U 8cu3ijvS/Nz197kHNs2zceJyVu4MPl5VKj2Ha8diKKQMCTnmzdAUhgaCNPYpoRuaP42w Jvgjyw5Wakvgq19/94VPIxLovUDivLUWRWwOLaPqh/AaUW7VTjtWQTu5KnIh+C+ic8OW KlP/wfas2xVDdUwzSz9cISnag84dBAFgLncaOxisUvLk+yrw8l0yTiAVhkR6FrM+9qKO 8Vnw== X-Gm-Message-State: AOJu0YwY51klfCFkKZh451l488IiyNwd7EVDvd3kyEeCIGrxZu1szJgf I2pXPz8GrGIpbztBybaXkNOZkA== X-Received: by 2002:a05:6e02:ca5:b0:350:f510:3990 with SMTP id 5-20020a056e020ca500b00350f5103990mr229352ilg.2.1695881588242; Wed, 27 Sep 2023 23:13:08 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id x6-20020a92d306000000b003506f457d70sm4774467ila.63.2023.09.27.23.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 23:13:07 -0700 (PDT) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley Cc: Atish Patra , Andrew Jones , Sunil V L , Saravana Kannan , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Anup Patel Subject: [PATCH v9 06/15] irqchip/riscv-intc: Add support for RISC-V AIA Date: Thu, 28 Sep 2023 11:41:58 +0530 Message-Id: <20230928061207.1841513-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928061207.1841513-1-apatel@ventanamicro.com> References: <20230928061207.1841513-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 23:13:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778282887066866613 X-GMAIL-MSGID: 1778282887066866613 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; }