From patchwork Thu May 13 13:45:43 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: 437327 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345422jao; Thu, 13 May 2021 06:46:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuor5+8o6+NpPvJKL/Zu7JXgRKANwQHzPslyi5zpNYjz4Xa7KOQBjgcjSQJzyzon7BsA9G X-Received: by 2002:a05:6e02:def:: with SMTP id m15mr36464563ilj.12.1620913607556; Thu, 13 May 2021 06:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913607; cv=none; d=google.com; s=arc-20160816; b=s50jmenZoGokiFJpkH9wAEGFBy06bAlmxc31c+2H5XkwvWTLyrU4ohRKn5N8pyWg62 qBmW7Tg/R79/zMXzvdDhM9Ev0cumAkuTlgaRzMgtKw6c6vpLRVdhO4C14QT1ysXYAJrR zMPfJXIycIsTq3Q+kYfaxWk5ri/W9+wycfm0HRvZmi0PCS8+Z7pAkFiJMGNIAE8sTz2s fFWeEiapk8CEXJ3WNdSaM0Q58cq/R/Jteile77HeT9LRIKdr++E76KY52q5j7sTelGsv SEz6Z1Wj7f+Mo0P84SNlQ20Ivpxk1dlssJC/GVLERz5eKSiCOZE3vQV+0xbXmLDE0wNa vMSQ== 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=ZCHAlG8FHv1jj0cWtbAPmfQGTskIPWvY5tiJRoxjNTwE+6UQeJF501qjv67qPlRR8x zeClhFA3X7tE9nzyHgsx4pQxaVDQfOn49e6sWhzwTqRPmzJXkPmQ08Kre0TELVX0YX5L mrNy07VoiYdSy6tgVcWcmNuNfTewhVxjrZYgmzejMn+CLHFEs0EKQB5CyruGcJpQBc7A yI7Bs4634JCUcdxFQDva2qZdWOFsdSLE9Gq8yDFbX3HLZOvPJmjsa55YkwMIDPPSmNJb 2zJmrd/DlSE0IEfznbzgRdFF+Xs7XcK3JWjRXkM4PjL5LlZSvohTBK818N9yDZKpVT/Z xn/w== 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.47; Thu, 13 May 2021 06:46:47 -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 S234136AbhEMNrz (ORCPT + 4 others); Thu, 13 May 2021 09:47:55 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2590 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234092AbhEMNru (ORCPT ); Thu, 13 May 2021 09:47:50 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FgtD400ydzsRCP; Thu, 13 May 2021 21:43:47 +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:22 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 1/8] ACPI/IORT: Add support for RMR node parsing Date: Thu, 13 May 2021 14:45:43 +0100 Message-ID: <20210513134550.2117-2-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 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 Thu May 13 13:45: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: 437328 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345433jao; Thu, 13 May 2021 06:46:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXxrwECZ9P9AoKF4z62WSll+822mdRlS9cA1V/AH+4UvqOAwMkvo3cVNjx7tfyaWZ29O8V X-Received: by 2002:a05:6e02:190a:: with SMTP id w10mr35477170ilu.1.1620913607946; Thu, 13 May 2021 06:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913607; cv=none; d=google.com; s=arc-20160816; b=z2u5BGZA5pdUG1qUcOWeRImlrEGVaafHCwOrejV33+rAYmCM+NMyfQb5tt5XwEAg6z ENOrw8vYGuGYBJgUAKz5apHwpMy7YLbugO42i+s0BoVAhh197fTwKfGQ/7O7peyuGpKt PF+phOEJRF2IGugRrvngPVQXzc3lznMC9eViAHF0YBGs57ia3XWcoUvZD46Cgw/CUoHo nS+88BsoPxz2CIY0DHc20JYqNhLlrH3vCg8+xUdzdlUNRIL9L7mzw3HRFEtXNhwQQbVb kaZxOsKTgyrYmqI1p6QOCU2pAmhhHhyvFpzD59gdaSKJVEbB7b9WfLki/RLOzW5yiihg CMIA== 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=LhC7FEfFFueMlo0Oj0z8A9hkVQlZ5ToqeydOvKY+6mU=; b=ja/ka4yGACiy/tNrPnrMOOdbFIqkY3fcD6XMwwNGGR2ia20ckGvJaSd9rQEhL30opp 5hJ0d+9kUlUFxmj7vpEECwB64G8bF4G91odrBXwQxNGgOvrZCRnWAbnrgeNrUCPSe/JB Vh49rJfUamhkBSL8whnUPN5wHuSbAsD/6qP+BSd13gZRyQP32B5ia/wHKtHZfWuVs9b8 V+7rwGWTAphNV3Cwr3ga068QPGbM6UYrtlkFe+S9wGn3kHefXD2Ejmd5PMX1LhKSNvaQ 59YK6q3NmU4P+S72tqoQLfMQexdwhKasWULOP5BmRh5HrymOyXvoz5TRRDTAKWlCzorC JlCg== 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.47; Thu, 13 May 2021 06:46:47 -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 S234092AbhEMNr4 (ORCPT + 4 others); Thu, 13 May 2021 09:47:56 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2723 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234155AbhEMNru (ORCPT ); Thu, 13 May 2021 09:47:50 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FgtD86xGHz16Njp; Thu, 13 May 2021 21:43:52 +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:27 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 2/8] iommu/dma: Introduce generic helper to retrieve RMR info Date: Thu, 13 May 2021 14:45:44 +0100 Message-ID: <20210513134550.2117-3-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 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. Signed-off-by: Shameer Kolothum --- drivers/iommu/dma-iommu.c | 33 +++++++++++++++++++++++++++++++++ include/linux/dma-iommu.h | 10 ++++++++++ include/linux/iommu.h | 19 +++++++++++++++++++ 3 files changed, 62 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7bcdd1205535..674bd8815159 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -193,6 +193,39 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) } EXPORT_SYMBOL(iommu_dma_get_resv_regions); +/** + * 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); + +struct iommu_rmr *iommu_dma_alloc_rmr(u64 base, u64 length, u32 sid, + u32 flags) +{ + struct iommu_rmr *rmr; + + rmr = kzalloc(sizeof(*rmr), GFP_KERNEL); + if (!rmr) + return NULL; + + INIT_LIST_HEAD(&rmr->list); + rmr->base_address = base; + rmr->length = length; + rmr->sid = sid; + rmr->flags = flags; + + return rmr; +} +EXPORT_SYMBOL(iommu_dma_alloc_rmr); + static int cookie_init_hw_msi_region(struct iommu_dma_cookie *cookie, phys_addr_t start, phys_addr_t end) { diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 6e75a2d689b4..319f332c279f 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -42,12 +42,17 @@ 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); +struct iommu_rmr *iommu_dma_alloc_rmr(u64 base, u64 length, u32 sid, u32 flags); + #else /* CONFIG_IOMMU_DMA */ struct iommu_domain; struct msi_desc; struct msi_msg; struct device; +struct fwnode_handle; +struct iommu_rmr; static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size) @@ -83,5 +88,10 @@ 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; +} + #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32d448050bf7..73cd2831cb45 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -555,6 +555,25 @@ struct iommu_sva { struct device *dev; }; +/** + * struct iommu_rmr - Reserved Memory Region details per IOMMU + * @list: Linked list pointers to hold RMR region info + * @base_address: base address of Reserved Memory Region + * @length: length of memory region + * @sid: associated stream id + * @flags: flags that apply to the RMR node + */ +struct iommu_rmr { + struct list_head list; + phys_addr_t base_address; + u64 length; + u32 sid; + u32 flags; +}; + +/* RMR Remap permitted */ +#define IOMMU_RMR_REMAP_PERMITTED (1 << 0) + int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, const struct iommu_ops *ops); void iommu_fwspec_free(struct device *dev); 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__ */ From patchwork Thu May 13 13:45:46 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: 437330 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345499jao; Thu, 13 May 2021 06:46:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycciX4FeaXPhLA/m3UYmbYSuFuTrKnIQ+FBFPGkiisizaMcmXJcjbL4s8BXA8sYfPbj4x4 X-Received: by 2002:a5d:87c4:: with SMTP id q4mr29137541ios.141.1620913612173; Thu, 13 May 2021 06:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913612; cv=none; d=google.com; s=arc-20160816; b=m4jJMnJOeTOqJd67VWWCneTp3KnTTtnPUdgFl4UJHkNO5zWS7eP5N1yRH6qWklFjad 48XOHkwJL5E6czu6Jp6QrI4hMhPaaJV4+Zmej9CZHakalGRqNmi9HX2fL5y+ktvzkmjY 7Y4fkRTKhPY5TUVDsRMnud/dhTMLC0eXnjVxFO/Pz3HNQQoHar5ZppPtL8xvSZc78rQo ztHx4aoqed5bwiDTs9fiTB1IXq4ha2WBS+OvA6/RAm4do5nglyaVnr8Cy1RI3J8ymskN hdVOcgyUP+/d6EhGAR/Lc+0nvFGX0bFas7UJecvZKdLLtsR0Ab+Hcgd4YbL+MYsNcg1t R/oA== 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=M1sNWRMFYwiq8WEv5Rax6XCvPR0lWJWJ9Dj2hUcE8jTY47962DYJmlfp6/8I7lG+6T 3UUL88DgKL9Tpgc0CJBnZN0/iNfOL/HPIjz7plD5KMA05s1I+NMMWcKTi2HbjQzhUmF7 2xl2cdxBAHnpG0YjqUY/tDyt3qo3RB9YCOwl3XAwy817+GN412mCPxnosHYhFtR8ijsm rjbn81Hiw6U1KtMS+i69khHG5P4aWMqHYIiDsVNjGSDkhpni+SCG/tEYRTwG/MOvdYvI O6LnabrvERxfhrELkFBboNF8UsAfyq/MFtSl5h/5+D9k3QJszFE2dTilVB3t+OXhUWOZ sJDA== 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.52; Thu, 13 May 2021 06:46: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 S234024AbhEMNsA (ORCPT + 4 others); Thu, 13 May 2021 09:48:00 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2592 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbhEMNr7 (ORCPT ); Thu, 13 May 2021 09:47:59 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FgtDS1vrVzsRJ1; Thu, 13 May 2021 21:44:08 +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:40 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 4/8] iommu/arm-smmu-v3: Introduce strtab init helper Date: Thu, 13 May 2021 14:45:46 +0100 Message-ID: <20210513134550.2117-5-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 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 Thu May 13 13:45:47 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: 437331 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345692jao; Thu, 13 May 2021 06:47:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzstexDQVYQNIJ6GyxpTeMBuq+3jSRP0FkmGL7X2i1k6eAt+Ldyn1fUzbLflYtEBQmWHE7H X-Received: by 2002:a05:6e02:12:: with SMTP id h18mr37230377ilr.246.1620913624419; Thu, 13 May 2021 06:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913624; cv=none; d=google.com; s=arc-20160816; b=R3FAZFslEeHmziQWeoI2wY/KJaojh75fnjyX5Mg2aGFBIlsmFFEsZowbzOXBlzykOy APq5TUPnNkbk3y2UwsIEAe6pf6ce6LT/Aby9unarnHlpukGD/cq8m7pgjzS3kmfox+3P PdJiz2qzAwr1XB+PjSkvJTdTRKUCIr6pjM3uDYZMEcb3OucK894TE69nosQ3eyJArUcB 7/EfTipsMiOXJwIzbXO7URM4kTkTKXGYpNkPrinVdTLeQZqJMQXULBOGlGnhjkgGDnPb kssHhOQy3p7X2lbBLLxUj+SbRRaHF/tDX5RpoMiSExEXG8q3hg3+uq2VG/7XNBGN3D5m WCMA== 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=a7rUP8EZD4kn4bs5B3fb3lZIrmTkqLvYGcEu0EqwQssSaZJ5Ir+Fb3bNAI4ibno0/u 4+9QKqEKjXYTwvjL7R7lCsn/IKf2HbS5+96avvp6oCZVvtStb+G8cgwOnbY6+oG7RzUz dgseErZNaMn61FXmdQRHt2T5UkA0P783IQtO7ERTrNSL9zusTmLJWVtRGij+S81rgDMY vQhL6oEhfJZcUpXZ1TURIyiLbbboNpvzAnC8snCzMAHk0LMcaYwWl2OD9zeM2QuFbcwn 23TYI6eqbwNIxZu32Xpi917RmgKGheUvSdIrg2ZenX6wM2708YaT9moW5UF6fjUgB9nX b15w== 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.47.04; Thu, 13 May 2021 06:47:04 -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 S234135AbhEMNsK (ORCPT + 4 others); Thu, 13 May 2021 09:48:10 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2724 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234047AbhEMNsF (ORCPT ); Thu, 13 May 2021 09:48:05 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FgtDY1Rg6z16LjG; Thu, 13 May 2021 21:44:13 +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:47 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 5/8] =?utf-8?q?iommu/arm-smmu-v3=3A_Add_bypass_flag_to?= =?utf-8?b?wqBhcm1fc21tdV93cml0ZV9zdHJ0YWJfZW50KCk=?= Date: Thu, 13 May 2021 14:45:47 +0100 Message-ID: <20210513134550.2117-6-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 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 Thu May 13 13:45:48 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: 437333 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345881jao; Thu, 13 May 2021 06:47:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4kzUoTWEdpIcjhuHBegzu/2X+mvcuJye1v1eQxuNWVpah0inFOX3rXWP47SUh4kLLvG4L X-Received: by 2002:a05:6e02:def:: with SMTP id m15mr36466735ilj.12.1620913638577; Thu, 13 May 2021 06:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913638; cv=none; d=google.com; s=arc-20160816; b=zu1A/R0oAKJaFBIXhhnF5mSF5T4zmzHrUCyicTXBzIgdB/gof5JiNuc9waK+3Ub4Kp nucWZLlJeTbmLpt7VBv6m+UE1lPIb7gEUmSf/OH+VwQjdDfLrLmk5x1a0TOIr+xVhfP+ TyQza4Swx9lRaUCZFUseXabpI9sIhJVaU2wHSuCg51h9fhSm9R3RawiWQThAXbrZz7iC jVpiTym7jqX30Yh8DeSsHwf7j+TzMqj3LGORWeTu8Jgy7zdjBj/IKgX0d7AASUzBwA4E akC7AjtLbAfePqXm+EEamBQfqritz/+Pp2uq1Doc+hW/5dBjI7M1CW0XqerHwaxGXUm5 AWBQ== 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=HUs4bEs0y+tVO2fn4aNgkcaN6iDPbWkCUaMjNpHfvGU=; b=0ewN4VqonLzCMPBMxfmif5eZhyORVcJS5LtF2xuMvbjgW78qtXNfunZEFbDWtJblz0 mUgQ/BvNZLWeEQSeWtLALkIVApTyTjAt9BzlTQOJhmw2vZjwCl5nOX0hb8HrIRdsll2p CorXGEgfp7V7BKG4mG5cX+L1EnZCSyzkd9BNwd29MHcl5pnm8IzvTclqGsI35T2qGk2c Q87t2QNY2KSwP3OFrksICLvXnV1G6cfdDIjubNLfGDB1Y6IVLrC4tmF+KURbR2vOIpBi 1yKCi4/PYRDh12MtyzwWkRTUGQ0gIGuYqWNJgVzf0fLEpsy9CISR82a0u8602qwZkcOS WBEw== 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.47.18; Thu, 13 May 2021 06:47:18 -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 S234163AbhEMNs0 (ORCPT + 4 others); Thu, 13 May 2021 09:48:26 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:2478 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234168AbhEMNsQ (ORCPT ); Thu, 13 May 2021 09:48:16 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FgtDk5dkhzBvBf; Thu, 13 May 2021 21:44:22 +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:54 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 6/8] iommu/arm-smmu-v3: Get associated RMR info and install bypass STE Date: Thu, 13 May 2021 14:45:48 +0100 Message-ID: <20210513134550.2117-7-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 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 | 33 +++++++++++++++++++++ 1 file changed, 33 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..c2d2e65b9856 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,36 @@ 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_rmr *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; + + ret = arm_smmu_init_sid_strtab(smmu, e->sid); + if (ret) { + dev_err(smmu->dev, "RMR bypass(0x%x) failed\n", + e->sid); + continue; + } + + step = arm_smmu_get_step_for_sid(smmu, e->sid); + arm_smmu_write_strtab_ent(NULL, e->sid, step, true); + } +} + static int arm_smmu_device_probe(struct platform_device *pdev) { int irq, ret; @@ -3657,6 +3687,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 Thu May 13 13:45:49 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: 437335 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345900jao; Thu, 13 May 2021 06:47:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2N7dEDclhD/tUbyYzIx5d0wfczG7QjS5jCU4ZmMw3E7GWRbfzPcdgGcdvWn3bB/VTwegh X-Received: by 2002:a02:ca4e:: with SMTP id i14mr37179398jal.101.1620913639482; Thu, 13 May 2021 06:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913639; cv=none; d=google.com; s=arc-20160816; b=oCjzE9kOZVSjzrJExHaChrALO9/LlPV0GUurSGZRYC4En/dbTFu5QKoSdqfEiR1NxT +zQMqi2rS4AgebbWIQDAukZx43gQQrSEimUu9uhzfr7etvd+f8eNZueak8V1rNf2ZHsy 0efbEV0UWgJ3AeneI7b59iFkM85F4tSkhLwQsIX6LBFu3alDjy55xaPtKJf8zuEy9YWZ wFOba9+QPOZ6VjwpUVXC1ARIxqEvd0E6Cz+YHkb2kUFQ+ERCz+MXhbLQJO7WapuRl/un zamcNiNLkfXHqBPSWXcrMK1Zot8F4cf/seBM4lmqHi3R7dHCSH7yrHxVj4LJG3EJQ4gj BtIA== 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=k7TBxndOq3P82CKhRZWzSpMYeverR0fe7cMObPgMk9U=; b=J5U+sIGAjY57bG3SlWxWtaZJQay1tkirJq2nVsY4m3tSeRKBV/H9AKe9D//z/kjoSJ 8ETsP5NWAKbgKHjM5ZHijGtDL8exbKAv+5MUuYWEWP887jCaV+GhZSg5VnAhqgrwz0WB k+jAkFy6isN/Wgt1MC9bDq4yi72Mg6d7+Qjd7iXrWcVY3vm+Lid/T/uMEEQ1pwdPVSGc SQism1CQq9L4XvGRlvCYTWqkgUWmd2EFcpdt7bS2jnXI1/EzMYxjQh9Y+PRqBvRhE5CG DbFbRtCHxgmnq5c0QmaQDp+AZ+Db3aT1yMet1iFB3UEwuc6zDk4iRUSP/mZo0vJbQ0Xa 3+Gw== 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.47.19; Thu, 13 May 2021 06:47:19 -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 S234123AbhEMNs1 (ORCPT + 4 others); Thu, 13 May 2021 09:48:27 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2725 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234047AbhEMNsU (ORCPT ); Thu, 13 May 2021 09:48:20 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FgtDr3ZHYz16PgN; Thu, 13 May 2021 21:44:28 +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:47:00 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 7/8] iommu/arm-smmu: Get associated RMR info and install bypass SMR Date: Thu, 13 May 2021 14:45:49 +0100 Message-ID: <20210513134550.2117-8-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 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 | 64 +++++++++++++++++++++++++++ 1 file changed, 64 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..f67aeb30b5ef 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -2042,6 +2042,66 @@ 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_rmr *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->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"); +} + static int arm_smmu_device_probe(struct platform_device *pdev) { struct resource *res; @@ -2168,6 +2228,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 Thu May 13 13:45:50 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: 437334 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp345906jao; Thu, 13 May 2021 06:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLt5xj5u92E5u0Ja6oh+t0F9sXVWtO8UAslyt3dWn4jYQoZYHfIKXc5eXY+gqU4lB+MkzC X-Received: by 2002:a92:d486:: with SMTP id p6mr29793131ilg.235.1620913640063; Thu, 13 May 2021 06:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620913640; cv=none; d=google.com; s=arc-20160816; b=a0Bt6Jp3bBT4gQcAR3OhEK/Qhl1OTEAupogcKkm/hzi5oVRxrazR70xeyKvCUr+B39 C2wcqP1O2RcEWticMbDruqDKlz0/VWgsCDjkPnXKUBuYV69Ukmc8eVIurgo2ByGorpoF G0QUT9zPvVXZd/PEpXTYQ7UyMDBv7G8Fcbo8oRwa0l9YyPHYykELzohRUO2DT90IW6uB qCQOnU/tr3f2Ew4Py4YaNeR5BBgiDSm5kC23ZIJ76cBuK9/3zkfE13sErrryPTuFBpSM Q2iObiBP7IczyuYxtX4oBE4BdhFddEGYK2mzu9mEe2Ad1j0SlHwjHwcBFctIKum9BwHL Kq4w== 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=npxOUUA+qAqRTzOee+vFMD+o6lO24I1Xwq3hH7pZ1EU=; b=w8ppy3J6+43lXb+dV3sfLTawO+WR7l2oGcvTH7PfHb1EWqAxUg8KxkefzzQgapvUSa Xe2uEBqQL05s4iN5Xf5mWeOcswQ08RmkY40wk3DAxuYMFww+O9FZHcQJSQoTGL+QSgSg 85N7K8K9qMpEyTtCqIR4Ht0qRen8BfnQ1YH0Qzjy9CFGDdU9kXBYw4XlPZ2DTr8u2f4W 1th0ioRfgflyOJURXxHodMDr42rVEyOwayMrzECopKWlYJtgB2w91o/sjw6cHNjwF6RC khaL5BS2+jmLhmXigjl0gh3q16NMyCU/WLqvV2E3BVPH9dxnzf89c+SfwuDJGuWyQfnt 6ReQ== 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.47.19; Thu, 13 May 2021 06:47:20 -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 S234047AbhEMNs2 (ORCPT + 4 others); Thu, 13 May 2021 09:48:28 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3749 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234160AbhEMNsZ (ORCPT ); Thu, 13 May 2021 09:48:25 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FgtD70GSdzqSrx; Thu, 13 May 2021 21:43:51 +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:47:06 +0800 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v4 8/8] iommu/dma: Reserve any RMR regions associated with a dev Date: Thu, 13 May 2021 14:45:50 +0100 Message-ID: <20210513134550.2117-9-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 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 | 66 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 2d9caf548a32..6838caf3e8ff 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -174,22 +174,78 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) } EXPORT_SYMBOL(iommu_put_dma_cookie); +static bool iommu_dma_dev_has_rmr(struct iommu_fwspec *fwspec, + struct iommu_rmr *e) +{ + int i; + + for (i = 0; i < fwspec->num_ids; i++) { + if (e->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_rmr *rmr; + + 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(rmr, &rmr_list, list) { + int prot = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; + struct iommu_resv_region *region; + enum iommu_resv_type type; + + if (!iommu_dma_dev_has_rmr(fwspec, rmr)) + continue; + + if (rmr->flags & IOMMU_RMR_REMAP_PERMITTED) + type = IOMMU_RESV_DIRECT_RELAXABLE; + else + type = IOMMU_RESV_DIRECT; + + region = iommu_alloc_resv_region(rmr->base_address, + rmr->length, prot, + type); + if (!region) + return; + + list_add_tail(®ion->list, 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);