From patchwork Mon Feb 21 15:43:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 12753808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13056C433F5 for ; Mon, 21 Feb 2022 15:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kQYvnk7dpM0/gGb6s2G3lqQSxydjWXCwnedW94w0iY4=; b=jittr+eXBHZbSC +syu73U/927QQfOLqNubAHeDA2934H2td6BQDlHlu76Z9DyQW0tpE6IqcZaec07fYTXy8nu9/Z1mK 7uiLXwdpTWIxkHE24UM39jhk4iB8av8728vzmdRx0xULkucg9xAglZF9ger/cV00//vuwSJSlZnFZ Yr2Cj7NJzWq98DIy2yjYGqXJhqr82SQ0ozhe776OaxbfSMbUXClzHgcHZprqO7Amq5nZUsaQhcKqh ebN0iEzQ5zcQHp4lKxQNhh6xgAL2PoROgygCH+BeAKY33rsbb/tNxkmd+z053y6J8dmD7xG9ri2ad zBZzSDnvIGhIda68u+bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMAsc-006S5w-Ff; Mon, 21 Feb 2022 15:45:38 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMAsJ-006Rwk-LO for linux-arm-kernel@lists.infradead.org; Mon, 21 Feb 2022 15:45:21 +0000 Received: from fraeml709-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4K2RMl61rrz67Ys9; Mon, 21 Feb 2022 23:40:35 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml709-chm.china.huawei.com (10.206.15.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 21 Feb 2022 16:45:17 +0100 Received: from A2006125610.china.huawei.com (10.47.91.169) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 21 Feb 2022 15:45:09 +0000 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v8 05/11] ACPI/IORT: Add a helper to retrieve RMR memory regions Date: Mon, 21 Feb 2022 15:43:38 +0000 Message-ID: <20220221154344.2126-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20220221154344.2126-1-shameerali.kolothum.thodi@huawei.com> References: <20220221154344.2126-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.169] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220221_074520_047142_252D28D7 X-CRM114-Status: GOOD ( 15.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add helper functions (iort_iommu_get/put_rmrs()) that retrieves/releases RMR memory descriptors associated with a given IOMMU. This will be used by IOMMU drivers to set up necessary mappings. Invoke it from the generic iommu helper functions. Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 56 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/dma-iommu.c | 4 +++ include/linux/acpi_iort.h | 14 ++++++++++ 3 files changed, 74 insertions(+) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 05da9ebff50a..b2c959c72fb2 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1055,6 +1055,57 @@ static void iort_find_rmrs(struct acpi_iort_node *iommu, struct device *dev, } } +/** + * iort_iommu_dma_put_rmrs - Free any memory associated with RMRs. + * @iommu_fwnode: fwnode associated with IOMMU + * @head: Resereved region list + * + * This function go through the provided reserved region list and + * free up memory associated with RMR entries and delete them from + * the list. + */ +void iort_iommu_put_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *head) +{ + struct iommu_resv_region *e, *tmp; + + /* + * RMR entries will have mem allocated for fw_data.rmr.sids. + * Free the mem and delete the node. + */ + list_for_each_entry_safe(e, tmp, head, list) { + if (e->fw_data.rmr.sids) { + kfree(e->fw_data.rmr.sids); + list_del(&e->list); + kfree(e); + } + } +} + +/** + * + * iort_iommu_dma_get_rmrs - Retrieve Reserved Memory Regions(RMRs) associated + * with a given IOMMU and dev. + * @iommu_fwnode: fwnode associated with IOMMU + * @dev: Device associated with RMR(Optional) + * @list: RMR list to be populated + * + * This function populates the RMR list associated with a given IOMMU and + * dev(if provided). If dev is NULL, the function populates all the RMRs + * associated with the given IOMMU. + */ +void iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, struct device *dev, + struct list_head *head) +{ + struct acpi_iort_node *iommu; + + iommu = iort_get_iort_node(iommu_fwnode); + if (!iommu) + return; + + iort_find_rmrs(iommu, dev, head); +} + /** * iort_iommu_msi_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() @@ -1287,6 +1338,11 @@ int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) { return 0; } int iort_iommu_configure_id(struct device *dev, const u32 *input_id) { return -ENODEV; } +void iort_iommu_get_rmrs(struct fwnode_handle *fwnode, struct device *dev, + struct list_head *head) +{ } +void iort_iommu_put_rmrs(struct fwnode_handle *fwnode, struct list_head *head) +{ } #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 65ab01d5128b..b33e4df85de1 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -382,12 +382,16 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) void iommu_dma_get_rmrs(struct fwnode_handle *iommu_fwnode, struct device *dev, struct list_head *list) { + if (!is_of_node(iommu_fwnode)) + iort_iommu_get_rmrs(iommu_fwnode, dev, list); } EXPORT_SYMBOL(iommu_dma_get_rmrs); void iommu_dma_put_rmrs(struct fwnode_handle *iommu_fwnode, struct list_head *list) { + if (!is_of_node(iommu_fwnode)) + iort_iommu_put_rmrs(iommu_fwnode, list); } EXPORT_SYMBOL(iommu_dma_put_rmrs); diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index f1f0842a2cb2..212f7f178ec3 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -38,6 +38,10 @@ int iort_dma_get_ranges(struct device *dev, u64 *size); int 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); +void iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, struct device *dev, + struct list_head *list); +void iort_iommu_put_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) @@ -57,6 +61,16 @@ 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 +void iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, struct device *dev, + struct list_head *list) +{ } +void iort_iommu_put_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list) +{ } + +{ } #endif #endif /* __ACPI_IORT_H__ */