Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp556060imm; Fri, 28 Sep 2018 03:05:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Ncd1BW79MkrDX78WOP4Afbb1NfGlBeWCgvpIxQlu003v/n4OZi6zWYsq40/p10VP4LF/a X-Received: by 2002:a63:7b09:: with SMTP id w9-v6mr14671965pgc.385.1538129140502; Fri, 28 Sep 2018 03:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538129140; cv=none; d=google.com; s=arc-20160816; b=sHwB8Pzu3EXq84YjusPIzFMNYWtMVeZ2LrlP4IyAZrt6f6rRobCVwcm29yZF4RpLNF agJGdae5aT0jFU2o6vDHU9jnx+3x+WwhVlyZ3EPvgbY7BPLmNAGIwwUwQeQyHt1fHN0L 6ENrdIk9JqZFOiAZbwlyV55NXtmU9F3Zb/CEdz1kvbly0xHxQZsBZPFwvPknMeTZNhmz rbjpIUxEwitsC43skuZ2Iq3Qw9MZAeKGH58iRzSd+KBfryG051WYkIWJypw3dUkVp+xS jDFWVvy57j5e4yeoz0UK0QvTx/BU3rPupbzpnYguDpmOCLdGrIyczrMANOcYDfu/+5Tw 1jOg== 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=LaFOjqDZ6WI0i/yH6zFD0nufGhQnnaLs+W5Eq53CcJE=; b=qcgD3kMsjPp6+mDNWq4rtwWukGNrsBYsIo6YBc96aKjh1UhYed9X1utqxfl6uvlE0L /nY0LUNIz3TQYzv0Sp2DFV+HPd8cqT3JaJb65R4V5erAvQr6Sptbz+/VRzAPflDgQvTK NGAe0m8XR2b0bXWzdJMGH8byLgHVOlPBKUTVBQwXovTt2FbaDtP+gLvPQQO4Mto8rMJg fbJZiXN6hnJ5Trzjl92bHeV+hw4c4QLRBmjK4HNXIrJNwD3hTIJSx0ObUfJWiTKIzGGg Mc1O3Fe94rmPQGNk3eEZpAlzjUIzpUSmKwMU1hxCXxqH6wNs/zboUwBomkzwggvbGlmt 12xA== 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 o15-v6si4607880pgf.253.2018.09.28.03.05.24; Fri, 28 Sep 2018 03:05:40 -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 S1729406AbeI1Q16 (ORCPT + 99 others); Fri, 28 Sep 2018 12:27:58 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49950 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729362AbeI1Q15 (ORCPT ); Fri, 28 Sep 2018 12:27:57 -0400 X-UUID: 3b42a84649244825948714084e935bff-20180928 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 496390613; Fri, 28 Sep 2018 18:04:52 +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; Fri, 28 Sep 2018 18:04:51 +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; Fri, 28 Sep 2018 18:04:50 +0800 From: To: , , , , , , CC: , , , , , , , , , Subject: [PATCH v5 9/9] PCI: mediatek: Add loadable kernel module support Date: Fri, 28 Sep 2018 18:04:40 +0800 Message-ID: <1538129080-8206-10-git-send-email-honghui.zhang@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1538129080-8206-1-git-send-email-honghui.zhang@mediatek.com> References: <1538129080-8206-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 --- drivers/pci/controller/Kconfig | 2 +- drivers/pci/controller/pcie-mediatek.c | 52 +++++++++++++++++++++++++++++++++- 2 files changed, 52 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 d35890c..b8ae214 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 @@ -536,6 +537,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) { @@ -1175,6 +1197,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); + + 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); @@ -1252,6 +1300,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, @@ -1259,4 +1308,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