From patchwork Mon May 24 11:02:15 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: 446433 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3237647jac; Mon, 24 May 2021 04:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE23wUPFGsUZyoonc9KN6PiLkugqFYMrf/vJYdPPi+liQtX0J3sy5kOCnvC3UYJaQVVPaK X-Received: by 2002:a17:906:e10b:: with SMTP id gj11mr22462451ejb.202.1621854204228; Mon, 24 May 2021 04:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854204; cv=none; d=google.com; s=arc-20160816; b=w6fJ0FwlcUCeN2GchB/U7tp1UJa3f1J3IruOVgKAwGoHXWc0ht/uqqiDLIgk450v2f B3eYoVRPo6mGjlntfAt8Cgqy1L//Dj3Su/RnsNQRRq7nQ4h2ary86TyYQSaVOLhyOk7B C10dh9cA2SSF0j5e3FdkK8UqZ4LEj2X+OZbgztR4JG9rLtxGD9JhSSQgquEEc6ue+Ls4 pcd76q2vQYPKoFJTkWcgc2LNyhmwork696g/kIVQWDzg2z1RQu7Fq8bW7CZu4kyuip7P ypG7kAJoxlfBVPLjYXOyXJi0dDqvq0GgeNckDFErSfOKCwLUAbBJB8/oxeeB42rcBFbW ACFQ== 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=flRwSlD3DTRrQQWdUyrcvfAenRCVTlA71wuTlzMX4Vs=; b=px/XKDfP6oQsDtDZq4CRzKejbKBKKPHmtzSdHRjvodTQ7LNNBvuOgVt08QreD9QeIY P6sHi2dHAysSj7aWjv5PCi6qJ9fMD4VOgO8QdZakBbuEYLAXzDyqui20BGtmzFKOJ2nV A9lZRBAJD3mMHfczgAWheMxx5+kQWg2FkY8QjiMD3ynLuvms0qBDDrp2mv8JJzoRZvaT m8LhQIniD4mQkyKW9MGeJ2Te0ApxX+iM5x0GaaVK0JwgZHv988zUQYdC4TnFihaFAZVa Y+0cvoSpk8P7jbnOiRGqtXiGryy1GWtq9Cbaw1GWefDBts+gkgzO6OrONMC7uPDG6yAr eKPQ== 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 m5si12473319eds.484.2021.05.24.04.03.24; Mon, 24 May 2021 04:03:24 -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 S232547AbhEXLEu (ORCPT + 4 others); Mon, 24 May 2021 07:04:50 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5531 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232494AbhEXLEt (ORCPT ); Mon, 24 May 2021 07:04:49 -0400 Received: from dggems705-chm.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpZ4Y3MtMzkYwd; Mon, 24 May 2021 19:00:29 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:03:18 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:03:09 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 1/8] ACPI/IORT: Add support for RMR node parsing Date: Mon, 24 May 2021 12:02:15 +0100 Message-ID: <20210524110222.2212-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add support for parsing RMR node information from ACPI. Find associated stream id and smmu node info from the RMR node and populate a linked list with RMR memory descriptors. Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 104 +++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 3912a1f6058e..fea1ffaedf3b 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -40,6 +40,19 @@ struct iort_fwnode { static LIST_HEAD(iort_fwnode_list); static DEFINE_SPINLOCK(iort_fwnode_lock); +/* + * One entry for IORT RMR. + */ +struct iort_rmr_entry { + struct list_head list; + u32 sid; + struct acpi_iort_node *smmu; + struct acpi_iort_rmr_desc *rmr_desc; + u32 flags; +}; + +static LIST_HEAD(iort_rmr_list); /* list of RMR regions from ACPI */ + /** * iort_set_fwnode() - Create iort_fwnode and use it to register * iommu data in the iort_fwnode_list @@ -393,7 +406,8 @@ static struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX || node->type == ACPI_IORT_NODE_SMMU_V3 || - node->type == ACPI_IORT_NODE_PMCG) { + node->type == ACPI_IORT_NODE_PMCG || + node->type == ACPI_IORT_NODE_RMR) { *id_out = map->output_base; return parent; } @@ -1660,6 +1674,91 @@ static void __init iort_enable_acs(struct acpi_iort_node *iort_node) #else static inline void iort_enable_acs(struct acpi_iort_node *iort_node) { } #endif +static int iort_rmr_desc_valid(struct acpi_iort_rmr_desc *desc, u32 count) +{ + int i, j; + + for (i = 0; i < count; i++) { + u64 end, start = desc[i].base_address, length = desc[i].length; + + if (!IS_ALIGNED(start, SZ_64K) || !IS_ALIGNED(length, SZ_64K)) + return -EINVAL; + + end = start + length - 1; + + /* Check for address overlap */ + for (j = i + 1; j < count; j++) { + u64 e_start = desc[j].base_address; + u64 e_end = e_start + desc[j].length - 1; + + if (start <= e_end && end >= e_start) + return -EINVAL; + } + } + + return 0; +} + +static int __init iort_parse_rmr(struct acpi_iort_node *iort_node) +{ + struct acpi_iort_node *smmu; + struct iort_rmr_entry *e; + struct acpi_iort_rmr *rmr; + struct acpi_iort_rmr_desc *rmr_desc; + u32 map_count = iort_node->mapping_count; + u32 sid; + int i, ret = 0; + + if (iort_node->type != ACPI_IORT_NODE_RMR) + return 0; + + if (!iort_node->mapping_offset || map_count != 1) { + pr_err(FW_BUG "Invalid ID mapping, skipping RMR node %p\n", + iort_node); + return -EINVAL; + } + + /* Retrieve associated smmu and stream id */ + smmu = iort_node_get_id(iort_node, &sid, 0); + if (!smmu) { + pr_err(FW_BUG "Invalid SMMU reference, skipping RMR node %p\n", + iort_node); + return -EINVAL; + } + + /* Retrieve RMR data */ + rmr = (struct acpi_iort_rmr *)iort_node->node_data; + if (!rmr->rmr_offset || !rmr->rmr_count) { + pr_err(FW_BUG "Invalid RMR descriptor array, skipping RMR node %p\n", + iort_node); + return -EINVAL; + } + + rmr_desc = ACPI_ADD_PTR(struct acpi_iort_rmr_desc, iort_node, + rmr->rmr_offset); + + ret = iort_rmr_desc_valid(rmr_desc, rmr->rmr_count); + if (ret) { + pr_err(FW_BUG "Invalid RMR descriptor[%d] for node %p, skipping...\n", + i, iort_node); + return ret; + } + + for (i = 0; i < rmr->rmr_count; i++, rmr_desc++) { + e = kmalloc(sizeof(*e), GFP_KERNEL); + if (!e) + return -ENOMEM; + + e->sid = sid; + e->smmu = smmu; + e->rmr_desc = rmr_desc; + e->flags = rmr->flags; + + list_add_tail(&e->list, &iort_rmr_list); + } + + return 0; +} static void __init iort_init_platform_devices(void) { @@ -1689,6 +1788,9 @@ static void __init iort_init_platform_devices(void) iort_enable_acs(iort_node); + if (iort_table->revision == 3) + iort_parse_rmr(iort_node); + ops = iort_get_dev_cfg(iort_node); if (ops) { fwnode = acpi_alloc_fwnode_static(); From patchwork Mon May 24 11:02:16 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: 446434 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3237772jac; Mon, 24 May 2021 04:03:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA8U2YcqrRfwnxx74IIsMpP8NBbJDkcL3v6BQRf9WiKLYkg2HRI0GfZo+lvOVV3LsN+XyV X-Received: by 2002:a17:907:980c:: with SMTP id ji12mr21946373ejc.152.1621854212892; Mon, 24 May 2021 04:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854212; cv=none; d=google.com; s=arc-20160816; b=0VSS0qN0Gif4UQRs9B9//SMdmvL1qARVnIbJs0dGU2Wg4OdCZY07WdiuFnrqaGA20J pPvnKFDMttu6+J44Ab8qHihQ/pa4QeO4bcg66fZ2GRLT6F9hdWOZzE4Tql8d2b3H6W0I 3890+gHpUZIYfFzCIFa04Et+z2LuE3aoy89vaEoPB1z5116IGxK204FyWzCx5Tt87fhu 4StcX/HPxinZeZeuKP22e7CH6qPjPbTdj3qXDb9SQMJylWwO3Q4rtkbKvmfD9QTmUVfE CUnoQvj4ii7toeifELQS3PFPtoFE9gY9iOG02RovF1od4eVAmK6E2mw0A4uXvaVpJ4ol Of2g== 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=MYjVJwbDogdtmHNT7/w2fpw8iYIwHfX6P2/1ra/LW/I=; b=fR7VecWJuPnC+h2YOo1BuCNaiCtWdlX5drlMEY++VyfPR1SWtCN56UltnfM8nXr6YV xL03XtoZOGNk8fNCUlchlueePtprKokwkqVWNN5qY4/jH2Go62wxQfZUOjFZAPGe5bwx siSiOiR+GTPx7+BC0XTmqzsB+nck05Fi3wVFutTL4xQLPkDvww1ClRhvGMATYFccRwEI e/AQhrLXg+H+8Kwx2b36IfEgftpvWxIxF95bU1UrTUYXAb9KU1Fr8RrAenqiJXM5VBJF hgR32iQu4rzESAUPQDt3FWlKBGLJ16dc3SudVNXAaDkQ4I2XhTQwCIq/Jk7YNm7neBmz xECw== 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 m5si12473319eds.484.2021.05.24.04.03.32; Mon, 24 May 2021 04:03:32 -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 S232646AbhEXLE7 (ORCPT + 4 others); Mon, 24 May 2021 07:04:59 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5532 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232574AbhEXLE6 (ORCPT ); Mon, 24 May 2021 07:04:58 -0400 Received: from dggems706-chm.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpZ4l1SlwzkYwQ; Mon, 24 May 2021 19:00:39 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems706-chm.china.huawei.com (10.3.19.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:03:28 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:03:19 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 2/8] iommu/dma: Introduce generic helper to retrieve RMR info Date: Mon, 24 May 2021 12:02:16 +0100 Message-ID: <20210524110222.2212-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Reserved Memory Regions(RMR) associated with an IOMMU can be described through ACPI IORT tables in systems with devices that require a unity mapping or bypass for those regions. Introduce a generic interface so that IOMMU drivers can retrieve and set up necessary mappings. Also introduce a union to struct iommu_resv_region to hold any firmware specific data(eg:RMR specific info). Signed-off-by: Shameer Kolothum --- drivers/iommu/dma-iommu.c | 29 +++++++++++++++++++++++++++++ include/linux/dma-iommu.h | 13 +++++++++++++ include/linux/iommu.h | 10 ++++++++++ 3 files changed, 52 insertions(+) -- 2.17.1 Reported-by: kernel test robot diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7bcdd1205535..229ec65d98be 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -174,6 +174,35 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) } EXPORT_SYMBOL(iommu_put_dma_cookie); +/** + * + * iommu_dma_get_rmrs - Retrieve Reserved Memory Regions(RMRs) associated + * with a given IOMMU + * @iommu_fwnode: fwnode associated with IOMMU + * @list: RMR list to be populated + * + */ +int iommu_dma_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list) +{ + return -EINVAL; +} +EXPORT_SYMBOL(iommu_dma_get_rmrs); + +/** + * + * iommu_dma_put_rmrs - Release Reserved Memory Regions(RMRs) associated + * with a given IOMMU + * @iommu_fwnode: fwnode associated with IOMMU + * @list: RMR list + * + */ +void iommu_dma_put_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list) +{ +} +EXPORT_SYMBOL(iommu_dma_put_rmrs); + /** * iommu_dma_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 6e75a2d689b4..a83e6c09444c 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -42,12 +42,16 @@ void iommu_dma_free_cpu_cached_iovas(unsigned int cpu, extern bool iommu_dma_forcedac; +int iommu_dma_get_rmrs(struct fwnode_handle *iommu, struct list_head *list); +void iommu_dma_put_rmrs(struct fwnode_handle *iommu, struct list_head *list); + #else /* CONFIG_IOMMU_DMA */ struct iommu_domain; struct msi_desc; struct msi_msg; struct device; +struct fwnode_handle; static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size) @@ -83,5 +87,14 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { } +int iommu_dma_get_rmrs(struct fwnode_handle *iommu, struct list_head *list) +{ + return -ENODEV; +} + +void iommu_dma_put_rmrs(struct fwnode_handle *iommu, struct list_head *list) +{ +} + #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32d448050bf7..856a1736c744 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -114,6 +114,12 @@ enum iommu_resv_type { IOMMU_RESV_SW_MSI, }; +struct iommu_iort_rmr_data { +#define IOMMU_RMR_REMAP_PERMITTED (1 << 0) + u32 flags; + u32 sid; /* Stream Id associated with RMR entry */ +}; + /** * struct iommu_resv_region - descriptor for a reserved memory region * @list: Linked list pointers @@ -121,6 +127,7 @@ enum iommu_resv_type { * @length: Length of the region in bytes * @prot: IOMMU Protection flags (READ/WRITE/...) * @type: Type of the reserved region + * @rmr: ACPI IORT RMR specific data */ struct iommu_resv_region { struct list_head list; @@ -128,6 +135,9 @@ struct iommu_resv_region { size_t length; int prot; enum iommu_resv_type type; + union { + struct iommu_iort_rmr_data rmr; + } fw_data; }; /** From patchwork Mon May 24 11:02:17 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: 446436 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3238039jac; Mon, 24 May 2021 04:03:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCefX/Zw/0F5tlXd5E8DbYnnud7aYgYqzT208rOQMKVvi8SO8a0O/9rkv0sjPNb2F+ryjw X-Received: by 2002:a05:6638:2181:: with SMTP id s1mr24681802jaj.66.1621854232611; Mon, 24 May 2021 04:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854232; cv=none; d=google.com; s=arc-20160816; b=vPBW5slgZO7sNvJbNP67rJzTYtm7LO7ap2xBtAf1l/yYaMOl8HtDT4fO7Zh8b/3XcR FYrr0yOkiBX7YZk32yrP16ihxJjNXxzaCzUXkNN55GfkLGzuAlxcGpoz0nG8sLB5TnPR ZyV3PUKeFKlNB+qiGOAUkX8zWC/Vr0zEYjdpdsbcao9Hg+tdMTfa78CM37vMz2zPdOZg 9q5tiyTQmEwTXkbepCq0EKITtucvD6BO2US62E48pDDWYoTiYXFH3fDn0M4HrWspar9h yyOotwQFJMEW/r8WOoN0V5oWIHj7tUolhXAMoFZkoc1HBaYgi/pt9CRBNRmMC3KCsZ2j sNsQ== 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=h9Lrp8CpCPAsQkb5F8WWK8/WuKqsUOIZe6owrcnue3c=; b=v5lauvmzcwSzhE6M7duFyM/RpOaasRR2rsb7IYdxkUCbVIwjOmmUTxpZqtSrCDA4wL NLfjOgBaBls6PFhXm80VHSXZsUeT6P7vsBziIf2ZsvvVpYt75H/dpqKYNef1DDLWpln+ RP0W6K9YaZCstttCuRkDdG4e47z8+eaISt1L0hsDvbZPvrF3DUfX4vq3GS/TSLWgosfF G35VQ6N10WRXtxW/i9d/CfEyhQ0RgJIHExxUX+4ZllLeZsgtuSdLWkWJewVfTAGmHVlJ maL/VN99UlGYdfflMin57MZNTN9IvIyp5BNG+ra3lhWMqHbVNBwvoq0Bsu5TDqqpYVyy A4QA== 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 f14si12766626ilj.120.2021.05.24.04.03.52; Mon, 24 May 2021 04:03:52 -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 S232513AbhEXLFT (ORCPT + 4 others); Mon, 24 May 2021 07:05:19 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:3923 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232548AbhEXLFR (ORCPT ); Mon, 24 May 2021 07:05:17 -0400 Received: from dggems704-chm.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FpZ541s5yzCx69; Mon, 24 May 2021 19:00:56 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems704-chm.china.huawei.com (10.3.19.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:03:38 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:03:28 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 3/8] ACPI/IORT: Add a helper to retrieve RMR memory regions Date: Mon, 24 May 2021 12:02:17 +0100 Message-ID: <20210524110222.2212-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 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 | 50 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/dma-iommu.c | 4 ++++ include/linux/acpi_iort.h | 7 ++++++ 3 files changed, 61 insertions(+) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index fea1ffaedf3b..01917caf58de 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,53 @@ 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; + int rmrs = 0; + + iommu = iort_get_iort_node(iommu_fwnode); + if (!iommu || list_empty(&iort_rmr_list)) + return -ENODEV; + + list_for_each_entry(e, &iort_rmr_list, list) { + int prot = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; + struct iommu_resv_region *region; + enum iommu_resv_type type; + struct acpi_iort_rmr_desc *rmr_desc; + + if (e->smmu != iommu) + continue; + + rmr_desc = e->rmr_desc; + if (e->flags & IOMMU_RMR_REMAP_PERMITTED) + type = IOMMU_RESV_DIRECT_RELAXABLE; + else + type = IOMMU_RESV_DIRECT; + + region = iommu_alloc_resv_region(rmr_desc->base_address, + rmr_desc->length, + prot, type); + if (region) { + region->fw_data.rmr.flags = e->flags; + region->fw_data.rmr.sid = e->sid; + list_add_tail(®ion->list, head); + rmrs++; + } + } + + return (rmrs == 0) ? -ENODEV : 0; +} + /** * iort_iommu_msi_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() @@ -1108,6 +1156,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 229ec65d98be..f893d460cfa4 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -185,6 +185,9 @@ EXPORT_SYMBOL(iommu_put_dma_cookie); 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); @@ -200,6 +203,7 @@ EXPORT_SYMBOL(iommu_dma_get_rmrs); void iommu_dma_put_rmrs(struct fwnode_handle *iommu_fwnode, struct list_head *list) { + generic_iommu_put_resv_regions(iommu_fwnode->dev, list); } EXPORT_SYMBOL(iommu_dma_put_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__ */ From patchwork Mon May 24 11:02:18 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: 446435 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3238031jac; Mon, 24 May 2021 04:03:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQtWH09m28yMUjj67a9JpjiYt2t3ZeXh/poMDXd5Y+SWweTjqXXEdtVPpMN32VNrkBXAqb X-Received: by 2002:a92:ca0e:: with SMTP id j14mr13427325ils.271.1621854232020; Mon, 24 May 2021 04:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854232; cv=none; d=google.com; s=arc-20160816; b=sn55pMQoeDIXYBvOogIAMSSRV5KEeNA1AkoniIBa+kXuW4Xb729b8oLttrDJ5nN+RQ C38BiAFgwIVtfOJu6amYp8tjnneIQyW/UVU+h5x/ahHdWidqbNcv8nZYIrXGSF8rcfvJ 3mV5yF6OPn9OICR/I5MvUV342iHg2c88tb/auvPnin75pM/W4aHjcovjlOALQIw3wnhQ gKIKMdx6JkCsuf88Wzqi4qUcgtSO6kL4cAMeq/52tOr385t/nmx1SU3LHFVe9sUOglNc Z2NVqODvRteJbWfFUEAeAAQq9svYXYso6hoCFgUcSmSvnXalRNZb3qHNaCi9LlVCJcKj yojw== 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=cgZpEyoKrzBJpPJaOIScjUvR5b91ohFDfmYnYin62cA=; b=m3jYrTB5Nf+XxVCEX/P8zmj91hwF/O6yuSK62GrlMxKU6Q7ADv/B/qnRYrXr7bIRbo sHe7ZysKV5CLw5gmi/prcbDuw5B/KVOr88igsiC1woxK1h41QpYardMuOOH2pWKyVaNI 7UpNg9Bez/U7RvwpWXh4G3p9FfF8hUKexnm3Zad/SDXsTJSukZemhw3e/eKjpfBBphe/ uCMOhZDJVPWKt1F5Fru+RlZXsZQ8ULMz6tNJXvlA0Uju4DAvUuMUtKLg4VDy9HkRvCSH f/P8RUtf5S+zZW6bpQniU4Da37kkuPYWrLHbQgbvnzdjvCKl8xSRCWjmB9oNs8R0atz4 hFAA== 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 f14si12766626ilj.120.2021.05.24.04.03.51; Mon, 24 May 2021 04:03:52 -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 S232666AbhEXLFS (ORCPT + 4 others); Mon, 24 May 2021 07:05:18 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:3924 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232661AbhEXLFR (ORCPT ); Mon, 24 May 2021 07:05:17 -0400 Received: from dggems701-chm.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FpZ555vJnzCx6J; Mon, 24 May 2021 19:00:57 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems701-chm.china.huawei.com (10.3.19.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:03:47 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:03:38 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 4/8] iommu/arm-smmu-v3: Introduce strtab init helper Date: Mon, 24 May 2021 12:02:18 +0100 Message-ID: <20210524110222.2212-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Introduce a helper to check the sid range and to init the l2 strtab entries(bypass). This will be useful when we have to initialize the l2 strtab with bypass for RMR SIDs. Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 28 +++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 54b2f27b81d4..754bad6092c1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2369,6 +2369,19 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) return sid < limit; } +static int arm_smmu_init_sid_strtab(struct arm_smmu_device *smmu, u32 sid) +{ + /* Check the SIDs are in range of the SMMU and our stream table */ + if (!arm_smmu_sid_in_range(smmu, sid)) + return -ERANGE; + + /* Ensure l2 strtab is initialised */ + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) + return arm_smmu_init_l2_strtab(smmu, sid); + + return 0; +} + static int arm_smmu_insert_master(struct arm_smmu_device *smmu, struct arm_smmu_master *master) { @@ -2392,20 +2405,9 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, new_stream->id = sid; new_stream->master = master; - /* - * Check the SIDs are in range of the SMMU and our stream table - */ - if (!arm_smmu_sid_in_range(smmu, sid)) { - ret = -ERANGE; + ret = arm_smmu_init_sid_strtab(smmu, sid); + if (ret) break; - } - - /* Ensure l2 strtab is initialised */ - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { - ret = arm_smmu_init_l2_strtab(smmu, sid); - if (ret) - break; - } /* Insert into SID tree */ new_node = &(smmu->streams.rb_node); From patchwork Mon May 24 11:02:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 446437 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3238200jac; Mon, 24 May 2021 04:04:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwakOs+aNJHeaOR3PLqctRWQVVRN4qf4PFWFvimzQSbzHFbl0xsQPQ/d/X91NWh9oeviqcZ X-Received: by 2002:a6b:f60e:: with SMTP id n14mr15656930ioh.179.1621854242441; Mon, 24 May 2021 04:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854242; cv=none; d=google.com; s=arc-20160816; b=n6NXGSltZLXoJhofSZ/GtrCcaNJuNJ8xEKwcF9QagvQjbREE77x76ONVP0VQlW2HIh nKKlIvgSOioWlI+7KKWgWRAv+hRa4I04++wv/L99S7DADoLHZtZlGbYoq4wFonCyDD3a yVz1/XbH4DNoRiarbgvk7BahoLFnb/UiqdPKMf+adR06D3/3lKS8gHUiJZIJTMdEPUzo 98iIQOQ/gwHpFjyXw5cS1mNtYglA6oXf2YQX1P+R58K3SjEk+z7vzOMefJAx7XDTh/nx +wGn1zRGQ6xLrjiVf46aVGXFbEE5Oap0zrupWvlbD/he4CzcyR39EMoDydRPNpbJpA8m xvNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dLcifpRbpGOOo5l2uyzsGI7847e1bclNUfLumTjbuCo=; b=IXxvrxcSNCZ+urds7MUChh6ZYk9K0zv1D0jqRSJpdyxFVuD8Z+DBVzYxnAtNcv+o6N 5TSU9UYsdJ8OTf9chWx5db3UKvA/70p846TSOpulUd/nZGpgy/RNQGlWeZDrTQAjfZwc bmZ6k+w986iAkxh02ShWBIXWw7eFnOy+AZ4PSc1rMfE/2TFR0gko2N9X6rALzwB+GRaL KDvT7fg8TzcqSzuD4Ig7+z0hu7Y2avjCdMG7npTInyiXFGc5IrWs9ph0a198K+1kutKW QimZMR3hK+weZhxpXffh0YVLoIaxrKhHxbLAnyG7y7DUhAKamUdpo99Jtgtdxb3Sr9T5 mm/g== 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 f14si12766626ilj.120.2021.05.24.04.04.02; Mon, 24 May 2021 04:04:02 -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 S232516AbhEXLF3 (ORCPT + 4 others); Mon, 24 May 2021 07:05:29 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5533 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232636AbhEXLF2 (ORCPT ); Mon, 24 May 2021 07:05:28 -0400 Received: from dggems702-chm.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpZ5K1rWszkYvj; Mon, 24 May 2021 19:01:09 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:03:58 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:03:49 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 5/8] =?utf-8?q?iommu/arm-smmu-v3=3A_Add_bypass_flag_to?= =?utf-8?b?wqBhcm1fc21tdV93cml0ZV9zdHJ0YWJfZW50KCk=?= Date: Mon, 24 May 2021 12:02:19 +0100 Message-ID: <20210524110222.2212-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org By default, disable_bypass is set and any dev without an iommu domain installs STE with CFG_ABORT during arm_smmu_init_bypass_stes(). Introduce a "bypass" flag to arm_smmu_write_strtab_ent() so that we can force it to install CFG_BYPASS STE for specific SIDs. This will be useful in follow up patch to install bypass for IORT RMR SIDs. Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 754bad6092c1..f9195b740f48 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1174,7 +1174,7 @@ static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid) } static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, - __le64 *dst) + __le64 *dst, bool bypass) { /* * This is hideously complicated, but we only really care about @@ -1245,7 +1245,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, /* Bypass/fault */ if (!smmu_domain || !(s1_cfg || s2_cfg)) { - if (!smmu_domain && disable_bypass) + if (!smmu_domain && disable_bypass && !bypass) val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); else val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); @@ -1320,7 +1320,7 @@ static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent) unsigned int i; for (i = 0; i < nent; ++i) { - arm_smmu_write_strtab_ent(NULL, -1, strtab); + arm_smmu_write_strtab_ent(NULL, -1, strtab, false); strtab += STRTAB_STE_DWORDS; } } @@ -2097,7 +2097,7 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) if (j < i) continue; - arm_smmu_write_strtab_ent(master, sid, step); + arm_smmu_write_strtab_ent(master, sid, step, false); } } From patchwork Mon May 24 11:02:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 446438 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3238367jac; Mon, 24 May 2021 04:04:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWQB8/mDfZ5xCWjOfYzzeqQ+JUVhxLlwKxlhmVZFfIzZfDOxTDfcjuI2+ADRSnIVUlo3Vf X-Received: by 2002:a05:6e02:1b87:: with SMTP id h7mr15761467ili.185.1621854252686; Mon, 24 May 2021 04:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854252; cv=none; d=google.com; s=arc-20160816; b=foVenYzZukUdqV9lVuWv40rtFdTzTeRDLY8p2NeF4rlTSB5sQdoXfzVhOMG8obsXy7 ADZNzhgf8TPO7szQDJCjySdA0jXOob/VLnXpssbWxNzETNs5QQuT5X394k2kLM0vkDSR xvdYjqBzu2ahG2ei4P4kGYz3dtsaH46OdVLqctV0adXfL0gKbKh/VPYZUREtoYLlmwUj ETD1iBVWjjyoRHKuvHURfBjl10fSvMj7QbZmqAdadMMhblRhdzH+++Qb3Ysn0mabdS8v jNWzXsp//NCSZ4+U4WjhuBi43sSmsFWJLFuDweKtq/HnmR/FKwybeZRjUUp+PAhjCXKD /4qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LuI+MqMeih6DpacXu7GHfXHm8xq2oKYMFz/gawR+j2Y=; b=ueewXdSF24eH4Y0t4vHkmvSkilmYB+8hZ+71gqdUCjIUx+rvG8grRApcobgv2gObGD e4wr2KDPKX9SD7LZBFRZ2yUnkaMXEHOecSmuvmteHeR9OkrKxwdEhU/9xku6FCy6KlLL 1N3Vj1HD7/23XWV+WVAUWJenBzjsVdT6pXWLxcsssVKPuXx6KA1iO8xITgByhOCEr5RC Fz07LiQBMmC/SH42ximfFA6KlzFJG27B7cy5Y4nSHA6f4Pp1ZlhpN8obQycYg0uGwid+ 1TL2snIKPT5nH6er4wtiGmFTuZEZVeqzEmXfFHeiz7c2RrYrSngEpVIejneSEDV8WgX3 g4mQ== 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 f14si12766626ilj.120.2021.05.24.04.04.12; Mon, 24 May 2021 04:04:12 -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 S232548AbhEXLFj (ORCPT + 4 others); Mon, 24 May 2021 07:05:39 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5750 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232547AbhEXLFi (ORCPT ); Mon, 24 May 2021 07:05:38 -0400 Received: from dggems703-chm.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FpZ4f2rBbzmknN; Mon, 24 May 2021 19:00:34 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems703-chm.china.huawei.com (10.3.19.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:04:08 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:03:59 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 6/8] iommu/arm-smmu-v3: Get associated RMR info and install Date: Mon, 24 May 2021 12:02:20 +0100 Message-ID: <20210524110222.2212-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Check if there is any RMR info associated with the devices behind the SMMUv3 and if any, install bypass STEs for them. This is to keep any ongoing traffic associated with these devices alive when we enable/reset SMMUv3 during probe(). Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index f9195b740f48..be1563e06732 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3574,6 +3574,39 @@ static void __iomem *arm_smmu_ioremap(struct device *dev, resource_size_t start, return devm_ioremap_resource(dev, &res); } +static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) +{ + struct list_head rmr_list; + struct iommu_resv_region *e; + int ret; + + INIT_LIST_HEAD(&rmr_list); + if (iommu_dma_get_rmrs(dev_fwnode(smmu->dev), &rmr_list)) + return; + + /* + * Since, we don't have a mechanism to differentiate the RMR + * SIDs that has an ongoing live stream, install bypass STEs + * for all the reported ones.  + */ + list_for_each_entry(e, &rmr_list, list) { + __le64 *step; + u32 sid = e->fw_data.rmr.sid; + + ret = arm_smmu_init_sid_strtab(smmu, sid); + if (ret) { + dev_err(smmu->dev, "RMR bypass(0x%x) failed\n", + sid); + continue; + } + + step = arm_smmu_get_step_for_sid(smmu, sid); + arm_smmu_write_strtab_ent(NULL, sid, step, true); + } + + iommu_dma_put_rmrs(dev_fwnode(smmu->dev), &rmr_list); +} + static int arm_smmu_device_probe(struct platform_device *pdev) { int irq, ret; @@ -3657,6 +3690,9 @@ static int arm_smmu_device_probe(struct platform_device *pdev) /* Record our private device structure */ platform_set_drvdata(pdev, smmu); + /* Check for RMRs and install bypass STEs if any */ + arm_smmu_rmr_install_bypass_ste(smmu); + /* Reset the device */ ret = arm_smmu_device_reset(smmu, bypass); if (ret) From patchwork Mon May 24 11:02:21 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: 446439 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3238544jac; Mon, 24 May 2021 04:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq1zxg6rxYrKptBWTbSXC0nwZPdEXHAmZlRhgpG+EX6nBdTYYri+BjVcGL/Fd7/JJ69Cfp X-Received: by 2002:a05:6638:155:: with SMTP id y21mr25544734jao.62.1621854263275; Mon, 24 May 2021 04:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854263; cv=none; d=google.com; s=arc-20160816; b=X+IcoeD6kFCxh6Mwdqsn920xvW+LEElcR8VPcN3t9L4CtBIs/x85I4E0c4r99WaFNB 92KAu1vLiz1xlz5166Gc2JqfduoIjRsKAN2LJNcVSOo5V3KAuCZnI3RUOb8f9EwAA5t1 HePjANGt3vCheRXD/h4rzoXDHbO49EZoXcBYD32m26odWp7hLSU36/MAF03dpf2d4Syx fBm5+VZry3PZ170JzbQt+3MhM4gL9i6g+Ib5dDy/MeaqhFcJ6V5ftFH/By2OAcHb5sCY HG3q9mP6UiviBbYc3ZY2y97sJpmFn1Xl1yuHzlnkDXhz761v76QSiA9gpBC1C+rYYGRz RlKA== 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=o1xF5+mQQR1ucyOgRqgImJ8CDEvHvaUpPOKiI9z+NN4=; b=pt2XcR7IPZoQk3Ro9fVCOHzCNN5xdH9CCOYNrMgTSRCR9Oe8A9gPI7e+aYu+F/DPNv /ON1iAfThxFUBxCLuZPneoaQN0CEVGJ1owMvujftx0lN8yMW49C2dQOSVV1GYpB+cPWE D/5+GrBWoC6QTWk+V5nys0cCPBGzRgpQD60qNlKsx4jJz2XyFrQ33bs6NrEPJTLaiDA8 USpsxX4N23f+XKdtTzDKy/5nFkC0XvT1y0KEcOa1jUn1uhn79cRSQEoOfz2wKunhOIkW sgUy04jbM8zeSpe0fnIPdnkj0GOjI/EXBoyFptOX4w2n2vh3h0UuBgVjK92QI/rM7Vnl bThA== 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 f14si12766626ilj.120.2021.05.24.04.04.23; Mon, 24 May 2021 04:04:23 -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 S232589AbhEXLFt (ORCPT + 4 others); Mon, 24 May 2021 07:05:49 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:3976 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232494AbhEXLFt (ORCPT ); Mon, 24 May 2021 07:05:49 -0400 Received: from dggems705-chm.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FpZ6H2Ft2zmZw3; Mon, 24 May 2021 19:01:59 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:04:18 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:04:08 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 7/8] iommu/arm-smmu: Get associated RMR info and install bypass SMR Date: Mon, 24 May 2021 12:02:21 +0100 Message-ID: <20210524110222.2212-8-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Jon Nettleton Check if there is any RMR info associated with the devices behind the SMMU and if any, install bypass SMRs for them. This is to keep any ongoing traffic associated with these devices alive when we enable/reset SMMU during probe(). Signed-off-by: Jon Nettleton Signed-off-by: Steven Price Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 6f72c4d208ca..56db3d3238fc 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -2042,6 +2042,67 @@ err_reset_platform_ops: __maybe_unused; return err; } +static void arm_smmu_rmr_install_bypass_smr(struct arm_smmu_device *smmu) +{ + struct list_head rmr_list; + struct iommu_resv_region *e; + int i, cnt = 0; + u32 smr; + u32 reg; + + INIT_LIST_HEAD(&rmr_list); + if (iommu_dma_get_rmrs(dev_fwnode(smmu->dev), &rmr_list)) + return; + + reg = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_sCR0); + + if ((reg & ARM_SMMU_sCR0_USFCFG) && !(reg & ARM_SMMU_sCR0_CLIENTPD)) { + /* + * SMMU is already enabled and disallowing bypass, so preserve + * the existing SMRs + */ + for (i = 0; i < smmu->num_mapping_groups; i++) { + smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i)); + if (!FIELD_GET(ARM_SMMU_SMR_VALID, smr)) + continue; + smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr); + smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr); + smmu->smrs[i].valid = true; + } + } + + list_for_each_entry(e, &rmr_list, list) { + u32 sid = e->fw_data.rmr.sid; + + i = arm_smmu_find_sme(smmu, sid, ~0); + if (i < 0) + continue; + if (smmu->s2crs[i].count == 0) { + smmu->smrs[i].id = sid; + smmu->smrs[i].mask = ~0; + smmu->smrs[i].valid = true; + } + smmu->s2crs[i].count++; + smmu->s2crs[i].type = S2CR_TYPE_BYPASS; + smmu->s2crs[i].privcfg = S2CR_PRIVCFG_DEFAULT; + smmu->s2crs[i].cbndx = 0xff; + + cnt++; + } + + if ((reg & ARM_SMMU_sCR0_USFCFG) && !(reg & ARM_SMMU_sCR0_CLIENTPD)) { + /* Remove the valid bit for unused SMRs */ + for (i = 0; i < smmu->num_mapping_groups; i++) { + if (smmu->s2crs[i].count == 0) + smmu->smrs[i].valid = false; + } + } + + dev_notice(smmu->dev, "\tpreserved %d boot mapping%s\n", cnt, + cnt == 1 ? "" : "s"); + iommu_dma_put_rmrs(dev_fwnode(smmu->dev), &rmr_list); +} + static int arm_smmu_device_probe(struct platform_device *pdev) { struct resource *res; @@ -2168,6 +2229,10 @@ static int arm_smmu_device_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, smmu); + + /* Check for RMRs and install bypass SMRs if any */ + arm_smmu_rmr_install_bypass_smr(smmu); + arm_smmu_device_reset(smmu); arm_smmu_test_smr_masks(smmu); From patchwork Mon May 24 11:02:22 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: 446440 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp3238693jac; Mon, 24 May 2021 04:04:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGMsM9tkJGDSmwmRSywIYZdVEf7eBEjRyuEP65cYiBOgE+uR2SQMoo95jvg5O5lhJeB/Vj X-Received: by 2002:a02:5b0a:: with SMTP id g10mr19031443jab.2.1621854274523; Mon, 24 May 2021 04:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621854274; cv=none; d=google.com; s=arc-20160816; b=K0E/r+leokEfiKS2FzE4rn2Nj/xU5iS9SdPp1px8+vLrtn297wfqHIUxjbFDbttImM 4EupbC7olIo0xxsxEUojeGCGE7B1ixQXu/CTg9/hewOzZGaiDHJQi0xu/4l5PPIl5nEV c3vwWYP7U56MzJUv2J+2pjA4N4zWqQLgUj5mj6ALpo3hTVGY9VL3cGUV+A6aAYKrh44M Rf/Jl6CWnonm0u3Qxh/DFDYaTEnk7XvWDXIeQVsr02LHfBv6hgvSDtnE3OoO/PJ/oo04 /F+kePSASpQIYagTJLo3mHOapcQg4/P8uamY7guQys6aaRdXoSEktfb47jzfq9Fp8shI VcMg== 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=Mlw12trvDarIo7h+JXOKg9VcRbXPK5wuHCykKTCEQ/0=; b=wqvDvfVjL7pFj508jVvITvKq7o5hqqF01Sr/VEcZ3msKREw4uug1Jun51iJGMv18x3 swTU7DAA9Hxfn/s7BDbzWI8aGGOGXpsrc74uboy1usjlOiOfqO20NCyryLFyR6L6AooW b1TZ7fXRoHNVlRiO0SB+epK7shWrkFIBxULjuonUSfzvIm39L1m57YzVdMS7EvQ5ZMtC w1+amzXzPZt05TO7kx+an51HOMf4zx0TFAmijLctOYzznbdVzzuaW3qBMlUN6Ux43oGl vu0ckUDAxgffo3J6pMyoWyQ1aNM/LMSDyOk1cEQg6K2pB/1JNu/zY9T+L57zC7u7gfKr Yjtw== 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 f14si12766626ilj.120.2021.05.24.04.04.34; Mon, 24 May 2021 04:04: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 S232494AbhEXLGA (ORCPT + 4 others); Mon, 24 May 2021 07:06:00 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3642 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232547AbhEXLF6 (ORCPT ); Mon, 24 May 2021 07:05:58 -0400 Received: from dggems706-chm.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpZ514N5BzNyyy; Mon, 24 May 2021 19:00:53 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems706-chm.china.huawei.com (10.3.19.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:04:28 +0800 Received: from A2006125610.china.huawei.com (10.47.80.77) 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.2176.2; Mon, 24 May 2021 12:04:18 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v5 8/8] iommu/dma: Reserve any RMR regions associated with a dev Date: Mon, 24 May 2021 12:02:22 +0100 Message-ID: <20210524110222.2212-9-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> References: <20210524110222.2212-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.77] 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Get ACPI IORT RMR regions associated with a dev reserved so that there is a unity mapping for them in SMMU. Signed-off-by: Shameer Kolothum --- drivers/iommu/dma-iommu.c | 56 +++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index f893d460cfa4..c68093f48816 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -207,22 +207,68 @@ void iommu_dma_put_rmrs(struct fwnode_handle *iommu_fwnode, } EXPORT_SYMBOL(iommu_dma_put_rmrs); +static bool iommu_dma_dev_has_rmr(struct iommu_fwspec *fwspec, + struct iommu_resv_region *e) +{ + int i; + + for (i = 0; i < fwspec->num_ids; i++) { + if (e->fw_data.rmr.sid == fwspec->ids[i]) + return true; + } + + return false; +} + +static void iommu_dma_get_rmr_resv_regions(struct device *dev, + struct list_head *list) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct list_head rmr_list; + struct iommu_resv_region *rmr, *tmp; + + INIT_LIST_HEAD(&rmr_list); + if (iommu_dma_get_rmrs(fwspec->iommu_fwnode, &rmr_list)) + return; + + if (dev_is_pci(dev)) { + struct pci_dev *pdev = to_pci_dev(dev); + struct pci_host_bridge *host = pci_find_host_bridge(pdev->bus); + + if (!host->preserve_config) + return; + } + + list_for_each_entry_safe(rmr, tmp, &rmr_list, list) { + if (!iommu_dma_dev_has_rmr(fwspec, rmr)) + continue; + + /* Remove from iommu RMR list and add to dev resv_regions */ + list_del_init(&rmr->list); + list_add_tail(&rmr->list, list); + } + + iommu_dma_put_rmrs(fwspec->iommu_fwnode, &rmr_list); +} + /** * iommu_dma_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() * @list: Reserved region list from iommu_get_resv_regions() * * IOMMU drivers can use this to implement their .get_resv_regions callback - * for general non-IOMMU-specific reservations. Currently, this covers GICv3 - * ITS region reservation on ACPI based ARM platforms that may require HW MSI - * reservation. + * for general non-IOMMU-specific reservations. Currently this covers, + * -GICv3 ITS region reservation on ACPI based ARM platforms that may + * require HW MSI reservation. + * -Any ACPI IORT RMR memory range reservations (IORT spec rev E.b) */ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) { - if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) + if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) { iort_iommu_msi_get_resv_regions(dev, list); - + iommu_dma_get_rmr_resv_regions(dev, list); + } } EXPORT_SYMBOL(iommu_dma_get_resv_regions);