From patchwork Tue Apr 20 08:27:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 424556 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp206623jao; Tue, 20 Apr 2021 02:28:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9RIrdXK0Mo5cZ520bWcj8xy4lsUf/WP18W3sGM/5D8sQuvVbN0yTRge2MIfD6rlhBPJFz X-Received: by 2002:a17:906:2e59:: with SMTP id r25mr26308615eji.268.1618910914539; Tue, 20 Apr 2021 02:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618910914; cv=none; d=google.com; s=arc-20160816; b=y5iSh3Rw5gvSPvQ5rzQFPQWqj1zQh88IBYlre+ssw3X9sCaM/y1820DKntvHCxAitA 6ldP6msR6v02eBvdm43aFVEVHsIYvHukw1+5uUSGisAddYgKDoigHW41NxOTPyP4V2Fs UhIFrrYPRLaYD9VrVU/gpuNeBgZj6zek26oheAFBQsDWKYhL6PGj/NBPjAWPyPRihN3s IPdeJwQolmW6G5QDh1f+tmSR0kIn0DEbNnAXScF8VqCe7LfsdHJGnkPVRIIy8mve4BYY Dtxht05eCzv0z76zJYBzGEDw7pw05y4xtmyDMh+Vp2it1eLjsDIyzKj1bcPKXhiCjMwE LwiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=QtPBDB1MdsMQm220JUwBsxKV35NmSrYgqg++CfmXnhs=; b=sjpOttvhe+JWM7JBL9UJGFZyLrJchaDXRzSykzCoOvxeKz4M9B/Ks8gz8flU5X1tHs NhdgF5IEfrgg8xnN6wvvP04TcI9pj/iYYv8yZ2ZslchrXFNaxzal0+cp08ym0QCCAGY1 4hiz1c5bl8WhSbFBkLg72YSG2jJiDhbcGcjV9UG1ZFv2BGwsYkyUV7kfd286vDm87Nss wYhiUCUKCVTk1jmAKGkeiNGmEVFIhlotXo/W5Mb8ZX/biGfU2feNypLzn8mM311o92fv OQ4MqlWz8EqtC8HsKlB8M1Q/8n8MAGTq1nfI/vuCn5dJ0cFdJ7T5gQE2bEPQHWIq0M/s A3pA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si5177143edq.3.2021.04.20.02.28.34; Tue, 20 Apr 2021 02:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230429AbhDTJ3E (ORCPT + 4 others); Tue, 20 Apr 2021 05:29:04 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:16606 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbhDTJ3E (ORCPT ); Tue, 20 Apr 2021 05:29:04 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FPdbQ05w2z19M2h; Tue, 20 Apr 2021 17:26:10 +0800 (CST) Received: from A2006125610.china.huawei.com (10.47.83.26) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 20 Apr 2021 17:28:20 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , Subject: [PATCH v3 03/10] ACPI/IORT: Add a helper to retrieve RMR memory regions Date: Tue, 20 Apr 2021 10:27:44 +0200 Message-ID: <20210420082751.1829-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210420082751.1829-1-shameerali.kolothum.thodi@huawei.com> References: <20210420082751.1829-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.83.26] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add a helper function that retrieves RMR memory descriptors associated with a given IOMMU. This will be used by IOMMU drivers to setup necessary mappings. Now that we have this, invoke this from the generic helper interface. Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 40 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/dma-iommu.c | 3 +++ include/linux/acpi_iort.h | 7 +++++++ 3 files changed, 50 insertions(+) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index bd96c5e3b36e..66e314b15692 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -837,6 +838,43 @@ static inline int iort_add_device_replay(struct device *dev) return err; } +/** + * iort_iommu_get_rmrs - Helper to retrieve RMR info associated with IOMMU + * @iommu: fwnode for the IOMMU + * @head: RMR list head to be populated + * + * Returns: 0 on success, <0 failure + */ +int iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *head) +{ + struct iort_rmr_entry *e; + struct acpi_iort_node *iommu; + + iommu = iort_get_iort_node(iommu_fwnode); + if (!iommu) + return 0; + + list_for_each_entry(e, &iort_rmr_list, list) { + struct acpi_iort_rmr_desc *rmr_desc; + struct iommu_rmr *rmr; + + if (e->smmu != iommu) + continue; + + rmr_desc = e->rmr_desc; + rmr = iommu_dma_alloc_rmr(rmr_desc->base_address, + rmr_desc->length, e->sid, + e->flags); + if (!rmr) + return -ENOMEM; + + list_add_tail(&rmr->list, head); + } + + return 0; +} + /** * iort_iommu_msi_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() @@ -1107,6 +1145,8 @@ int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) const struct iommu_ops *iort_iommu_configure_id(struct device *dev, const u32 *input_id) { return NULL; } +int iort_iommu_get_rmrs(struct fwnode_handle *fwnode, struct list_head *head) +{ return 0; } #endif static int nc_dma_get_range(struct device *dev, u64 *size) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 86a1e48b1fe8..a942cc04eee1 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -201,6 +201,9 @@ EXPORT_SYMBOL(iommu_dma_get_resv_regions); int iommu_dma_get_rmrs(struct fwnode_handle *iommu_fwnode, struct list_head *list) { + if (!is_of_node(iommu_fwnode)) + return iort_iommu_get_rmrs(iommu_fwnode, list); + return 0; } EXPORT_SYMBOL(iommu_dma_get_rmrs); diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index 1a12baa58e40..e9f3bc2f4842 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -39,6 +39,8 @@ const struct iommu_ops *iort_iommu_configure_id(struct device *dev, const u32 *id_in); int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head); phys_addr_t acpi_iort_dma_get_max_cpu_address(void); +int iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list); #else static inline void acpi_iort_init(void) { } static inline u32 iort_msi_map_id(struct device *dev, u32 id) @@ -59,6 +61,11 @@ int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) static inline phys_addr_t acpi_iort_dma_get_max_cpu_address(void) { return PHYS_ADDR_MAX; } + +static inline +int iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list) +{ return 0; } #endif #endif /* __ACPI_IORT_H__ */