Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5004189imm; Tue, 16 Oct 2018 03:46:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Lz2u2nY78yzujoVVP9l+p4Fsm8ako7qKc+VseihRzc6BZOEqw0JuPBhdJZOBjOeZa7R6/ X-Received: by 2002:a63:2c8a:: with SMTP id s132-v6mr19210360pgs.73.1539686762550; Tue, 16 Oct 2018 03:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539686762; cv=none; d=google.com; s=arc-20160816; b=dNZHviueIG+FgKAE+H3OdT5DDpxjZt0C93fHh2fVe5azHWpLFUnci4rQxELLFhJY/O OQKxuPlzzKon+B/mc7X8/YW6z023M7teX54H3h3odEiLntfIb9TUV8/9A2x8yaJLUafx sYAkpgxX9xYfE11oicZJDNGxJ5n/Y02NQKP7s48XO+RFTyJAHO8Zn4wGCEhPZ6zI93kT /uqSDKoEeyYNzerlh0fi0vWL/4hfW7twfMQzi2J8t/NYd5/haT0AN2IUkOQaz/0aJNbv PoxrWJKaBMciXE6iXw0pAjgx7SGrb561x2Q2vzEY1k3GM8sCH8u83Sr/ar8aOA3OBIx0 Ingg== 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; bh=myzZ/N1OgtZSkkDrFEw52SJ6+pKKie0HqckFpJC14EI=; b=F3bm5HBBLeZ7i76Hgy1uodLn+ut1Ey3wdEWxUcIPquOEJ7nm+p+JNLl5lt5Zbce8K2 cenufruhxsoa4Z2asv1kbBQVHrywQZCZKftj0U94UL+py/JOhgqUoXm/+BqHw0rfbFft bpG34xw4Wn9fmjTx8xy5dWAP3hEujoxxonBoor2zC7vBJEMmpqJYNBYim3Wb+G/XRhU5 z9+zaEHfwHPk8mGIVgsEqh6n0a9rRKgqNPA8VAhdgXE/LsoshCm7zpcX0pM0gC0AjtTN CjaTv+tGKQh+iOgAsireNg7zHjo+0xSRChQ515yH08/6RQ5fl64Fs8qoCGau60FZgjFb nbPw== 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 b35-v6si9553697plh.177.2018.10.16.03.45.46; Tue, 16 Oct 2018 03:46:02 -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 S1727290AbeJPSfH (ORCPT + 99 others); Tue, 16 Oct 2018 14:35:07 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:2925 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726861AbeJPSfG (ORCPT ); Tue, 16 Oct 2018 14:35:06 -0400 X-UUID: 3a1b41a1e9f549908193c9f72323aca9-20181016 X-UUID: 3a1b41a1e9f549908193c9f72323aca9-20181016 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1003103490; Tue, 16 Oct 2018 18:45:09 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Oct 2018 18:45:07 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Oct 2018 18:45:07 +0800 From: To: , , , , , , CC: , , , , , , , , , Subject: [PATCH v9 9/9] PCI: mediatek: Add loadable kernel module support Date: Tue, 16 Oct 2018 18:44:50 +0800 Message-ID: <1539686690-24068-10-git-send-email-honghui.zhang@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1539686690-24068-1-git-send-email-honghui.zhang@mediatek.com> References: <1539686690-24068-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 | 51 +++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig index 028b287..465790f 100644 --- a/drivers/pci/controller/Kconfig +++ b/drivers/pci/controller/Kconfig @@ -231,7 +231,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 7f3b8a0..2a1f97c 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 @@ -532,6 +533,27 @@ 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; + + 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) { @@ -1171,6 +1193,31 @@ 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_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); + + mtk_pcie_put_resources(pcie); + + return 0; +} + static int __maybe_unused mtk_pcie_suspend_noirq(struct device *dev) { struct mtk_pcie *pcie = dev_get_drvdata(dev); @@ -1248,6 +1295,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, @@ -1255,4 +1303,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