Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6139881imm; Wed, 27 Jun 2018 02:57:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJKzzLllZcFjP6jEWSn5blT0CZcHHpvxEU5IXWNMA0hGdXeWldiljW+wnxoMpPiKuH6NqC9 X-Received: by 2002:a63:64c2:: with SMTP id y185-v6mr4540090pgb.126.1530093425397; Wed, 27 Jun 2018 02:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530093425; cv=none; d=google.com; s=arc-20160816; b=uY0Zx0rOEiv3gSUxj822mPg0Gfdi86/6WQbI8SBS0DGcrlmFX/AC+20eKq6WT6WBPY pK4Wk4hX7CskgC9kQUaJDvdSPHjmAY0rrSCbo4eYZ7Ek4yUhA3pO6JisLuTvMaRViTvO B98tPnNyT83OxiPmc2J5+h58puyMqaFEzQc6gcFa3VZ+KWQIKNWCQR2oRQ0LC2VnvFwK aMXox/qC7BYeG4HQNuASKCrMHhUhjfYBQH3R7Auo7DT1YmN5/A/mDMvnZOyk3Hcp/IbH Ak5/sYSNZYnMliBAXgJYCkUQWJAzvUiJAo+2gUuN3SIcXprhRuVItwhj6cjkLN7/Qh89 qQ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=wL3iMPihtyxvLa0vulTG/KgP9jnB2SjMqi/ANp6FlzA=; b=FLmPsaI0cu8Mt+iovdEyNUJjGdEtXQLKOUuhnPIzUo4EXwyumHS3Xgi0B1FgTHQTnp 8IQbW0QR6ZPq4s4e+CtVpRSIIBfzEhpBF9ESCsdXSeXkHhaHfLH33qy0G6V+bJilQ/jR BC0G/5loLVFNIs0FuzZEcihkgR7KwU3Vn/GBeNkxo5/sAjDWNEma9ugma+3gywR+VnK/ n8BfJn2BJ+YfZRDzt/pj6p9SNtf5Dp86Hz37ESBgRThKvGYfER4XZ+v5/7wHiJgOXLEw 3PwSfh+ZMNsJzVYL6+0XieqJcj854SCybjraUs3C68OStm9SwA4FPdNq3EMqi3PsHoZQ Wj7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v73-v6si3668480pfi.22.2018.06.27.02.56.47; Wed, 27 Jun 2018 02:57:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753445AbeF0JWS (ORCPT + 99 others); Wed, 27 Jun 2018 05:22:18 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:35320 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753319AbeF0JV7 (ORCPT ); Wed, 27 Jun 2018 05:21:59 -0400 X-UUID: 747f2962b28b460bb1873de5c46714d4-20180627 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 158322434; Wed, 27 Jun 2018 17:21:55 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 27 Jun 2018 17:21:53 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Wed, 27 Jun 2018 17:21:52 +0800 From: To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH 4/4] PCI: mediatek: Add loadable kernel module support Date: Wed, 27 Jun 2018 17:21:38 +0800 Message-ID: <1530091298-28120-5-git-send-email-honghui.zhang@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1530091298-28120-1-git-send-email-honghui.zhang@mediatek.com> References: <1530091298-28120-1-git-send-email-honghui.zhang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Honghui Zhang Implement remove callback function for Mediatek PCIe driver to add loadable kernel module support. Signed-off-by: Honghui Zhang Reviewed-by: Ryder Lee --- drivers/pci/controller/Kconfig | 2 +- drivers/pci/controller/pcie-mediatek.c | 63 +++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig index 18fa09b..6c61ac65 100644 --- a/drivers/pci/controller/Kconfig +++ b/drivers/pci/controller/Kconfig @@ -234,7 +234,7 @@ config PCIE_ROCKCHIP_EP available to support GEN2 with 4 slots. config PCIE_MEDIATEK - bool "MediaTek PCIe controller" + tristate "MediaTek PCIe controller" depends on ARCH_MEDIATEK || COMPILE_TEST depends on OF depends on PCI_MSI_IRQ_DOMAIN diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index cac01ab..5830cea 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -184,6 +185,7 @@ struct mtk_pcie_port { struct phy *phy; u32 lane; u32 slot; + int irq; struct irq_domain *irq_domain; struct irq_domain *inner_domain; struct irq_domain *msi_domain; @@ -536,6 +538,30 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port) writel(val, port->base + PCIE_INT_MASK); } +static void mtk_pcie_irq_teardown(struct mtk_pcie *pcie) +{ + struct mtk_pcie_port *port, *tmp; + + if (list_empty(&pcie->ports)) + return; + + list_for_each_entry_safe(port, tmp, &pcie->ports, list) { + irq_set_chained_handler_and_data(port->irq, NULL, NULL); + + if (port->irq_domain) + irq_domain_remove(port->irq_domain); + + if (IS_ENABLED(CONFIG_PCI_MSI)) { + if (port->msi_domain) + irq_domain_remove(port->msi_domain); + if (port->inner_domain) + irq_domain_remove(port->inner_domain); + } + + irq_dispose_mapping(port->irq); + } +} + static int mtk_pcie_intx_map(struct irq_domain *domain, unsigned int irq, irq_hw_number_t hwirq) { @@ -626,7 +652,7 @@ static int mtk_pcie_setup_irq(struct mtk_pcie_port *port, struct mtk_pcie *pcie = port->pcie; struct device *dev = pcie->dev; struct platform_device *pdev = to_platform_device(dev); - int err, irq; + int err; err = mtk_pcie_init_irq_domain(port, node); if (err) { @@ -634,8 +660,9 @@ static int mtk_pcie_setup_irq(struct mtk_pcie_port *port, return err; } - irq = platform_get_irq(pdev, port->slot); - irq_set_chained_handler_and_data(irq, mtk_pcie_intr_handler, port); + port->irq = platform_get_irq(pdev, port->slot); + irq_set_chained_handler_and_data(port->irq, + mtk_pcie_intr_handler, port); return 0; } @@ -1197,6 +1224,32 @@ static int mtk_pcie_probe(struct platform_device *pdev) return err; } +static void mtk_pcie_free_resources(struct mtk_pcie *pcie) +{ + struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); + struct list_head *windows = &host->windows; + + pci_unmap_iospace(&pcie->pio); + pci_free_resource_list(windows); +} + +static int mtk_pcie_remove(struct platform_device *pdev) +{ + struct mtk_pcie *pcie = platform_get_drvdata(pdev); + struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); + + pci_stop_root_bus(host->bus); + pci_remove_root_bus(host->bus); + mtk_pcie_free_resources(pcie); + + mtk_pcie_irq_teardown(pcie); + + if (!list_empty(&pcie->ports)) + mtk_pcie_put_resources(pcie); + + return 0; +} + #ifdef CONFIG_PM_SLEEP static int mtk_pcie_suspend_noirq(struct device *dev) { @@ -1290,6 +1343,7 @@ static const struct of_device_id mtk_pcie_ids[] = { static struct platform_driver mtk_pcie_driver = { .probe = mtk_pcie_probe, + .remove = mtk_pcie_remove, .driver = { .name = "mtk-pcie", .of_match_table = mtk_pcie_ids, @@ -1297,4 +1351,5 @@ static struct platform_driver mtk_pcie_driver = { .pm = &mtk_pcie_pm_ops, }, }; -builtin_platform_driver(mtk_pcie_driver); +module_platform_driver(mtk_pcie_driver); +MODULE_LICENSE("GPL v2"); -- 2.6.4