From patchwork Thu May 13 13:45:45 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: 437329 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345448jao; Thu, 13 May 2021 06:46:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiVE4jT6njmHvACnmVChpxsBhyM6DK+BH2nXpsncqIkJtodsHwBKr5t3BQbbYqbz2vosZk X-Received: by 2002:a92:c544:: with SMTP id a4mr11399201ilj.207.1620913608762; Thu, 13 May 2021 06:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913608; cv=none; d=google.com; s=arc-20160816; b=sdJd72/cuftSh2txqLJlSp/WLZygywtQyymtFONxewN7eSqKOY7Z8BavOPRBPWtmOt ERGolsTNOfXf54ggRzjLkZZAfGYOQ5J9X4Yzjf1BagWW2mGknfifCAnhP9ugo8fOxWGi QpYqFrFFBLA1uiowfNt2s/2GAYaXAzNjmIQaaq/KfmCLldn9NsaWjaR0rUNo9HDDyw9o OlVql9Ov8+xVBkh6zcQX0wTgFLTy/6uMgKmY6esckv7IUJZPr5Dg1KlQ1VSBkvV00/pA C9OFMEtiaUrQ0RD+mq9AEjrC2lMy4MvuPUbntxIBteiKcZuDOSJR8IbW8xqLQOt7sooO fv/Q== 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=WR6ijNUUYHwxxb7y3nHXkaEGt03tMduEeHClWr1NQ+k=; b=GdlRJtT6HcpENFYzvCnROy4hSg+oK4VS3a329UkF/pRsCct8uKfWgufrlfAzVBXpRp rCwNPrwFiDluoUR8lFlEDgIpBOctFAJqVSqOLjyB/++Uz/J0lIYR9xivc/blSw/Mk6iC aF2zBmcIqkTDHdG/+/Onfa9lYO7CJnL0ZEywkLkovT8eivZp2LJB/unla0CLO2NItdNg UQGithJTjWoVUiOoIrx4IQMkfhdIM5hcryhrsatfGKTqWl1S8PSxifJ4jhmKX4OyaD/i tZg+qB5GXw+JklzrcUBZh4hagLK9CRxmegGW4xtcm1Cu9j6V7PmdxBm+N/3Kx8hy880s JbqQ== 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 u10si3346494ilv.5.2021.05.13.06.46.48; Thu, 13 May 2021 06:46:48 -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 S234099AbhEMNr4 (ORCPT + 4 others); Thu, 13 May 2021 09:47:56 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2591 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234161AbhEMNrz (ORCPT ); Thu, 13 May 2021 09:47:55 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FgtDM1Y86zsRJ3; Thu, 13 May 2021 21:44:03 +0800 (CST) Received: from A2006125610.china.huawei.com (10.47.81.63) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Thu, 13 May 2021 21:46:33 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 3/8] ACPI/IORT: Add a helper to retrieve RMR memory regions Date: Thu, 13 May 2021 14:45:45 +0100 Message-ID: <20210513134550.2117-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210513134550.2117-1-shameerali.kolothum.thodi@huawei.com> References: <20210513134550.2117-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.81.63] 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 it 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 fea1ffaedf3b..6ca88c38987a 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 -EINVAL; + + 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() @@ -1108,6 +1146,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 -ENODEV; } #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 674bd8815159..2d9caf548a32 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -203,6 +203,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 -EINVAL; } EXPORT_SYMBOL(iommu_dma_get_rmrs); diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index 1a12baa58e40..e8c45fa59531 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 -ENODEV; } #endif #endif /* __ACPI_IORT_H__ */