From patchwork Thu Nov 19 12:11:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328403 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361498ils; Thu, 19 Nov 2020 04:13:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIS/Mb6hrNXob3/D/YlKlMtFoVK6uXXffgeOFFc5yI51XYqE0I11wS5+G1C7+aIl9UsviP X-Received: by 2002:aa7:c30e:: with SMTP id l14mr30658108edq.315.1605788032643; Thu, 19 Nov 2020 04:13:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788032; cv=none; d=google.com; s=arc-20160816; b=n+3Ygg4PIgB+81Mo+hSV/2ngjuNHsTvxOTWO5avXwmEK5ELFR5hQoGkajI1kFViI/W APlz5TviPLqEKqbQpF2Jj4ZADtm54shIBMqK7agWSFnyThy49W5m0KuPIVLd88pBwEPt 4O7PsQsUR3Iv9Q8m8q/Ik5QGRBvqPaB3zfCj/RifbKJ5pglskdaHDROKrkIjBKF1+Luj 8/pd2CKojDC70kGvf+9NLyEsDR7l32anu0GPtRSvWQBX+w14f/W0hXd0ebRLRood7z80 0ijjY3+hkoGC21BURyoK46EraA/apvD3WSVNpw8rrqZl5W+d7evB4r9Tb62rTOycRnF7 pQwA== 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=1RXyRJfu+HXCuhsiLAGwbZaeku3TAjDSAZTBtfIPhU4=; b=HxtDlFb0RGDNwfReqdggGmSHzOCMqkC4peQQJZh57k9++dq6CfFGRUcOT/Kjxi6MSx E5MOizhbaJNznplqTMR6BXCGI8iHtuo3NQQqtHS3R89/ThAZT9iyYbmxOFncB98AlYb+ 3l3XCoZ+nxGD9+r5CdFGahrIpvWsjsHE4dbvJH9whIq0Sudgg1YoThKTBhesRwJEzOpJ 9hVbfGpC24t+Z0Gq4/k4vWcUYltENNsWFqutwSw7yhWhukKOk5lnhCX4jBXmXxipxzSv tP6LQjUNxZNMsvYzZbQCAKWA9XHwqQySVhhW7T/aqHRUb3y8HpBwwnFDR+prmmHjbG/C 3S9g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.52; Thu, 19 Nov 2020 04:13:52 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727114AbgKSMMx (ORCPT + 5 others); Thu, 19 Nov 2020 07:12:53 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:7564 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727058AbgKSMMx (ORCPT ); Thu, 19 Nov 2020 07:12:53 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcJTb4ZwHzhd1R; Thu, 19 Nov 2020 20:12:35 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:44 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 4/8] ACPI/IORT: Add RMR memory regions reservation helper Date: Thu, 19 Nov 2020 12:11:46 +0000 Message-ID: <20201119121150.3316-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] 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 | 60 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/dma-iommu.c | 3 ++ include/linux/acpi_iort.h | 6 ++++ 3 files changed, 69 insertions(+) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index a9705aa35028..d1a2b09230ab 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -842,6 +843,63 @@ 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 iort_rmr_id *rmr_ids = e->rmr_ids; + struct acpi_iort_rmr_desc *rmr_desc; + struct iommu_rmr *rmr; + u32 *ids, num_ids = 0; + int i, j = 0; + + for (i = 0; i < e->rmr_ids_num; i++) { + if (rmr_ids[i].smmu == iommu) + num_ids++; + } + + if (!num_ids) + continue; + + ids = kmalloc_array(num_ids, sizeof(*ids), GFP_KERNEL); + if (!ids) + return -ENOMEM; + + for (i = 0; i < e->rmr_ids_num; i++) { + if (rmr_ids[i].smmu == iommu) + ids[j++] = rmr_ids[i].sid; + } + + rmr_desc = e->rmr_desc; + rmr = iommu_dma_alloc_rmr(rmr_desc->base_address, + rmr_desc->length, + ids, num_ids); + if (!rmr) { + kfree(ids); + return -ENOMEM; + } + + list_add_tail(&rmr->list, head); + kfree(ids); + } + + return 0; +} + /** * iort_iommu_msi_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() @@ -1112,6 +1170,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 d73768ecdd1a..aa8304e50786 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -176,6 +176,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 20a32120bb88..0b61b98a4941 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -38,6 +38,8 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *size); 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); +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) @@ -55,6 +57,10 @@ static inline const struct iommu_ops *iort_iommu_configure_id( static inline int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) { return 0; } +static inline +int iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list) +{ return 0; } #endif #endif /* __ACPI_IORT_H__ */