Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp894460rdb; Fri, 25 Aug 2023 04:46:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHon1VoryKLeZdCR2ZG/DMLqq80RQFwmArvow8/TuHK27pUG93ctW868S+HkNufCPzSTs6o X-Received: by 2002:a17:90a:1d08:b0:26d:2fab:1e51 with SMTP id c8-20020a17090a1d0800b0026d2fab1e51mr14833193pjd.21.1692963967749; Fri, 25 Aug 2023 04:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692963967; cv=none; d=google.com; s=arc-20160816; b=UH3QokTF1CPZQI0aA/zIA3xUgQv4/xeEB9HHVbaDId3b/ELI2ihK+uk0qKOIj9AJUF tXXE/rwL0C4+kf6BO3wsAu9M159zRJQ09fQK9umxRZ1kCq7TQUWg3LP/xEt9zwVAZcFF yIjT/pP9haX4x/4rT94RHGoph2XRvePtExPGKzqzW0ZSorwm395ClCW13MEokZBw1qyC ysE+z3sdmlYISlbgq+tqxDawwNJJnHQCj0ra1WCooqndLkfpj+muZZOkLVrhgiCjo/aJ zCegCBCaJet09VQ+WUhxp0EDymInOQ9saoub+cvqDRpyTNyHx9OwtkHlxrZrfTxXR/+8 weLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=qnEap3pMzpYwacZORn0ZhBjmE4JHGeXcGPoTOdhXnV8=; fh=y8d0C5dLtGb8zs8KQUIJy2R9+5DBPV29N8a8eZxYvuU=; b=cYWtZiylgB4b76v9iX6I/p0T1113e+Q3tgkVMRlMR49F65AONy+3EC3JLB1o1KPMWU EXyadDjBaj+bHwVN/gXxnY6+g/5koFZTj0n17mAXVibyeD+IIrm5PWiPokZ/134dLx9H TxxjjMWGxjwMY3vi7xzvWfHg0b2uWm9Kr14uh6DPJYFGGev55FG/m6gkFXf2wxdsPxpK rMZ4p8drJivX6HqvxG3Tay0wHFNzSz6zVIDk8ssh9yt/Ma63iJmD0HrO3QSMPcHv57iq oSZZu+hH0+Y5PlGP4Zj7b/I2emFLoCHZcZ6npxryqCN9fxdnnLUK91nN6GScn7O4+lDk r7fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oc11-20020a17090b1c0b00b0026839b09526si1804064pjb.96.2023.08.25.04.45.53; Fri, 25 Aug 2023 04:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244092AbjHYJCZ (ORCPT + 99 others); Fri, 25 Aug 2023 05:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242047AbjHYJBm (ORCPT ); Fri, 25 Aug 2023 05:01:42 -0400 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EADA1BFA; Fri, 25 Aug 2023 02:01:40 -0700 (PDT) Received: from EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id C433B81FB; Fri, 25 Aug 2023 17:01:38 +0800 (CST) Received: from EXMBX171.cuchost.com (172.16.6.91) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 25 Aug 2023 17:01:38 +0800 Received: from ubuntu.localdomain (113.72.145.205) by EXMBX171.cuchost.com (172.16.6.91) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 25 Aug 2023 17:01:37 +0800 From: Minda Chen To: Daire McNamara , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Bjorn Helgaas , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Emil Renner Berthing CC: , , , , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Paul Walmsley , Palmer Dabbelt , Albert Ou , Philipp Zabel , Mason Huo , Leyfoon Tan , Kevin Xie , Minda Chen Subject: [PATCH v4 06/11] PCI: plda: Add event interrupt codes and IRQ domain ops Date: Fri, 25 Aug 2023 17:01:24 +0800 Message-ID: <20230825090129.65721-7-minda.chen@starfivetech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825090129.65721-1-minda.chen@starfivetech.com> References: <20230825090129.65721-1-minda.chen@starfivetech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [113.72.145.205] X-ClientProxiedBy: EXCAS062.cuchost.com (172.16.6.22) To EXMBX171.cuchost.com (172.16.6.91) X-YovoleRuleAgent: yovoleflag X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For PolarFire implements non-PLDA local interrupt events, most of event interrupt process codes can not be re-used. PLDA implements new codes and IRQ domain ops like PolarFire. plda_handle_event() adds a new IRQ num to event num mapping codes for PLDA local event except DMA engine interrupt events. The DMA engine interrupt events are implemented by vendors. Signed-off-by: Minda Chen --- drivers/pci/controller/plda/pcie-plda-host.c | 99 ++++++++++++++++++++ drivers/pci/controller/plda/pcie-plda.h | 4 + 2 files changed, 103 insertions(+) diff --git a/drivers/pci/controller/plda/pcie-plda-host.c b/drivers/pci/controller/plda/pcie-plda-host.c index ce02cfe6b5fa..bf63f220a518 100644 --- a/drivers/pci/controller/plda/pcie-plda-host.c +++ b/drivers/pci/controller/plda/pcie-plda-host.c @@ -250,6 +250,105 @@ int plda_pcie_intx_map(struct irq_domain *domain, unsigned int irq, return 0; } +irqreturn_t plda_event_handler(int irq, void *dev_id) +{ + return IRQ_HANDLED; +} + +void plda_handle_event(struct irq_desc *desc) +{ + struct plda_pcie_rp *port = irq_desc_get_handler_data(desc); + struct irq_chip *chip = irq_desc_get_chip(desc); + unsigned long events = 0; + u32 bit, val, origin; + + chained_irq_enter(chip, desc); + + val = readl_relaxed(port->bridge_addr + ISTATUS_LOCAL); + origin = val; + val = val >> A_ATR_EVT_POST_ERR_SHIFT; + events |= val & 0xff; + if (origin & PM_MSI_INT_INTX_MASK) + events |= BIT(EVENT_PM_MSI_INT_INTX); + val = (origin >> PM_MSI_INT_MSI_SHIFT) & 0xf; + events |= val << EVENT_PM_MSI_INT_MSI; + + for_each_set_bit(bit, &events, port->num_events) + generic_handle_domain_irq(port->event_domain, bit); + + chained_irq_exit(chip, desc); +} + +static u32 plda_hwirq_to_mask(int hwirq) +{ + u32 mask; + + if (hwirq < EVENT_PM_MSI_INT_INTX) + mask = BIT(hwirq + A_ATR_EVT_POST_ERR_SHIFT); + else if (hwirq == EVENT_PM_MSI_INT_INTX) + mask = PM_MSI_INT_INTX_MASK; + else + mask = BIT(hwirq + PM_MSI_TO_MASK_OFFSET); + + return mask; +} + +static void plda_ack_event_irq(struct irq_data *data) +{ + struct plda_pcie_rp *port = irq_data_get_irq_chip_data(data); + + writel_relaxed(plda_hwirq_to_mask(data->hwirq), + port->bridge_addr + ISTATUS_LOCAL); +} + +static void plda_mask_event_irq(struct irq_data *data) +{ + struct plda_pcie_rp *port = irq_data_get_irq_chip_data(data); + u32 mask, val; + + mask = plda_hwirq_to_mask(data->hwirq); + + raw_spin_lock(&port->lock); + val = readl_relaxed(port->bridge_addr + IMASK_LOCAL); + val &= ~mask; + writel_relaxed(val, port->bridge_addr + IMASK_LOCAL); + raw_spin_unlock(&port->lock); +} + +static void plda_unmask_event_irq(struct irq_data *data) +{ + struct plda_pcie_rp *port = irq_data_get_irq_chip_data(data); + u32 mask, val; + + mask = plda_hwirq_to_mask(data->hwirq); + + raw_spin_lock(&port->lock); + val = readl_relaxed(port->bridge_addr + IMASK_LOCAL); + val |= mask; + writel_relaxed(val, port->bridge_addr + IMASK_LOCAL); + raw_spin_unlock(&port->lock); +} + +static struct irq_chip plda_event_irq_chip = { + .name = "PLDA PCIe EVENT", + .irq_ack = plda_ack_event_irq, + .irq_mask = plda_mask_event_irq, + .irq_unmask = plda_unmask_event_irq, +}; + +static int plda_pcie_event_map(struct irq_domain *domain, unsigned int irq, + irq_hw_number_t hwirq) +{ + irq_set_chip_and_handler(irq, &plda_event_irq_chip, handle_level_irq); + irq_set_chip_data(irq, domain->host_data); + + return 0; +} + +static const struct irq_domain_ops plda_evt_dom_ops = { + .map = plda_pcie_event_map, +}; + void plda_pcie_setup_window(void __iomem *bridge_base_addr, u32 index, phys_addr_t axi_addr, phys_addr_t pci_addr, size_t size) diff --git a/drivers/pci/controller/plda/pcie-plda.h b/drivers/pci/controller/plda/pcie-plda.h index a5eb02ec6171..315d9874b899 100644 --- a/drivers/pci/controller/plda/pcie-plda.h +++ b/drivers/pci/controller/plda/pcie-plda.h @@ -102,6 +102,8 @@ #define EVENT_PM_MSI_INT_SYS_ERR 12 #define NUM_PLDA_EVENTS 13 +#define PM_MSI_TO_MASK_OFFSET 19 + struct plda_msi { struct mutex lock; /* Protect used bitmap */ struct irq_domain *msi_domain; @@ -118,10 +120,12 @@ struct plda_pcie_rp { raw_spinlock_t lock; struct plda_msi msi; void __iomem *bridge_addr; + int num_events; }; void plda_handle_msi(struct irq_desc *desc); int plda_allocate_msi_domains(struct plda_pcie_rp *port); +irqreturn_t plda_event_handler(int irq, void *dev_id); void plda_handle_intx(struct irq_desc *desc); int plda_pcie_intx_map(struct irq_domain *domain, unsigned int irq, irq_hw_number_t hwirq); -- 2.17.1