From patchwork Tue Jul 24 11:45:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 10541921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B46A184F for ; Tue, 24 Jul 2018 11:47:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77169285B5 for ; Tue, 24 Jul 2018 11:47:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B1E528709; Tue, 24 Jul 2018 11:47:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F0EF1285B5 for ; Tue, 24 Jul 2018 11:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=q9hKuMXs3H8nVj11GU/DSG11no6PHddDQLKiYV1ZfXQ=; b=YQ2qIhsHwZ7Eqc rNuM8keKFOq4XHKABkVGN3ImKtRvkXgVrcLEgoHwKbF2CRoomJfjQAHKdLelNTQiMT1XClA5Cd4sB N1d2r2FWlYREpzIWEA4D3+kOF9wRM48aOZKsq94iz7sOtR09i7KGREOHcPBNur7PaiRdi8oEHyU0I 1aMUqcWAZnvrOpFAStmFNwGMQqNgslmh59piAWdBo5fUcLNsh2wbltn9c1veNVKf2iw9es4RS/m2y TYll5QeK3b907k0LFK/Jqp+TjB9adMpFzruEXAYFoNSv7RMeBfOGO7u63hxR4XBHQO9F3lDCLTFl5 PM4sEpupx3nZMWlRxgXg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhvn9-00085F-Km; Tue, 24 Jul 2018 11:47:47 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhvm2-00075g-Tx for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 11:46:42 +0000 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DD0AFB580EA43; Tue, 24 Jul 2018 19:46:29 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.382.0; Tue, 24 Jul 2018 19:46:21 +0800 From: Shameer Kolothum To: , Subject: [PATCH v2 2/4] acpi: arm64: iort helper to find the associated smmu of pmcg node Date: Tue, 24 Jul 2018 12:45:13 +0100 Message-ID: <20180724114515.21764-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20180724114515.21764-1-shameerali.kolothum.thodi@huawei.com> References: <20180724114515.21764-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_044639_210150_6D4FD318 X-CRM114-Status: GOOD ( 18.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, vkilari@codeaurora.org, neil.m.leeder@gmail.com, pabba@codeaurora.org, john.garry@huawei.com, will.deacon@arm.com, rruigrok@codeaurora.org, linuxarm@huawei.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, guohanjun@huawei.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This adds an helper to retrieve the smmuv3 dev(if any) associated with the PMCG node. This will be used in subsequent SMMUv3 PMU driver patch to name the pmu device. Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 84 ++++++++++++++++++++++++++++++++++++----------- include/linux/acpi_iort.h | 4 +++ 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index ac4d0d6..7940080 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -42,6 +42,7 @@ struct iort_fwnode { struct list_head list; struct acpi_iort_node *iort_node; struct fwnode_handle *fwnode; + struct platform_device *pdev; }; static LIST_HEAD(iort_fwnode_list); static DEFINE_SPINLOCK(iort_fwnode_lock); @@ -52,12 +53,14 @@ static DEFINE_SPINLOCK(iort_fwnode_lock); * * @node: IORT table node associated with the IOMMU * @fwnode: fwnode associated with the IORT node + * @pdev: platform dev associated with the IORT node if any * * Returns: 0 on success * <0 on failure */ static inline int iort_set_fwnode(struct acpi_iort_node *iort_node, - struct fwnode_handle *fwnode) + struct fwnode_handle *fwnode, + struct platform_device *pdev) { struct iort_fwnode *np; @@ -69,6 +72,7 @@ static inline int iort_set_fwnode(struct acpi_iort_node *iort_node, INIT_LIST_HEAD(&np->list); np->iort_node = iort_node; np->fwnode = fwnode; + np->pdev = pdev; spin_lock(&iort_fwnode_lock); list_add_tail(&np->list, &iort_fwnode_list); @@ -78,6 +82,31 @@ static inline int iort_set_fwnode(struct acpi_iort_node *iort_node, } /** + * iort_get_pdev() - Retrieve pdev associated with an IORT node + * + * @node: IORT table node to be looked-up + * + * Returns: platform dev pointer on success, NULL on failure + */ +static inline struct platform_device *iort_get_pdev( + struct acpi_iort_node *node) +{ + struct iort_fwnode *curr; + struct platform_device *pdev = NULL; + + spin_lock(&iort_fwnode_lock); + list_for_each_entry(curr, &iort_fwnode_list, list) { + if (curr->iort_node == node) { + pdev = curr->pdev; + break; + } + } + spin_unlock(&iort_fwnode_lock); + + return pdev; +} + +/** * iort_get_fwnode() - Retrieve fwnode associated with an IORT node * * @node: IORT table node to be looked-up @@ -1347,6 +1376,32 @@ static struct acpi_iort_node *iort_find_pmcg_ref(struct acpi_iort_node *node) return ref_node; } +/** + * iort_find_pmcg_ref_smmu - helper to retrieve SMMUv3 associated with PMCG + * @dev: PMCG device + * + * Returns: smmu dev associated with the PMCG on success, NULL on failure + */ +struct device *iort_find_pmcg_ref_smmu(struct device *dev) +{ + struct acpi_iort_node *node; + struct acpi_iort_node *ref_node = NULL; + struct platform_device *pdev = NULL; + + node = iort_get_iort_node(dev->fwnode); + if (!node || node->type != ACPI_IORT_NODE_PMCG) + return NULL; + + ref_node = iort_find_pmcg_ref(node); + if (ref_node && ref_node->type == ACPI_IORT_NODE_SMMU_V3) + pdev = iort_get_pdev(ref_node); + + if (pdev) + return &pdev->dev; + + return NULL; +} + struct iort_dev_config { const char *name; int (*dev_init)(struct acpi_iort_node *node); @@ -1453,13 +1508,14 @@ static int __init iort_add_platform_device(struct acpi_iort_node *node, if (ret) goto dev_put; - fwnode = iort_get_fwnode(node); - + fwnode = acpi_alloc_fwnode_static(); if (!fwnode) { ret = -ENODEV; goto dev_put; } + iort_set_fwnode(node, fwnode, pdev); + pdev->dev.fwnode = fwnode; if (ops->dev_dma_configure) { @@ -1472,12 +1528,14 @@ static int __init iort_add_platform_device(struct acpi_iort_node *node, ret = platform_device_add(pdev); if (ret) - goto dma_deconfigure; + goto out; return 0; -dma_deconfigure: +out: acpi_dma_deconfigure(&pdev->dev); + iort_delete_fwnode(node); + acpi_free_fwnode_static(fwnode); dev_put: platform_device_put(pdev); @@ -1519,8 +1577,7 @@ static void __init iort_init_platform_devices(void) { struct acpi_iort_node *iort_node, *iort_end; struct acpi_table_iort *iort; - struct fwnode_handle *fwnode; - int i, ret; + int i; bool acs_enabled = false; const struct iort_dev_config *ops; @@ -1547,18 +1604,7 @@ static void __init iort_init_platform_devices(void) ops = iort_get_dev_cfg(iort_node); if (ops) { - fwnode = acpi_alloc_fwnode_static(); - if (!fwnode) - return; - - iort_set_fwnode(iort_node, fwnode); - - ret = iort_add_platform_device(iort_node, ops); - if (ret) { - iort_delete_fwnode(iort_node); - acpi_free_fwnode_static(fwnode); - return; - } + iort_add_platform_device(iort_node, ops); } iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index 38cd77b..54ccff2 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -36,6 +36,7 @@ u32 iort_msi_map_rid(struct device *dev, u32 req_id); struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id); void acpi_configure_pmsi_domain(struct device *dev); int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id); +struct device *iort_find_pmcg_ref_smmu(struct device *dev); /* IOMMU interface */ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *size); const struct iommu_ops *iort_iommu_configure(struct device *dev); @@ -48,6 +49,9 @@ static inline struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id) { return NULL; } static inline void acpi_configure_pmsi_domain(struct device *dev) { } +static inline +struct device *iort_find_pmcg_ref_smmu(struct device *dev) +{ return NULL; } /* IOMMU interface */ static inline void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *size) { }