From patchwork Wed Jul 19 10:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minda Chen X-Patchwork-Id: 122524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2335190vqt; Wed, 19 Jul 2023 03:24:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGo7AG84sKeI2/b/SXTzsjWMQu7cmVmSV2K6JcpzvPS0OaeFqqw1QrAwNKYZR3bqpe3i+Z2 X-Received: by 2002:a17:903:1d1:b0:1b8:af7f:6331 with SMTP id e17-20020a17090301d100b001b8af7f6331mr1887912plh.55.1689762279048; Wed, 19 Jul 2023 03:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689762279; cv=none; d=google.com; s=arc-20160816; b=OiQGHO33M5Xbb02V5r10VVNYFYbanCGRBD5wmhH4yst+7hRgjG9dUCgr/fGhtie+7L 4nbee8bTaOpgtzdNAiiZrhHXuzTHVL2k437oLdvmXLXhL9ibvb02+7F/+dfrjiMOPdbD IvGZ6lQ8z+2Tx4nxFXBgk2jkHH2C53WAdGybpTGkT7dlcB6xYSJd1qv2Q5+9W9niM5LH 4/wKviIN+O9r9mQ3fWqSGeP4oEz2tyOicWxrG0xkla9lVl/9gU1W/JnmtM/mNSivxXTI U1iAnPMdYnfg2b0woLRed/txTloH3SGflUX3D7JTpHyXxk03Lm2I2v0e47qijSzM2Pgp +ZfQ== 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=8rmHmSBKfowS1ls3regSoE8iIjRjDNXAWZxZoubAiNg=; fh=d7kWbhDXUUwg3/pUZd6mzQXiPEgw5Ezg/At26C3Qzq0=; b=zhXhonyiQnViMXcF9/gIiMWqx/lED5diXFlVyjaJ98XculuGIqn/MZNjcontQ2StBd v9x/x4aCJO86nuGJaG0cK4WgMJSXtcDjDV4/cxzjF5/MKWUuCdbpFkRhYoo2jGBVO30l LmWtbn6hqGn6QTwQET8gwsKXN0Dkanb/e3wqbK58GaBoOjlBcPOgVpV3T+JThQ8vaBHS twU3HMnCtZ1ex8O7YNTYSV4NV9kFJlTLxs8BH5p028atZ+BowO7dDx1APfsTRFIc7E0b 9Zp3Dl4fK1TmWqxF45OUP/EVU+VehCOLnUettYhrKpX47+Kq9qXZ9BG33P+c5Xamsd9L Kkiw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a170902680800b001a64fa4eb27si3264187plk.230.2023.07.19.03.24.25; Wed, 19 Jul 2023 03:24:39 -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 S229651AbjGSKV3 (ORCPT + 99 others); Wed, 19 Jul 2023 06:21:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230360AbjGSKVJ (ORCPT ); Wed, 19 Jul 2023 06:21:09 -0400 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C3E1FC0; Wed, 19 Jul 2023 03:21:06 -0700 (PDT) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id 823AC24E2C0; Wed, 19 Jul 2023 18:21:05 +0800 (CST) Received: from EXMBX171.cuchost.com (172.16.6.91) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 19 Jul 2023 18:21:05 +0800 Received: from ubuntu.localdomain (113.72.147.86) by EXMBX171.cuchost.com (172.16.6.91) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 19 Jul 2023 18:21:04 +0800 From: Minda Chen To: Daire McNamara , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Bjorn Helgaas , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Emil Renner Berthing CC: , , , , Paul Walmsley , Palmer Dabbelt , Albert Ou , Philipp Zabel , Mason Huo , Leyfoon Tan , Kevin Xie , Minda Chen Subject: [PATCH v1 6/9] PCI: PLDA: Add host conroller platform driver Date: Wed, 19 Jul 2023 18:20:54 +0800 Message-ID: <20230719102057.22329-7-minda.chen@starfivetech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230719102057.22329-1-minda.chen@starfivetech.com> References: <20230719102057.22329-1-minda.chen@starfivetech.com> MIME-Version: 1.0 X-Originating-IP: [113.72.147.86] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) 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,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771844171434285182 X-GMAIL-MSGID: 1771844171434285182 Add PLDA XpressRICH PCIe host controller IP platform driver. Implement it like DesignWare PCIe platform driver. Signed-off-by: Minda Chen --- drivers/pci/controller/plda/Kconfig | 8 ++ drivers/pci/controller/plda/Makefile | 1 + drivers/pci/controller/plda/pcie-plda-host.c | 111 +++++++++++++++++++ drivers/pci/controller/plda/pcie-plda-plat.c | 64 +++++++++++ drivers/pci/controller/plda/pcie-plda.h | 3 + 5 files changed, 187 insertions(+) create mode 100644 drivers/pci/controller/plda/pcie-plda-plat.c diff --git a/drivers/pci/controller/plda/Kconfig b/drivers/pci/controller/plda/Kconfig index fb274976b84b..a3c790545843 100644 --- a/drivers/pci/controller/plda/Kconfig +++ b/drivers/pci/controller/plda/Kconfig @@ -8,6 +8,14 @@ config PCIE_PLDA_HOST depends on OF && PCI_MSI select IRQ_DOMAIN +config PCIE_PLDA_PLAT_HOST + bool "PLDA PCIe platform host controller" + select PCIE_PLDA_HOST + help + Say Y here if you want to support the PLDA PCIe platform controller in + host mode. This PCIe controller may be embedded into many different + vendors SoCs. + config PCIE_MICROCHIP_HOST bool "Microchip AXI PCIe controller" select PCI_HOST_COMMON diff --git a/drivers/pci/controller/plda/Makefile b/drivers/pci/controller/plda/Makefile index 4340ab007f44..2f16d9126535 100644 --- a/drivers/pci/controller/plda/Makefile +++ b/drivers/pci/controller/plda/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_PCIE_PLDA_HOST) += pcie-plda-host.o +obj-$(CONFIG_PCIE_PLDA_PLAT_HOST) += pcie-plda-plat.o obj-$(CONFIG_PCIE_MICROCHIP_HOST) += pcie-microchip-host.o diff --git a/drivers/pci/controller/plda/pcie-plda-host.c b/drivers/pci/controller/plda/pcie-plda-host.c index ca720430721c..e4baa63f6a5b 100644 --- a/drivers/pci/controller/plda/pcie-plda-host.c +++ b/drivers/pci/controller/plda/pcie-plda-host.c @@ -20,6 +20,15 @@ #include "pcie-plda.h" +void __iomem *plda_pcie_map_bus(struct pci_bus *bus, unsigned int devfn, + int where) +{ + struct plda_pcie *pcie = bus->sysdata; + + return pcie->config_base + PCIE_ECAM_OFFSET(bus->number, devfn, where); +} +EXPORT_SYMBOL_GPL(plda_pcie_map_bus); + void plda_pcie_enable_msi(struct plda_pcie *port) { struct plda_msi *msi = &port->msi; @@ -552,3 +561,105 @@ int plda_pcie_setup_iomems(struct plda_pcie *port, struct pci_host_bridge *bridg return 0; } EXPORT_SYMBOL_GPL(plda_pcie_setup_iomems); + +static void plda_pcie_irq_domain_deinit(struct plda_pcie *pcie) +{ + irq_set_chained_handler_and_data(pcie->irq, NULL, NULL); + irq_set_chained_handler_and_data(pcie->msi_irq, NULL, NULL); + irq_set_chained_handler_and_data(pcie->intx_irq, NULL, NULL); + + irq_domain_remove(pcie->msi.msi_domain); + irq_domain_remove(pcie->msi.dev_domain); + + irq_domain_remove(pcie->intx_domain); + irq_domain_remove(pcie->event_domain); +} + +int plda_pcie_host_init(struct plda_pcie *pcie, struct pci_ops *ops) +{ + struct resource *cfg_res; + struct device *dev = pcie->dev; + int ret; + struct pci_host_bridge *bridge; + struct platform_device *pdev = to_platform_device(dev); + struct plda_evt evt = {NULL, NULL, EVENT_PM_MSI_INT_INTX, + EVENT_PM_MSI_INT_MSI}; + + pcie->bridge_addr = + devm_platform_ioremap_resource_byname(pdev, "host"); + + if (IS_ERR(pcie->bridge_addr)) + return dev_err_probe(dev, PTR_ERR(pcie->bridge_addr), + "Failed to map reg memory\n"); + + cfg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg"); + if (!cfg_res) + return dev_err_probe(dev, -ENODEV, + "Failed to get config memory\n"); + + pcie->config_base = devm_ioremap_resource(dev, cfg_res); + if (IS_ERR(pcie->config_base)) + return dev_err_probe(dev, PTR_ERR(pcie->config_base), + "Failed to map config memory\n"); + + pcie->phy = devm_phy_optional_get(dev, NULL); + if (IS_ERR(pcie->phy)) + return dev_err_probe(dev, PTR_ERR(pcie->phy), + "Failed to get pcie phy\n"); + + bridge = devm_pci_alloc_host_bridge(dev, 0); + if (!bridge) + return dev_err_probe(dev, -ENOMEM, + "Failed to alloc bridge\n"); + + pcie->bridge = bridge; + + if (pcie->ops->host_init) { + ret = pcie->ops->host_init(pcie); + if (ret) + return ret; + } + + plda_pcie_setup_window(pcie->bridge_addr, 0, cfg_res->start, 0, + resource_size(cfg_res)); + plda_pcie_setup_iomems(pcie, bridge); + plda_set_default_msi(&pcie->msi); + ret = plda_pcie_init_irq(pcie, pdev, &evt); + if (ret) + goto err_host; + + /* Set default bus ops */ + bridge->ops = ops; + bridge->sysdata = pcie; + + plda_pcie_enable_msi(pcie); + + ret = pci_host_probe(bridge); + if (ret < 0) { + dev_err(dev, "Failed to pci host probe: %d\n", ret); + goto err_probe; + } + + return ret; + +err_probe: + plda_pcie_irq_domain_deinit(pcie); +err_host: + if (pcie->ops->host_deinit) + pcie->ops->host_deinit(pcie); + + return ret; +} +EXPORT_SYMBOL_GPL(plda_pcie_host_init); + +void plda_pcie_host_deinit(struct plda_pcie *pcie) +{ + pci_stop_root_bus(pcie->bridge->bus); + pci_remove_root_bus(pcie->bridge->bus); + + plda_pcie_irq_domain_deinit(pcie); + + if (pcie->ops->host_deinit) + pcie->ops->host_deinit(pcie); +} +EXPORT_SYMBOL_GPL(plda_pcie_host_deinit); diff --git a/drivers/pci/controller/plda/pcie-plda-plat.c b/drivers/pci/controller/plda/pcie-plda-plat.c new file mode 100644 index 000000000000..270aceb57c7a --- /dev/null +++ b/drivers/pci/controller/plda/pcie-plda-plat.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PLDA XpressRich PCIe platform driver + * + * Authors: Minda Chen + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie-plda.h" + +static struct pci_ops plda_default_ops = { + .map_bus = plda_pcie_map_bus, + .read = pci_generic_config_read, + .write = pci_generic_config_write, +}; + +static int plda_plat_pcie_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct plda_pcie *pci; + int ret; + + pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); + if (!pci) + return -ENOMEM; + + pci->dev = dev; + + ret = plda_pcie_host_init(pci, &plda_default_ops); + if (ret) { + dev_err(dev, "Failed to initialize host\n"); + return ret; + } + + platform_set_drvdata(pdev, pci); + + return ret; +} + +static const struct of_device_id plda_plat_pcie_of_match[] = { + { .compatible = "plda,xpressrich-pcie-host"}, + { /* sentinel */ } +}; + +static struct platform_driver plda_plat_pcie_driver = { + .driver = { + .name = "plda-xpressrich-pcie", + .of_match_table = plda_plat_pcie_of_match, + .suppress_bind_attrs = true, + }, + .probe = plda_plat_pcie_probe, +}; +builtin_platform_driver(plda_plat_pcie_driver); diff --git a/drivers/pci/controller/plda/pcie-plda.h b/drivers/pci/controller/plda/pcie-plda.h index feb3a0d9ace5..8785f885ddb1 100644 --- a/drivers/pci/controller/plda/pcie-plda.h +++ b/drivers/pci/controller/plda/pcie-plda.h @@ -157,6 +157,7 @@ struct plda_evt { int msi_evt; }; +void __iomem *plda_pcie_map_bus(struct pci_bus *bus, unsigned int devfn, int where); void plda_pcie_enable_msi(struct plda_pcie *port); void plda_pcie_setup_window(void __iomem *bridge_base_addr, u32 index, phys_addr_t axi_addr, phys_addr_t pci_addr, @@ -164,6 +165,8 @@ void plda_pcie_setup_window(void __iomem *bridge_base_addr, u32 index, int plda_pcie_setup_iomems(struct plda_pcie *port, struct pci_host_bridge *host_bridge); int plda_pcie_init_irq(struct plda_pcie *port, struct platform_device *pdev, struct plda_evt *evt); +int plda_pcie_host_init(struct plda_pcie *pcie, struct pci_ops *ops); +void plda_pcie_host_deinit(struct plda_pcie *pcie); static inline void plda_set_default_msi(struct plda_msi *msi) {