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: 142774 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp7166415ljj; Tue, 24 Jul 2018 04:46:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf9xA20521ygo0lyoOiReYe9ON0XYVY9AGJFFJGOWR2Ptx5BZY7+qLnDb/NaCFeO95p0QIm X-Received: by 2002:a63:d309:: with SMTP id b9-v6mr15991867pgg.163.1532432797942; Tue, 24 Jul 2018 04:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532432797; cv=none; d=google.com; s=arc-20160816; b=DG+uE/swOy1w7Jw3YVQZX4bDqVJyfUA1iHgV7784t1w3eDbizuGyquqZucV5P/SXKg GjFDOb3ICt+z0tXGg+5+Y8RUAyLzzQScrYXbL5hKt7SuZvbx9r1xcvzyJTrcA8OUbDJf aBLgo8E/wKH8XabVLvvJO+cfhfHhtZkZRL8BRvUcGF8seLOiX6oq0Xa+bkwY/XL95TrO xtBKmEURTqXSfuhbFAv87no3MNGuSvJkJ2xm+AZ6EjsgX278WEe3tq1FckEVJ12WyFbm S/hX7s1vLFDZPwIcerSBB/mre9fdGpTDj0xNM2b/4QMp8xRIAbAZ6hubzzRGHKRgelEE UnUg== 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=vUZORpuNv9VcH0DvoRt7GLwotfl01CcNvXZ4dcufeK0=; b=Wam1lntoRyg8l5GzGdLT2ELxOP4lHOOn3wFPy8OrZMP1gPjvsSDIfJfHlocVfWL+Kn 6vQ0Nn2SCPTwJC6R9ClszJOdH8vwrMqRW92hRpMGshZYTyNzccnXwZ8SQL2AeRKnJ2XJ 2zygYKkHCwmD9q4+4tR3N4emfUGi5HMQbE36ZTKFHZrNFvneciKhVPCL8drmjBpXckLQ IJnvrxhGqCJP/kcjDadl/TT0tcI7pe7I7hCgF7jRE0OBOWfHN7wys9hnmM5EevvfeQV8 eILapPR2PTqjvYRliLs2CW4BCpbbawyz4c7HEADJAm0ynXzjb6Uo9h69I5XOznQabZE0 1ulQ== 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 l7-v6si11273861pgc.650.2018.07.24.04.46.37; Tue, 24 Jul 2018 04:46:37 -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 S2388449AbeGXMwk (ORCPT + 31 others); Tue, 24 Jul 2018 08:52:40 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10112 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388370AbeGXMwj (ORCPT ); Tue, 24 Jul 2018 08:52:39 -0400 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: , CC: , , , , , , , , , , , 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.4 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) { }