Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp369969rdb; Thu, 19 Oct 2023 07:01:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeN83Md9GPbixLxmebodTWiud4ebTUlglIEyynxXJ8VhKmeAWHdf6LV6lruCn2jFhCGPSS X-Received: by 2002:aa7:88c6:0:b0:6bd:a8a3:cc59 with SMTP id k6-20020aa788c6000000b006bda8a3cc59mr2365033pff.24.1697724063269; Thu, 19 Oct 2023 07:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697724063; cv=none; d=google.com; s=arc-20160816; b=dOxvCcTg6DeA9/ewcP0ecC32GqnrWLFt8wwqu3B3k2bM/646I548wbVYT9HuFPTBlo RdscZCOfbvI4Q5jPCveWbPXR5lHkolnJ5JQGnA7guyy9ugyqooWgJ+7lOh0FC2NizMMV jLUTZPFo3BjPtzsixGKNYVlR1FqD7LxMvauEprYz/ZxlpexgI4ZU9xNUXVmqgBK1j46y 3R9lyeyjSA70nygs7GJpvNf9Vl/mgX40z6z4OlyVp/yWSkCecTsSbPbLWvpwldwiS2z+ GFUqOzd74KlPNR0u46Xw2cXWPGvtgU9h/iWHPoaGpBBBFiHyC+e83DZXGUWHWRrfX3ES 1Bug== 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 :message-id:date:subject:cc:to:from; bh=6vUtITsfMdYlZziJF7wGim5KAitW3P+8AmGtvufC1aI=; fh=78jUVGZFPZxycKurpkxwBMNH0WY7Z2iotcVzD3qlDxQ=; b=VkjezZqLMlM5zFW0ARry3Phhg2N1yDJq4Zje+9xtyVh7JbjZj3uSe307i+nRZo0uEw EvPPMCKtNfx8WtFYggwVnVwGMuC9GxfM+aAX/u/kDnTHzVrO47nEttq31iCYjVNygauz vKLUSzZULoCmlFp3eeqGO5l8jz5u/idKS8zVqWRgQ1lXxbrftiO31TCJ2dPW41To4e2O Fbgcuzazs2cvOjVARV/oXA/tMwz1Lc4a9h8I5/Ykol95Q2Yq545FAipAdCKKvGBsi6Pl Umu8RDzksoB0HVSSPthfwghszErrWFkD4TBhFhUtTpqCRYpU70mFAx7GM3ex4bGHw1s/ 4CPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=andestech.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id z19-20020a63e113000000b0056a1a149034si4814453pgh.650.2023.10.19.07.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:01:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=andestech.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 136CE81AA518; Thu, 19 Oct 2023 07:01:00 -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 S1345858AbjJSOAw (ORCPT + 99 others); Thu, 19 Oct 2023 10:00:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345821AbjJSOAt (ORCPT ); Thu, 19 Oct 2023 10:00:49 -0400 Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30F74B0 for ; Thu, 19 Oct 2023 07:00:46 -0700 (PDT) Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JE0RGM027779; Thu, 19 Oct 2023 22:00:27 +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, 19 Oct 2023 22:00:23 +0800 From: Yu Chien Peter Lin To: , , , , , , , , CC: , , , Subject: [PATCH v2 03/10] irqchip/riscv-intc: Introduce Andes IRQ chip Date: Thu, 19 Oct 2023 21:57:23 +0800 Message-ID: <20231019135723.3657156-1-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JE0RGM027779 X-Spam-Status: No, score=-0.8 required=5.0 tests=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]); Thu, 19 Oct 2023 07:01:00 -0700 (PDT) This commit adds support for the Andes IRQ chip, which provides IRQ mask/unmask functions to access the custom CSR (SLIE) where the non-standard S-mode local interrupt enable bits are located. The Andes INTC requires the "andestech,cpu-intc" compatible string to be present in interrupt-controller of each cpu node. e.g., cpu0: cpu@0 { compatible = "andestech,ax45mp", "riscv"; ... cpu0-intc: interrupt-controller { #interrupt-cells = <0x01>; compatible = "andestech,cpu-intc"; interrupt-controller; }; }; Signed-off-by: Yu Chien Peter Lin Reviewed-by: Charles Ci-Jyun Wu Reviewed-by: Leo Yu-Chi Liang --- Changes v1 -> v2: - New patch --- drivers/irqchip/irq-riscv-intc.c | 49 ++++++++++++++++++++++++-- include/linux/irqchip/irq-riscv-intc.h | 12 +++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 include/linux/irqchip/irq-riscv-intc.h diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index 79d049105384..fcd06b58bdac 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,26 @@ static void riscv_intc_irq_unmask(struct irq_data *d) csr_set(CSR_IE, BIT(d->hwirq)); } +static void andes_intc_irq_mask(struct irq_data *d) +{ + unsigned int mask = BIT(d->hwirq % BITS_PER_LONG); + + if (d->hwirq < ANDES_SLI_CAUSE_BASE) + csr_clear(CSR_IE, mask); + else + csr_clear(ANDES_CSR_SLIE, mask); +} + +static void andes_intc_irq_unmask(struct irq_data *d) +{ + unsigned int mask = BIT(d->hwirq % BITS_PER_LONG); + + if (d->hwirq < ANDES_SLI_CAUSE_BASE) + csr_set(CSR_IE, mask); + else + csr_set(ANDES_CSR_SLIE, mask); +} + static void riscv_intc_irq_eoi(struct irq_data *d) { /* @@ -68,12 +89,35 @@ static struct irq_chip riscv_intc_chip = { .irq_eoi = riscv_intc_irq_eoi, }; +static struct irq_chip andes_intc_chip = { + .name = "RISC-V INTC", + .irq_mask = andes_intc_irq_mask, + .irq_unmask = andes_intc_irq_unmask, + .irq_eoi = riscv_intc_irq_eoi, +}; + static int riscv_intc_domain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hwirq) { + struct fwnode_handle *fn = riscv_get_intc_hwnode(); + struct irq_chip *chip; + const char *cp; + int rc; + irq_set_percpu_devid(irq); - irq_domain_set_info(d, irq, hwirq, &riscv_intc_chip, d->host_data, - handle_percpu_devid_irq, NULL, NULL); + + rc = fwnode_property_read_string(fn, "compatible", &cp); + if (rc) + return rc; + + if (strcmp(cp, "riscv,cpu-intc") == 0) + chip = &riscv_intc_chip; + else if (strcmp(cp, "andestech,cpu-intc") == 0) + chip = &andes_intc_chip; + + irq_domain_set_info(d, irq, hwirq, chip, + d->host_data, handle_percpu_devid_irq, NULL, + NULL); return 0; } @@ -166,6 +210,7 @@ static int __init riscv_intc_init(struct device_node *node, } IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init); +IRQCHIP_DECLARE(andes, "andestech,cpu-intc", riscv_intc_init); #ifdef CONFIG_ACPI diff --git a/include/linux/irqchip/irq-riscv-intc.h b/include/linux/irqchip/irq-riscv-intc.h new file mode 100644 index 000000000000..87c105b5b545 --- /dev/null +++ b/include/linux/irqchip/irq-riscv-intc.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 Andes Technology Corporation + */ +#ifndef __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H +#define __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H + +#define ANDES_SLI_CAUSE_BASE 256 +#define ANDES_CSR_SLIE 0x9c4 +#define ANDES_CSR_SLIP 0x9c5 + +#endif /* __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H */ -- 2.34.1