Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7980024rwp; Wed, 19 Jul 2023 03:29:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlFfqazuOZ6+zYTH8nTh9ktp7QpnvMlfVc88oYYvOp5klxoJ8si1wQv7tc2uVNHsDb8JC+6F X-Received: by 2002:aa7:c3d8:0:b0:51d:d5a1:a7f1 with SMTP id l24-20020aa7c3d8000000b0051dd5a1a7f1mr2127387edr.38.1689762565758; Wed, 19 Jul 2023 03:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689762565; cv=none; d=google.com; s=arc-20160816; b=a7qT+fsojRmIK1hLP3aXW43bahq2oC+HdWodu2SF04KjM6LvloCWOz7vpaDbwvXbCu 3ApDttxEEVT8Nz5oiXM1qxdg7V5j6Wew0TuUyn+m0ixX394UoT9d9n99/YqJyur7fOqs mUBQlw3J/xGWhAGd05t9m8uo2MoGNLP1e708TvBx6T+GKDHUpSLLtokGG0bldip/4uq5 hbXSp+I6wToUxZpO3MaFLUVQsOjLg7izKnnd6GfFbk4VKn8+k2ygBIRWscuY815mkH+L XnS1HaxGG4BWkWPUwpjtFP7BFMpiIroKnX30RLFEXJfqV1cxWBZ5wQJepHUgBp+P2FKB FWfg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e25-20020a50fb99000000b0051ddc36463dsi2641469edq.629.2023.07.19.03.29.01; Wed, 19 Jul 2023 03:29:25 -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 S231224AbjGSKV2 (ORCPT + 99 others); Wed, 19 Jul 2023 06:21:28 -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=20Wilczy=C5=84ski?= , 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 Content-Type: text/plain 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 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) { -- 2.17.1