From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A504AC3DA4B for ; Mon, 15 Jul 2024 18:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=c7owLXpFna1dFjNdHfNbwtJ+e/sHELDIGCOsgbwDi7k=; b=nT6TKA1mza8SH2o1dvjPB66i++ wyGcfGxrM5LpLy8XSccDuLFTvlRyiPdebdPhoKD8ikjwaoZAEENCJ0FmtIX0p3pc2QChj6RK4rpPv ti1DzeutnnaGp7C5uNywlz/Itr+6h4dPsfiK8EZtS7ZMUDUTSNgA7Qo82QU1rWrVP7/4+Et+DnEuo uuWtfTYCxxbb6utMPzrlAPuqnQ77ei2FbIOL6dKgv5U/lEHqLh7OYuRFmc/jyiXdrwbQtg+c9nUOI /eOvx+LNXrus2qTyDp9p1uZ3J3cjcX54Ki7gTxZxmtOUj7CZ8LmNn3QE0Dp+ps6Oco8qIyxDkoFbK M+w4v45g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTQFS-00000007zTT-06rO; Mon, 15 Jul 2024 18:16:30 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTQDC-00000007yXW-1pnD for linux-arm-kernel@lists.infradead.org; Mon, 15 Jul 2024 18:14:12 +0000 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46FH8gjl029987; Mon, 15 Jul 2024 18:13:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=qcppdkim1; bh=c7owLXpFna1dFjNdHfNbwtJ+ e/sHELDIGCOsgbwDi7k=; b=Q60kSvphq2xIVOGd4LV5oa54fKfTyzVPQZTUg6UU SDAdRUVEtPV+T8GKsA9WF36A07JAtNX1ETPFg6hg7yy8b1553waS+yPYhNnhvGNp gnymCGcyeXESc8S7MRYWIhUlahyh2QA/mv+tflu76YiRgrhJ4IYXpeyEqu+ZXNEo /0NLvTuPgW5me+RwLwicqiaj6NAvB4HI/IrPWvO+/OmKD/YIov5AcXzJHdMuxidX i0chdbyg6s4Xcr+/cUpJmMP8HnHaWU4zE41aOssiFDK7hoWw7KRhcuIVR+SsHtiA VG9bsYqQ1wEDoZcAcayRQ7R7Hj65y6bbDOgeFuZOLoIZbw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 40bf9ed68k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Jul 2024 18:13:55 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 46FIDsbr003669 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Jul 2024 18:13:54 GMT Received: from hu-mrana-lv.qualcomm.com (10.49.16.6) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 15 Jul 2024 11:13:53 -0700 From: Mayank Rana To: , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , Mayank Rana Subject: [PATCH V2 7/7] PCI: host-generic: Add dwc PCIe controller based MSI controller usage Date: Mon, 15 Jul 2024 11:13:35 -0700 Message-ID: <1721067215-5832-8-git-send-email-quic_mrana@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1721067215-5832-1-git-send-email-quic_mrana@quicinc.com> References: <1721067215-5832-1-git-send-email-quic_mrana@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: GHBMqoNpPxgEnql2LIncftsiqsmH4MN- X-Proofpoint-GUID: GHBMqoNpPxgEnql2LIncftsiqsmH4MN- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-15_12,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407150142 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240715_111410_513255_DBFDC13C X-CRM114-Status: GOOD ( 21.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add usage of Synopsys Designware PCIe controller based MSI controller to support MSI functionality with ECAM compliant Synopsys Designware PCIe controller. To use this functionality add device compatible string as "snps,dw-pcie-ecam-msi". Signed-off-by: Mayank Rana --- drivers/pci/controller/pci-host-generic.c | 92 ++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-host-generic.c b/drivers/pci/controller/pci-host-generic.c index c2c027f..457ae44 100644 --- a/drivers/pci/controller/pci-host-generic.c +++ b/drivers/pci/controller/pci-host-generic.c @@ -8,13 +8,73 @@ * Author: Will Deacon */ -#include #include +#include #include +#include #include #include #include +#include "dwc/pcie-designware-msi.h" + +struct dw_ecam_pcie { + void __iomem *cfg; + struct dw_msi *msi; + struct pci_host_bridge *bridge; +}; + +static u32 dw_ecam_pcie_readl(void *p_data, u32 reg) +{ + struct dw_ecam_pcie *ecam_pcie = (struct dw_ecam_pcie *)p_data; + + return readl(ecam_pcie->cfg + reg); +} + +static void dw_ecam_pcie_writel(void *p_data, u32 reg, u32 val) +{ + struct dw_ecam_pcie *ecam_pcie = (struct dw_ecam_pcie *)p_data; + + writel(val, ecam_pcie->cfg + reg); +} + +static struct dw_ecam_pcie *dw_pcie_ecam_msi(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct dw_ecam_pcie *ecam_pcie; + struct dw_msi_ops *msi_ops; + u64 addr; + + ecam_pcie = devm_kzalloc(dev, sizeof(*ecam_pcie), GFP_KERNEL); + if (!ecam_pcie) + return ERR_PTR(-ENOMEM); + + if (of_property_read_reg(dev->of_node, 0, &addr, NULL) < 0) { + dev_err(dev, "Failed to get reg address\n"); + return ERR_PTR(-ENODEV); + } + + ecam_pcie->cfg = devm_ioremap(dev, addr, PAGE_SIZE); + if (ecam_pcie->cfg == NULL) + return ERR_PTR(-ENOMEM); + + msi_ops = devm_kzalloc(dev, sizeof(*msi_ops), GFP_KERNEL); + if (!msi_ops) + return ERR_PTR(-ENOMEM); + + msi_ops->readl_msi = dw_ecam_pcie_readl; + msi_ops->writel_msi = dw_ecam_pcie_writel; + msi_ops->pp = ecam_pcie; + ecam_pcie->msi = dw_pcie_msi_host_init(pdev, msi_ops, 0); + if (IS_ERR(ecam_pcie->msi)) { + dev_err(dev, "dw_pcie_msi_host_init() failed\n"); + return ERR_PTR(-EINVAL); + } + + dw_pcie_msi_init(ecam_pcie->msi); + return ecam_pcie; +} + static const struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = { .bus_shift = 16, .pci_ops = { @@ -73,6 +133,9 @@ static const struct of_device_id gen_pci_of_match[] = { { .compatible = "snps,dw-pcie-ecam", .data = &pci_dw_ecam_bus_ops }, + { .compatible = "snps,dw-pcie-ecam-msi", + .data = &pci_generic_ecam_ops }, + { }, }; MODULE_DEVICE_TABLE(of, gen_pci_of_match); @@ -80,6 +143,7 @@ MODULE_DEVICE_TABLE(of, gen_pci_of_match); static int gen_pcie_ecam_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct dw_ecam_pcie *ecam_pcie = NULL; int ret = 0; if (!IS_ERR_OR_NULL(dev->pm_domain)) { @@ -94,14 +158,30 @@ static int gen_pcie_ecam_probe(struct platform_device *pdev) } } + if (of_device_is_compatible(dev->of_node, "snps,dw-pcie-ecam-msi")) { + ecam_pcie = dw_pcie_ecam_msi(pdev); + if (IS_ERR(ecam_pcie)) { + ret = -ENODEV; + goto err; + } + } + ret = pci_host_common_probe(pdev); if (ret) { dev_err(dev, "pci_host_common_probe() failed:%d\n", ret); goto err; } + if (ecam_pcie) { + ecam_pcie->bridge = platform_get_drvdata(pdev); + platform_set_drvdata(pdev, ecam_pcie); + } + return ret; err: + if (!IS_ERR_OR_NULL(ecam_pcie)) + dw_pcie_free_msi(ecam_pcie->msi); + if (!IS_ERR_OR_NULL(dev->pm_domain)) pm_runtime_put_sync(dev); return ret; @@ -109,7 +189,17 @@ static int gen_pcie_ecam_probe(struct platform_device *pdev) static void gen_pcie_ecam_remove(struct platform_device *pdev) { + struct dw_ecam_pcie *ecam_pcie = NULL; + + if (of_device_is_compatible(pdev->dev.of_node, "snps,dw-pcie-ecam-msi")) { + ecam_pcie = platform_get_drvdata(pdev); + platform_set_drvdata(pdev, ecam_pcie->bridge); + } + pci_host_common_remove(pdev); + if (ecam_pcie) + dw_pcie_free_msi(ecam_pcie->msi); + if (pdev->dev.pm_domain) pm_runtime_put_sync(&pdev->dev); } -- 2.7.4