From patchwork Tue Oct 3 04:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 147619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1853661vqb; Mon, 2 Oct 2023 21:45:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9jx11WrG1zuRstB9ZbgVqmxPs2UW7u/2YmeyjMynygcV/aILszY63YAvCSteeyzi84MWW X-Received: by 2002:a05:6a20:9719:b0:15e:4084:6480 with SMTP id hr25-20020a056a20971900b0015e40846480mr2061799pzc.27.1696308354310; Mon, 02 Oct 2023 21:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696308354; cv=none; d=google.com; s=arc-20160816; b=R/RqAjqzUAsME2lbz7isTqHLu9EK1NiS9dBl+bmwaY/x10rhmgFAIft+pknTEmfStW 2Bvb305V3mIDyvb7sGqLvG/qEbvlgDS98qDCYgSxsoVHWNB/PxI/C0e3j+n4W/D5kK9A it6jkuYzYtLjn53nrE+aa+qqSJdP8b5nMh4Hl6Cu55MP9Uju4e+xuJ8U6qBVqom11Ls5 AzejL3vcQWQsXFUXUCoQ821NRVLDzQTrh4T5d1POwE5JyLeYHJXphHpJiHFo9dpGMde7 1rZB+krYNWy+7Tz9027xNqRAeyMh6KONkdU+vMdR3Oxo49tNihyjq8YnlBrXsnZS9Btp eh2A== 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=HiR77aXxZpk3zxogTLIvmoQu4hiYlv516VX77DzXr2myfVedLuAGTmQ9hSQMMbYeWz feiH81TwdBijtyu4JwCWz+h6RoAW6iizeaKYkjAO1MxKljJUZ6JZ/BbJW5QjpgxsYUl0 mN2con3y69XGUjSrCBz/1nvTIaic5GxtECh7n69PNVuxtFfqqQaIoPECdJOE3AwQVNEk Wo4QROm/x0lKuTkQgVZhEHkjCGvMeTRs0LBURotBpvpvVQfIC0GgMMS3/LmbfGAfc6Ze gDRJoOCLjehPrufvC0+WfdBCmGTYroZ8jQA7iA4s2GDGG4ZOLBCp+mDKGXWvC91VnpXG JozQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="k+aamnU/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q11-20020a056a00088b00b0069339f19f7dsi666659pfj.199.2023.10.02.21.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 21:45:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="k+aamnU/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id D06BF80E9E99; Mon, 2 Oct 2023 21:45:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239127AbjJCEpR (ORCPT + 18 others); Tue, 3 Oct 2023 00:45:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239121AbjJCEpN (ORCPT ); Tue, 3 Oct 2023 00:45:13 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C559FE for ; Mon, 2 Oct 2023 21:45:04 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-690d2441b95so339522b3a.1 for ; Mon, 02 Oct 2023 21:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1696308303; x=1696913103; 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=k+aamnU/xegf8QrsvQn3Zw1j4q9ezVrwK1rVrMFr7XkcotzI/pPuXKnYpK1EqDGU2h RvxDMo/Ep+4NfuvVSiQR6nlvHH59F1zaA52tTIjmJPK7BisPHXE+L9B/zImzwXHMIlb2 KTxxOPg4nXnIA2AEpcJIvVk4yHZLi8f5MgBola0dDllGo72ktzHcbxs63d2Spiuk/qCU ygDiJBEyj9erreX9XaP2YyV8nTDn41bsLuwrh99pRhjyGroPQc5UPwOMkk6sXWpUcKUp GuntxnKYnQrndQAExRzyBGPlMhCzoiCpGRs8/cYUKLNXcM3n4tSnS6aFCCUZJbd23szf p9OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696308303; x=1696913103; 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=NC8cGf8DxEHkBHRkakN/6MQgseZ0PGwCoUEBv4PGUow1KXxYztHz1lFVEUokCLkd28 J9xioA/Ql9OHFG6Mr0OOnBPYsqRxLd2CnRe85Rda+ERzzQEscj4HkRJXfMpiFovdUwjz SpR5q5/rPyq1rRFHEPOz9rfqWE7wMWrc+29YIBSqHNeUuFDrYzWqCRdPfoj8DIsC9D2G K9xWfkQ6p10a8PhfS3HsWJeYviVMP6MJypHQlaydosD27oqRzmayTmeo8w+AMn793kwF 9HnP3no4VzDN7hcMgKuoBKc2JYsvu2KcV7+aNi8K6Jm6UiJ5HGOnLk9QgsSbK/KNf5Qs yo4g== X-Gm-Message-State: AOJu0YxqKzKBq00WCkAT1cPgTvHXuH0Xn/wtOL/wrK2KVyoJqvbzNF4z OLJIY4QC+FIzkQrddXjhZPdcew== X-Received: by 2002:a05:6a00:b55:b0:68f:cb69:8e66 with SMTP id p21-20020a056a000b5500b0068fcb698e66mr2518288pfo.15.1696308303308; Mon, 02 Oct 2023 21:45:03 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([171.76.84.132]) by smtp.gmail.com with ESMTPSA id h9-20020aa786c9000000b0068e49cb1692sm346421pfo.1.2023.10.02.21.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 21:45:02 -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 v10 06/15] irqchip/riscv-intc: Add support for RISC-V AIA Date: Tue, 3 Oct 2023 10:13:54 +0530 Message-Id: <20231003044403.1974628-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003044403.1974628-1-apatel@ventanamicro.com> References: <20231003044403.1974628-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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 02 Oct 2023 21:45:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778708228998054068 X-GMAIL-MSGID: 1778708228998054068 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; }