Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp206729rdb; Thu, 22 Feb 2024 00:42:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUn3aWacv1Vl+pI/c401Kw/cvevw75nL61DVMhlRgmbsJUnm1XkYjqGcO/9rPXEdysGoRMGP4CLVtuNoP9nrdYbcCFC3JS8JljUjt5DHQ== X-Google-Smtp-Source: AGHT+IHFDtDfJBNo265hUl/2Kb6uzh6iLPhqtXcYp6f+tXC/V9iP9Uti9W0SVgMrcpoJhi/pLtuR X-Received: by 2002:a05:6808:f90:b0:3c1:7836:b39f with SMTP id o16-20020a0568080f9000b003c17836b39fmr1424143oiw.4.1708591340203; Thu, 22 Feb 2024 00:42:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708591340; cv=pass; d=google.com; s=arc-20160816; b=YyueVsVQXfSq2apR2LrKY3MiurC8cbfj91bKbrweuAplWx9SGBXgR//c2ZTM7uJ27M dlVtEL7rVl6PabhYXX0JHPz6DpTOOWUuBlo6t3mJThQrlvSeeUF+0elAts815jXNPgLo Df11shHiHprpXvVvg2K9xx7PBKedVbJT3pz2Mtvx/Us0cMNbQSCOVY0m0AGeVcYmgwXJ 7yMehiDEdfyxu6SZa6K19OuC35opazBvF2tvqTgZPJ9jOT8CcHOeKv1K6/92/3IGObM1 2/nLV18DMjrjDhxM1KB8PnyR54FVHcqcIJ70LAK9V4VW7dmtv+KQUgGKTAn1OVSIIi23 RCQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=KFYbXsE49nRRM+9gOYFkE7LFanNKSaZ0B2z8y9yrOfI=; fh=yFSYYOrV+AMBwG+L8g12vhazshGgS4Olt8r1o7sg/Ho=; b=GM4z01sJZ6S2dklomG20jjdCy5yGEWQ1cfsMecHeqZgJmdLfgbdPvLL/4rI6rB4ZlA yM9kVqy20Ppw7X5Y68u7tmwT7p9oaHYLZCl3RMSQUScc9YweYF1TQb1m4H7cwYVDjLXG btwDt/bdivxPgog8MA/yMXA682pKZI3J4h/Imu/9q2Z4DlD3dFaHTETMNF+zr649e3cZ dhM3vteAJ5e5jZz5uQ6WBCQJDYm1wRwweVgzkzHrg1JiCVWU3GR0AdmBMg3iXujne8HL fdEXzKrgqtOheNkC4eHUruFJFJNtnx9BskK6bQgD0ArkVUkm+afN9yCzRa2baTPUYxWY X5mw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=andestech.com dmarc=pass fromdomain=andestech.com); spf=pass (google.com: domain of linux-kernel+bounces-76126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=andestech.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h22-20020aa786d6000000b006e2861bc3f5si9159991pfo.38.2024.02.22.00.42.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:42:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=andestech.com dmarc=pass fromdomain=andestech.com); spf=pass (google.com: domain of linux-kernel+bounces-76126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=andestech.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D2CFB284357 for ; Thu, 22 Feb 2024 08:42:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0546374C1; Thu, 22 Feb 2024 08:41:43 +0000 (UTC) Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 995FA23747; Thu, 22 Feb 2024 08:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.248.80.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708591303; cv=none; b=TZDfhl14TaKj1z7qb/S7dgYkSWZoIaeJitC5ZEukkEn48VZMZ7ZUWLIgk3MqFfO+PMDa0Drlvi4cr/Kxm1L3kXefje6vXPPXJ41Gr3v9moTQ+8e9WWITQQy34/4qYfKOri+vOadrZzaICrCSuWod9WdEffFD1SlIV8yLDcPt4PM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708591303; c=relaxed/simple; bh=sMXqZxiP9g8gdSynKiNBOM8kHpMxXvlXIdpGmQRqTkw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TkIfHxboWy7YdjLcmUiu6mPZoI+Ao74ySLxLPDloF+kJGiNDNH2TNwy1LLfj7KBP3DhlCtFA8636ilu+LdqEjyMPWT7BTiHzMfE7bmxIj2bOhbmrNXiDrNIAOhNDQtBPy9V/AoPwfxdmi8H1rt+PHpDA1yA4hxp3EdVo3evun7Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=andestech.com; spf=pass smtp.mailfrom=andestech.com; arc=none smtp.client-ip=60.248.80.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=andestech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=andestech.com Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 41M8e38C074466; Thu, 22 Feb 2024 16:40:03 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 22 Feb 2024 16:39:59 +0800 From: Yu Chien Peter Lin To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Randolph , Atish Patra Subject: [PATCH v9 02/10] irqchip/riscv-intc: Allow large non-standard interrupt number Date: Thu, 22 Feb 2024 16:39:38 +0800 Message-ID: <20240222083946.3977135-3-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222083946.3977135-1-peterlin@andestech.com> References: <20240222083946.3977135-1-peterlin@andestech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL:Atcsqr.andestech.com 41M8e38C074466 Currently, the implementation of the RISC-V INTC driver uses the interrupt cause as the hardware interrupt number, with a maximum of 64 interrupts. However, the platform can expand the interrupt number further for custom local interrupts. To fully utilize the available local interrupt sources, switch to using irq_domain_create_tree() that creates the radix tree map, add global variables (riscv_intc_nr_irqs, riscv_intc_custom_base and riscv_intc_custom_nr_irqs) to determine the valid range of local interrupt number (hwirq). Signed-off-by: Yu Chien Peter Lin Reviewed-by: Randolph Reviewed-by: Anup Patel Reviewed-by: Atish Patra --- Changes v1 -> v2: - Fixed irq mapping failure checking (suggested by Clément and Anup) Changes v2 -> v3: - No change Changes v3 -> v4: (Suggested by Thomas [1]) - Use pr_warn_ratelimited instead - Fix coding style and commit message Changes v4 -> v5: (Suggested by Thomas) - Fix commit message Changes v5 -> v6: (Suggested by Anup [2]) - Add riscv_intc_* global variables for checking the range of valid interrupt number in riscv_intc_domain_alloc() - Advertise the number of interrupts allowed Changes v6 -> v7: - No functional change Changes v7 -> v8: - Include Reviewed-by tags from Anup and Atish Changes v8 -> v9 (Suggested by Thomas [3]): - Fix coding style - Update hwirq range checks - Update riscv_intc_* global variables initialization [1] https://patchwork.kernel.org/project/linux-riscv/patch/20231023004100.2663486-3-peterlin@andestech.com/#25573085 [2] https://patchwork.kernel.org/project/linux-riscv/patch/20231213070301.1684751-3-peterlin@andestech.com/#25636589 [3] https://patchwork.kernel.org/project/linux-riscv/patch/20240129092553.2058043-3-peterlin@andestech.com/#25710584 --- drivers/irqchip/irq-riscv-intc.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index e8d01b14ccdd..684875c39728 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -19,15 +19,16 @@ #include static struct irq_domain *intc_domain; +static unsigned int riscv_intc_nr_irqs __ro_after_init = BITS_PER_LONG; +static unsigned int riscv_intc_custom_base __ro_after_init = BITS_PER_LONG; +static unsigned int riscv_intc_custom_nr_irqs __ro_after_init; static asmlinkage void riscv_intc_irq(struct pt_regs *regs) { unsigned long cause = regs->cause & ~CAUSE_IRQ_FLAG; - if (unlikely(cause >= BITS_PER_LONG)) - panic("unexpected interrupt cause"); - - generic_handle_domain_irq(intc_domain, cause); + if (generic_handle_domain_irq(intc_domain, cause)) + pr_warn_ratelimited("Failed to handle interrupt (cause: %ld)\n", cause); } /* @@ -93,6 +94,14 @@ static int riscv_intc_domain_alloc(struct irq_domain *domain, if (ret) return ret; + /* + * Only allow hwirq for which we have corresponding standard or + * custom interrupt enable register. + */ + if ((hwirq >= riscv_intc_nr_irqs && hwirq < riscv_intc_custom_base) || + (hwirq >= riscv_intc_custom_base + riscv_intc_custom_nr_irqs)) + return -EINVAL; + for (i = 0; i < nr_irqs; i++) { ret = riscv_intc_domain_map(domain, virq + i, hwirq + i); if (ret) @@ -117,8 +126,7 @@ static int __init riscv_intc_init_common(struct fwnode_handle *fn) { int rc; - intc_domain = irq_domain_create_linear(fn, BITS_PER_LONG, - &riscv_intc_domain_ops, NULL); + intc_domain = irq_domain_create_tree(fn, &riscv_intc_domain_ops, NULL); if (!intc_domain) { pr_err("unable to add IRQ domain\n"); return -ENXIO; @@ -132,7 +140,11 @@ 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\n", riscv_intc_nr_irqs); + if (riscv_intc_custom_nr_irqs) { + pr_info("%d custom local interrupts mapped\n", + riscv_intc_custom_nr_irqs); + } return 0; } -- 2.34.1