From patchwork Fri Jul 16 08:34:34 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: 478366 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1145969jao; Fri, 16 Jul 2021 01:34:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT/l/sCVzh0uf2Ouibgd06KeWO+/LPFOAmpUAbuN/UPw8C1vLazVB+cED8IcGj3MnzB3jW X-Received: by 2002:a05:6402:1a38:: with SMTP id be24mr12916468edb.58.1626424499414; Fri, 16 Jul 2021 01:34:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424499; cv=none; d=google.com; s=arc-20160816; b=P79KnpcqI5bRnS0tZPFwBGCtJIzeDq3clgDQhnkb0X7PT/yEIgdpAIT7IBK25wI2rg qS5kA4wnhZuroPX7h4L0XJ27GwUrkAyJqgIyAf2iFq4tE/ppMvAA6PGJDIsrbLlpNqsb Ah7kWkYZG9TjkDCKzd6o2zMBad6UwRqMNyj7hCpf81X1/TeyzYMlcsBcaCWOoW8DMN1e zrA/n6HU38OLBsuxy8uFDnEfvNym7cgOQre6TR3+z/DPuUVLjS2CS2HssjIe8bGj/lxC iRJJkHzYM//oHpx87+X23Lgj7OeZm7CAtwT3YUynzydC9jWAX4T6tRMimhT0DiKzY7Cb yzNA== 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=NGMMLDAwgjy2DHBxsNtABryITZnNnq19kNJr7Bb5FGw=; b=k0UK608RWY5QvDmnaeVWrz66zoWIcYwUIXLM+VKWXY1n04eVdsmVsZQ6qsfcP/TZNt 2ehioDl++BPycf6r2FHWCCICLoutYzSMOVYOlFV9P7fV62ogNY6Nf+0n0mWOe/Gt/Rx4 JG9/sEhxw+9Rxe2FbJ10ws2HaGfgPoBjHw4IAfQz9j0uz/BZiC02bKXVyGk5iG/W+m/d 2BXLgdve7ZbsZA1Va1z4OgWxWzM+JcHsrcVar6kvVjXqhiH2hQcVe1uDW1gRMswJUZYi ATougGyEDE7JRfysUApUQ2/gh9tc2KQzWZi86J+LeN6sxVUxn0r50BQX13B8Bi4V1EeC 7LOA== 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 g14si10518330eds.289.2021.07.16.01.34.59; Fri, 16 Jul 2021 01:34:59 -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 S237069AbhGPIhx (ORCPT + 4 others); Fri, 16 Jul 2021 04:37:53 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3418 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237805AbhGPIhw (ORCPT ); Fri, 16 Jul 2021 04:37:52 -0400 Received: from fraeml715-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR41P26f5z6D8nl; Fri, 16 Jul 2021 16:20:25 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml715-chm.china.huawei.com (10.206.15.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 16 Jul 2021 10:34:56 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:34:49 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 1/9] iommu: Introduce a union to struct iommu_resv_region Date: Fri, 16 Jul 2021 09:34:34 +0100 Message-ID: <20210716083442.1708-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 A union is introduced to struct iommu_resv_region to hold any firmware specific data. This is in preparation to add support for IORT RMR reserve regions and the union now holds the RMR specific information. Signed-off-by: Shameer Kolothum --- include/linux/iommu.h | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.17.1 diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32d448050bf7..bd0e4641c569 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -114,6 +114,13 @@ 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 */ + void *smmu; /* Associated IORT SMMU node pointer */ +}; + /** * struct iommu_resv_region - descriptor for a reserved memory region * @list: Linked list pointers @@ -121,6 +128,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 +136,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 Fri Jul 16 08:34:35 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: 478367 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146280jao; Fri, 16 Jul 2021 01:35:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwipt2WGm2C0RRt+Wdc1viEp1Tx6byoS8qzXuZjW/kOuSAI2CTMsUSxv8NFO99JeqR4f9V0 X-Received: by 2002:a05:6402:90a:: with SMTP id g10mr13054217edz.365.1626424518448; Fri, 16 Jul 2021 01:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424518; cv=none; d=google.com; s=arc-20160816; b=tq/JzC4+7tHm9hR5BPc/OXW2kgXfS7uN1OGMMlg3eTbUffLxxuAa9OxX/0Kb/T5zgF Ih+3/Zm/L9uf9oPb3o81jXqteda7oSsA0+bOoEoX/yz4dC7LjiGfUsjUAzCJvwWbv0Q8 PI4pgVHvgc1tQ+nn8D88Y8FT/pSnCx8IaPAMksBB5va4JhThgwT0agkulx3/X3O8P2Ag OeGpr+eotjk6ugHeWpd7ikB1a06hYd6lbPBGcSldOHxauNbRzPPXGx+prwqvwRm5UF2g AOdMGIUaT4SFOJDa2XGHyF4J+Nb9QJI0yFCl4Z/l9lmGKmtIYo0/KnRXa3ttzlCh7QOd Br2A== 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=p7WixM+IB58VzsxtCs5h3F46CMP9TEH9d+5dljj/Rk8=; b=dhH4vCayRj6lgzf/qC/8Ng0wTgcN1r2dRKODsATCxEzYKK65xxY0U5VrHoSw8vXwu+ eliJQSx049ddnRJU/U/KM2ZbaDqbzBgZL9Gj62WpmWXj38Rpk5JpDUQIRWhV5r7GnsmP p1R/CowtwOjGZteIDvhKocmn0eGG/6TFGYAl583TGox27p+YzXfIElYgOBB7NYmDBmsJ g4SzFEVpx3LtwnUmkSz8MoA3oQyF7pCirGV+RLhaUdlnV2jCoG0Lqw/sBAFhxnO5RMKV F2L4L7lR94IWKbC7WJanNRfOr22RZ6+keLFynEFNNbTR9Ss9Nz/g1WN+XFqnpHao7nyg JgaQ== 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 g14si10518330eds.289.2021.07.16.01.35.18; Fri, 16 Jul 2021 01:35: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 S238153AbhGPIiK (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:10 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3419 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237980AbhGPIiF (ORCPT ); Fri, 16 Jul 2021 04:38:05 -0400 Received: from fraeml710-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR48T6Jdbz6FDGr; Fri, 16 Jul 2021 16:26:33 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml710-chm.china.huawei.com (10.206.15.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 16 Jul 2021 10:35:09 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:02 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 2/9] ACPI/IORT: Add support for RMR node parsing Date: Fri, 16 Jul 2021 09:34:35 +0100 Message-ID: <20210716083442.1708-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 the associated streamid 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 | 134 +++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 3b23fb775ac4..d76ba46ebe67 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -40,6 +40,8 @@ struct iort_fwnode { static LIST_HEAD(iort_fwnode_list); static DEFINE_SPINLOCK(iort_fwnode_lock); +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 +395,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; } @@ -1566,6 +1569,134 @@ 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 void iort_rmr_desc_check_overlap(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; + + 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) + pr_err(FW_BUG "RMR descriptor[0x%llx - 0x%llx] overlaps, continue anyway\n", + start, end); + } + } +} + +static void __init iort_node_get_rmr_info(struct acpi_iort_node *iort_node) +{ + struct acpi_iort_node *smmu; + struct acpi_iort_rmr *rmr; + struct acpi_iort_rmr_desc *rmr_desc; + u32 map_count = iort_node->mapping_count; + u32 sid; + int i; + + if (!iort_node->mapping_offset || map_count != 1) { + pr_err(FW_BUG "Invalid ID mapping, skipping RMR node %p\n", + iort_node); + return; + } + + /* 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; + } + + /* 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; + } + + rmr_desc = ACPI_ADD_PTR(struct acpi_iort_rmr_desc, iort_node, + rmr->rmr_offset); + + iort_rmr_desc_check_overlap(rmr_desc, rmr->rmr_count); + + for (i = 0; i < rmr->rmr_count; i++, rmr_desc++) { + struct iommu_resv_region *region; + enum iommu_resv_type type; + int prot = IOMMU_READ | IOMMU_WRITE; + u64 addr = rmr_desc->base_address, size = rmr_desc->length; + + if (!IS_ALIGNED(addr, SZ_64K) || !IS_ALIGNED(size, SZ_64K)) { + /* PAGE align base addr and size */ + addr &= PAGE_MASK; + size = PAGE_ALIGN(size + offset_in_page(rmr_desc->base_address)); + + pr_err(FW_BUG "RMR descriptor[0x%llx - 0x%llx] not aligned to 64K, continue with [0x%llx - 0x%llx]\n", + rmr_desc->base_address, + rmr_desc->base_address + rmr_desc->length - 1, + addr, addr + size - 1); + } + if (rmr->flags & IOMMU_RMR_REMAP_PERMITTED) { + type = IOMMU_RESV_DIRECT_RELAXABLE; + /* + * Set IOMMU_CACHE as IOMMU_RESV_DIRECT_RELAXABLE is + * normally used for allocated system memory that is + * then used for device specific reserved regions. + */ + prot |= IOMMU_CACHE; + } else { + type = IOMMU_RESV_DIRECT; + /* + * Set IOMMU_MMIO as IOMMU_RESV_DIRECT is normally used + * for device memory like MSI doorbell. + */ + prot |= IOMMU_MMIO; + } + + region = iommu_alloc_resv_region(addr, size, prot, type); + if (region) { + region->fw_data.rmr.flags = rmr->flags; + region->fw_data.rmr.sid = sid; + region->fw_data.rmr.smmu = smmu; + list_add_tail(®ion->list, &iort_rmr_list); + } + } +} + +static void __init iort_parse_rmr(void) +{ + struct acpi_iort_node *iort_node, *iort_end; + struct acpi_table_iort *iort; + int i; + + if (iort_table->revision < 3) + return; + + iort = (struct acpi_table_iort *)iort_table; + + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, + iort->node_offset); + iort_end = ACPI_ADD_PTR(struct acpi_iort_node, iort, + iort_table->length); + + for (i = 0; i < iort->node_count; i++) { + if (WARN_TAINT(iort_node >= iort_end, TAINT_FIRMWARE_WORKAROUND, + "IORT node pointer overflows, bad table!\n")) + return; + + if (iort_node->type == ACPI_IORT_NODE_RMR) + iort_node_get_rmr_info(iort_node); + + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, + iort_node->length); + } +} static void __init iort_init_platform_devices(void) { @@ -1636,6 +1767,7 @@ void __init acpi_iort_init(void) } iort_init_platform_devices(); + iort_parse_rmr(); } #ifdef CONFIG_ZONE_DMA From patchwork Fri Jul 16 08:34:36 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: 478368 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146336jao; Fri, 16 Jul 2021 01:35:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwblx0bPBzkE4rpvePE+5NqY8SxAHk7C/5zarwTRmGvsKDGELwP8N2vqNHu8PbuivAGx2Mr X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr12922728edu.51.1626424522436; Fri, 16 Jul 2021 01:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424522; cv=none; d=google.com; s=arc-20160816; b=bS5ovUizZaB1hg0+X8I9yUfruy3EzvxoJcLTTd+v8Nf2zr0z+pBFJDxcbOo8WTd0be 7fTZnlWbpCB5HqKsZvaDmCOC+uNQSL0rX+gvHOiF/w1gomDdcFfP1IEnFRJN+bOHpLEJ lZ/kl32ajjRom01giV7TUiefnFbKvrp3Kp4/W4L4i77q71D8o1/85i1y4/TzbCXcupqM ENp4ASf3O9bnPzmOjX89dllg7sOsgRtBrB94uVwJenIsMIzRntw3UqdXO9zBE1qTehVh wAc+deo+1Hv3q7zkiXCL2DlslcQabTC/HKNO2bG2y/b9z73TYHGSpvIPgzF6hVpJLbEN OBvg== 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=goYH1kxTUVniKteiIS7yqNleQTw7O8pk3eq1u9rBwJ4=; b=hp7L4YzaaXp1Iji7P+6ffGLXPEp75IecYLQ0PxYmlU5nY5mOt9les4p3f9UL4a4rGk 8Qw87Esp1uQVDDeBA75QIx3rxto7QUlvN48gR4n4fxCBvD5dSAQrTegq8T+4MxGJ+oZj Nni82uo1CT54siDWBoyWjVQCLTWWltRZ+QrmBrBb3TQMoBxVAYNp/qta3uTy94XsLkHb FP4sVfjA6Q9HpVVZlTggF5hsCMm3jxGWNt9YXHdpOBdmds5S5HRLNBuuMGYcj35CMPRp zhJ5nbKysAI9woEooP+GuADeaMO07Z4RD99mgpZU/QPmODIgV/AYjTTxLJIe3+01KQNa 4qkw== 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 dd21si2610993edb.514.2021.07.16.01.35.22; Fri, 16 Jul 2021 01:35:22 -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 S238233AbhGPIiO (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:14 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3420 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238195AbhGPIiN (ORCPT ); Fri, 16 Jul 2021 04:38:13 -0400 Received: from fraeml711-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR45Z5n6pz6H7Mp; Fri, 16 Jul 2021 16:24:02 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml711-chm.china.huawei.com (10.206.15.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 16 Jul 2021 10:35:17 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:10 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 3/9] iommu/dma: Introduce generic helper to retrieve RMR info Date: Fri, 16 Jul 2021 09:34:36 +0100 Message-ID: <20210716083442.1708-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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. Signed-off-by: Shameer Kolothum --- drivers/iommu/dma-iommu.c | 29 +++++++++++++++++++++++++++++ include/linux/dma-iommu.h | 13 +++++++++++++ 2 files changed, 42 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 98ba927aee1a..2fa2445e9070 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 758ca4694257..3b7b2d096c6e 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 dma_limit) @@ -83,5 +87,14 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { } +static int iommu_dma_get_rmrs(struct fwnode_handle *iommu, struct list_head *list) +{ + return -ENODEV; +} + +static void iommu_dma_put_rmrs(struct fwnode_handle *iommu, struct list_head *list) +{ +} + #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ From patchwork Fri Jul 16 08:34:37 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: 478369 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146407jao; Fri, 16 Jul 2021 01:35:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLTb4ogRG3walZQzszDNYNVL6Elw8mJuLgyFy+mrvDWIv3dN1EZTiLAJRT+qMRsy+5bX6e X-Received: by 2002:a05:6402:22e1:: with SMTP id dn1mr13271246edb.8.1626424527546; Fri, 16 Jul 2021 01:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424527; cv=none; d=google.com; s=arc-20160816; b=JwULq+kmqLjxfhim6OjS0rUCNYBVZPZV77E069nSQ8VT5aFshOtdatCpI5kJOkTWp2 yJqAayPnpVuxtPFalUkEiQq41lA07GCoP4h0IunTAWA8HIjRaagsKFcx8uLEEp0fiGM4 wKaX6NILJDzyUkGFQ7YVD/cj6yaPfIpn9cvJx3hRpYxVl+6IrhkI9/nRQM3QALqoayvH wr+E7ML2LyFtpIqCXyLnATh3U5utkPLH4dBKqeD20+K22zMzTWmiW/lztvnna3pYj8va MILcHsCy47L16Dl+8izTnKxW4+AfCS5YbbxfQdMmegZMi1dDsqfMTJt0E1CDDEKjafAh xYUQ== 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=CO1mw1LTKtDynOloRX/raJa2H9uH2iGxS1iJ8wfXnfo=; b=T0KtsOSOo3mbFhPdMaVZpZ1oyJJUD+7YITJt2lONNiNIQivYmQhDI324O/P8Th3WzU Ivhm6zIuhIf+M4NLjPNFXsdzC3qrUjlNrr/X9UEPvtw4OHW2ceTp3En2v9bS+BlnM2Ia n3pTNNQNVku6hnKCrfrhT9BV+gAuy9nOdcHDl17kN1u4omuYiGIw8fLQipBwjndPrEOR J7mxSPJ6syXZXvSDb8GNVdO78TVRRKSvAO0VqLfwgaTOlpbaZ8/qx/s6BHsvRDL37mSK VwedVOZy+T3hwMaJvIoEldJjh1ZlcA2vYunQEmyGoliOXYamFk4M1t2476Q4yOROYsNr tIiA== 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 dd21si2610993edb.514.2021.07.16.01.35.27; Fri, 16 Jul 2021 01:35:27 -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 S238272AbhGPIiV (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:21 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3421 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237826AbhGPIiU (ORCPT ); Fri, 16 Jul 2021 04:38:20 -0400 Received: from fraeml709-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR45k30k6z6H7M0; Fri, 16 Jul 2021 16:24:10 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml709-chm.china.huawei.com (10.206.15.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 16 Jul 2021 10:35:24 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:18 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 4/9] ACPI/IORT: Add a helper to retrieve RMR memory regions Date: Fri, 16 Jul 2021 09:34:37 +0100 Message-ID: <20210716083442.1708-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 (iort_iommu_get_rmrs()) that retrieves RMR memory descriptors associated with a given IOMMU. This will be used by IOMMU drivers to setup necessary mappings. Invoke it from the generic helper iommu_dma_get_rmrs(). Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/iommu/dma-iommu.c | 4 ++++ include/linux/acpi_iort.h | 7 +++++++ 3 files changed, 49 insertions(+) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index d76ba46ebe67..3c32d62e63b6 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -809,6 +809,42 @@ static struct acpi_iort_node *iort_get_msi_resv_iommu(struct device *dev) return NULL; } +/** + * iort_iommu_get_rmrs() - Helper to retrieve RMR info associated with IOMMU + * @iommu_fwnode: fwnode for the IOMMU + * @head: RMR list head to be populated + * + * Returns: 0 on success, <0 failure. Please note, we will keep the already + * allocated RMR reserve regions in case of a kmemdup() + * failure. + */ +int iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *head) +{ + struct iommu_resv_region *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) { + struct iommu_resv_region *region; + + if (e->fw_data.rmr.smmu != iommu) + continue; + + region = kmemdup(e, sizeof(*region), GFP_KERNEL); + if (region) { + 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() @@ -1041,6 +1077,8 @@ int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) { return 0; } int iort_iommu_configure_id(struct device *dev, const u32 *input_id) { return -ENODEV; } +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 2fa2445e9070..1b6e27475279 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 f1f0842a2cb2..d8c030c103f5 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -38,6 +38,8 @@ int iort_dma_get_ranges(struct device *dev, u64 *size); int iort_iommu_configure_id(struct device *dev, const u32 *id_in); int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head); phys_addr_t acpi_iort_dma_get_max_cpu_address(void); +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) @@ -57,6 +59,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 Fri Jul 16 08:34:38 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: 478370 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146508jao; Fri, 16 Jul 2021 01:35:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWkt8uBLkkWNPpjjm2uWmHT4dHNREraSx5ltRcTq4L1JyRJP6sl+E6PH5WNbgxC2GHfAPm X-Received: by 2002:a17:906:eb99:: with SMTP id mh25mr10579715ejb.330.1626424535149; Fri, 16 Jul 2021 01:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424535; cv=none; d=google.com; s=arc-20160816; b=u+we9b2G8tvaFPRKmk7uu4XAZJW3WLH1wM1AmNVU2UXg4ZUtfCqb+UpMWv8bnviigx 37VER6ti+cWjl5C8JAIto4iyLhcccL/SzLgrsoE52LOQUsXiyVk+AF1gYBw3pkjLCmmM FVwQHgj4pHSjyMR3L7ZbRtGf/P9pVT4SVHjIBRUjaYi8Lxz1d5cWX59TlgTNTz7Vt8PF zo8QHbBez/UBSH+Amfau1SLOVswkJli9U80WBtVbgo+HA8RAqA+/7/1M7Od9t9pd0B3x rN0WpnZ7fVjmSfuKSwnhwTYFfNXR8R/lQqq/nG4og6zj9dZpr7rM1Mgq/SG3kLpF33zg O1vg== 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=qSwcNL6dPkm5TC9PatEqttzSes7BMpC3qD9LDyrO9qs=; b=TCH6CsQiuIHjpDVxNSnoLHGaItOPNO6pA583brX24TvE9pl+6jKJfo32zL2PGSHZC5 XeajmZVSKkWu9Tgsf+S+fb3I3E+reWn+q0lowY9pONkNkBJND0KSdwfjZ0bKWXgalLvm OxqtiLCGlgHVRIInW3PPc4di0qzU2ivbxrStNIiyJBHwLz6o6bi+jLn83NNCXDnQlM3g RzYjLT0Tt120FDWv6kumZhqclsi25bVWh53wmc7XWfNcoq19H1r7MXjbmC5Bvnh4IJHn AKc4R+tfsJb7ahZGyenpPRbiWMPS1JE2DHJU7x7sVjeassvSEv+3iHy+GINg5A98oyY/ M/Yw== 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 dd21si2610993edb.514.2021.07.16.01.35.34; Fri, 16 Jul 2021 01:35:35 -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 S237240AbhGPIi2 (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:28 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3422 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237055AbhGPIi2 (ORCPT ); Fri, 16 Jul 2021 04:38:28 -0400 Received: from fraeml707-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR48x1PfNz6FDCj; Fri, 16 Jul 2021 16:26:57 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml707-chm.china.huawei.com (10.206.15.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 16 Jul 2021 10:35:32 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:26 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 5/9] iommu/arm-smmu-v3: Introduce strtab init helper Date: Fri, 16 Jul 2021 09:34:38 +0100 Message-ID: <20210716083442.1708-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 dd20b01771c4..33f5556aefeb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2517,6 +2517,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) { @@ -2540,20 +2553,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 Fri Jul 16 08:34:39 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: 478371 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146629jao; Fri, 16 Jul 2021 01:35:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFMdS5acAdU7y/mC0rXHGLSAIvwQZOuuic0F0yTigCA4lIzvEZA6908U+I+77tmtaccdGZ X-Received: by 2002:a17:906:3948:: with SMTP id g8mr10396753eje.282.1626424544550; Fri, 16 Jul 2021 01:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424544; cv=none; d=google.com; s=arc-20160816; b=oJpRhU6IWn8X9lZP5NTQRh4NIIRryejRagtRzU867rVebZs1ZOiclWvkeIWI1DdWIN UoWBdvLaoVBnT18k4PFzzcdgVcr4u8RVjy04yM0VOvH73cUyMbz4Sjn8jgIyP7UZ4cC5 a3HXR5mD5axrKqpJUP7Yolp0f4t6E2hqmYcTQSalgBt9KiZm+iFtOPFhTLcd2snUq053 RkouNlThjqOoP0EvEhNIwwBUZCjGXmYmjOOWwK9aLpP03FrDzOUql8yuVz5eRffHC7vX DLykeqNKQooFtwy2EtZi2BTGAti75Crb/pAk5/smE5+LaZ7Gvuz2p/S0y0jCEioA9ZR/ zwVw== 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=e74H04M5RAXHPukqdYgNCH/LNiTSkM7YH5DGKoP2BUA=; b=DbYgq2Z7O6cNtdBmmxdJiGFSfjMtG9ZyvQ2uZ62c3LrFW7A4DYo7V6G/M/Ct976LzU pxcUfBfEJ6S88L75FcKEYOlCb87pJEbQkT+24oAd7byTayleX3B2/K7GMU1O6SFIZQO/ 54gsXuDgrQGw4asyQ2s7byURS4AKN3FEGSKZvacF7fWU4CXXn+3HqbY9H4vczYVVRlfl mJKCcAoRu26A0VH9xAVnrZO33l4VR/rAikJdO4U9h3Ix5/uDUsgGtraou8jbDoMviZvY EaKVaKy57pEhzqAG1erO/1UvlRxqiHRLB7e3iIhB4ZtcO6DOep8CmSOMDtWjWSysyy21 sHyg== 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 dd21si2610993edb.514.2021.07.16.01.35.44; Fri, 16 Jul 2021 01:35:44 -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 S237801AbhGPIii (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:38 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3423 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237055AbhGPIih (ORCPT ); Fri, 16 Jul 2021 04:38:37 -0400 Received: from fraeml708-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR42F05Bjz6D8n1; Fri, 16 Jul 2021 16:21:09 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml708-chm.china.huawei.com (10.206.15.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 16 Jul 2021 10:35:40 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:33 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 6/9] =?utf-8?q?iommu/arm-smmu-v3=3A_Refactor=C2=A0arm?= =?utf-8?q?=5Fsmmu=5Finit=5Fbypass=5Fstes=28=29_to_force_bypass?= Date: Fri, 16 Jul 2021 09:34:39 +0100 Message-ID: <20210716083442.1708-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 flag is set and any dev without an iommu domain installs STE with CFG_ABORT during arm_smmu_init_bypass_stes(). Introduce a "force" flag and move the STE update logic to arm_smmu_init_bypass_stes() 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 | 17 +++++++++++++---- 1 file changed, 13 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 33f5556aefeb..34f84641dc6a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1356,12 +1356,21 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); } -static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent) +static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent, bool force) { unsigned int i; + u64 val = STRTAB_STE_0_V; + + if (disable_bypass && !force) + 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); for (i = 0; i < nent; ++i) { - arm_smmu_write_strtab_ent(NULL, -1, strtab); + strtab[0] = cpu_to_le64(val); + strtab[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, + STRTAB_STE_1_SHCFG_INCOMING)); + strtab[2] = 0; strtab += STRTAB_STE_DWORDS; } } @@ -1389,7 +1398,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT); + arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT, false); arm_smmu_write_strtab_l1_desc(strtab, desc); return 0; } @@ -3041,7 +3050,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); cfg->strtab_base_cfg = reg; - arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents); + arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents, false); return 0; } From patchwork Fri Jul 16 08:34:40 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: 478372 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146720jao; Fri, 16 Jul 2021 01:35:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq1lH9TRXUI5v9jTPlSRUZqLiqeM1cd0X0wf6sjLL1Yxpq4XHQCnmClK4K2fVWDm4lje75 X-Received: by 2002:a50:ce51:: with SMTP id k17mr8577909edj.185.1626424551993; Fri, 16 Jul 2021 01:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424551; cv=none; d=google.com; s=arc-20160816; b=fxKDXg3ieDmqwrlc1FtiaU9aoRFyN7CVz3XiqEl7u+rfzvhGBzPOLNzDZmXGAzx3+5 jPSKyvoe2JKEJezf0u3nVPuw6mSI87mtEeNQ+6vx/X4oPfNiXvKcmm0Ss+A/DCNfazLa 0mxGP+8fiCJbQB0S1gecuFDBCLlGVepv9r4NFo9NSXBpL+83x2yk2A3EoSvZZ5jAbWZz oECYpXMatyrhLWauHHnS4eLYNQycGCEMuHwvHhEfv7QP5iMlqGKdd+h1QTMWAwtX0hJG 6r9mrTVBb+1hWDCvHzS87WGIzmo6T7av28lq3OOFNaUCJIWR5kRF2SDz3sp7kZ5UiQOo ZaOQ== 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=SPa/MsIIqR3CNMdU7wlNoY0Yj1Aejk0gseQ+DqQaZ/c=; b=sVIAabwvhuzhmbPay2y9r6T7FU77GfDfcqJBekW5KCcEO5gsUhujMeYRmGjv3kzVs0 qX9DP98hL3CxQh0+6UOdIPFXvfFtPspda7LjWmcIJm+V1fSFPwKyb+/02KdrmRyaHy5B sfqTE0zqOdZUXtFtGmaTxpBJNEm+VUXdXbydJMjtwqT6Di1cQgrbPngdn/EOUkgT2ip+ e5frFIZA7hxF7oXw2SZRxxTTvHePRj+QP23ZVQ/nr2hVL4HADcP5ovQpzBHL3qwH9frP nJ4jNjgwE5N43klV6ug+xqsdlEOQR7psSkoWroiEPl8uPut517cebk+JNm+fMwJY23a2 JzTw== 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 dd21si2610993edb.514.2021.07.16.01.35.51; Fri, 16 Jul 2021 01:35:51 -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 S237577AbhGPIip (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:45 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3424 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237055AbhGPIio (ORCPT ); Fri, 16 Jul 2021 04:38:44 -0400 Received: from fraeml706-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR42N5bQqz6D8WS; Fri, 16 Jul 2021 16:21:16 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml706-chm.china.huawei.com (10.206.15.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 16 Jul 2021 10:35:48 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:41 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 7/9] iommu/arm-smmu-v3: Get associated RMR info and install bypass STE Date: Fri, 16 Jul 2021 09:34:40 +0100 Message-ID: <20210716083442.1708-8-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 | 31 +++++++++++++++++++++ 1 file changed, 31 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 34f84641dc6a..71a682fb375b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3759,6 +3759,34 @@ 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; + + 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 SID(0x%x) bypass failed\n", + sid); + continue; + } + + step = arm_smmu_get_step_for_sid(smmu, sid); + arm_smmu_init_bypass_stes(step, 1, true); + } + + iommu_dma_put_rmrs(dev_fwnode(smmu->dev), &rmr_list); +} + static int arm_smmu_device_probe(struct platform_device *pdev) { int irq, ret; @@ -3840,6 +3868,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 Fri Jul 16 08:34:41 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: 478373 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146778jao; Fri, 16 Jul 2021 01:35:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy6xapFuvFAFyK1VcPcaZfmbArwQFnAfPT/tJWJqcYyrvtm6/ApylYFlAd/+vHISzDfctx X-Received: by 2002:a05:6402:d54:: with SMTP id ec20mr13493853edb.41.1626424559054; Fri, 16 Jul 2021 01:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424559; cv=none; d=google.com; s=arc-20160816; b=0NkPXUueETAVyHX308qkQyMQpbKl5qTIal1AoxQ9uNyyEGR/be52irEjOHj2QSCECY JaCTiaBydLhUgrhy70jQc0jFUltxTxny3ttryC16XXEoa2w1oy5Mg8FxaZB4gIgFparu Bv3FNLr/wTA+5/ZoE2hcqUc0JqVP6Z/Iu67umEg3VZBrIxRsGygkbt3pn3exQu58Y2OO fIV+83RdQ5bQ3c2YCsVcSS8ci+WOYXNkOXz/ijdDgZk4hu1K9d098QEj6qH1NL38mnnt 8IDDy6bhMDEdRZgVYDHj/eFWXTJ69N3m8ain37Ca2A8Mk4hyPceEcuGzBnNWtqFzmMxw oDAw== 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=Zewr59NfwZxooTCWnPSVVwvFIPDjWkBCXZn96QttlWM=; b=TvAUN2QvPhG4qgNXiII+weFO+OQxVytLnozpZE4DHo7pUQL743MwuXhUc6iU1BHk5v Bw4YBP/DD6xEU98OgEK169JL3YDPXYvHu7w4LUpSj3JAMGro+5Mn/aZs84XO0kkS411V 28QW46GffdoCHX/GPuPs73FkCOMh3Q739GAlAqfgRKE/ym3e0RVIsZX2JJOOb+O2eOMp METn0g77vn4lvJjHAbHThDBGEVZrFAUCIw3hqoTNO7JKZR9+/F86GaQk1WZehpCyo3YA sFwQl4aPPzuuHYQ40hxkmuTkHaVL4krLZwQNTn4AjQPz39TTmnSigani+eXp02ky7/KX Vncg== 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 dd21si2610993edb.514.2021.07.16.01.35.58; Fri, 16 Jul 2021 01:35:59 -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 S231899AbhGPIiw (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:52 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3425 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232016AbhGPIiw (ORCPT ); Fri, 16 Jul 2021 04:38:52 -0400 Received: from fraeml705-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR46K4vNgz6H7P4; Fri, 16 Jul 2021 16:24:41 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml705-chm.china.huawei.com (10.206.15.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 16 Jul 2021 10:35:55 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:49 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 8/9] iommu/arm-smmu: Get associated RMR info and install bypass SMR Date: Fri, 16 Jul 2021 09:34:41 +0100 Message-ID: <20210716083442.1708-9-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 | 48 +++++++++++++++++++++++++++ 1 file changed, 48 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 f22dbeb1e510..e9fb3d962a86 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -2063,6 +2063,50 @@ 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 reg; + + INIT_LIST_HEAD(&rmr_list); + if (iommu_dma_get_rmrs(dev_fwnode(smmu->dev), &rmr_list)) + return; + + /* + * Rather than trying to look at existing mappings that + * are setup by the firmware and then invalidate the ones + * that do no have matching RMR entries, just disable the + * SMMU until it gets enabled again in the reset routine. + */ + reg = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_sCR0); + reg &= ~ARM_SMMU_sCR0_CLIENTPD; + arm_smmu_gr0_write(smmu, ARM_SMMU_GR0_sCR0, reg); + + 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; + + cnt++; + } + + 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; @@ -2189,6 +2233,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 Fri Jul 16 08:34:42 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: 478374 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1146845jao; Fri, 16 Jul 2021 01:36:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYF4bAqdBdNxQzgXBbRsPkyp4BRLlCQAO6B9Y+xkguONfSE3KNynORkZ/U4skXyOgvkQM/ X-Received: by 2002:a17:906:f8d7:: with SMTP id lh23mr10698205ejb.485.1626424566572; Fri, 16 Jul 2021 01:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626424566; cv=none; d=google.com; s=arc-20160816; b=pjpSRWvxps5CA55V7nTTHfeTUmW8pOyccqZFr/yKlb9EVXjkkDO+nt6MTzqGnFHozQ 8/yfV4AD0x9cuJ5Mm7Aa4LZz7cIUOXaFE8ytaHiXJTTnKsNo3HDV0cgwZzJU1cOgeyFi r2i1eUCRuyOXTcTHx+QXoDAQ8M9otr12BLKZqEUAP4/nobpKn3mM5NwkumbmkrVhU8re 3w/MorKFssxYmsjiwiapsUX4P7ode7dVwY1NcURwkxJU1kvwvTJYOa7OusGyWkygRQfa PZJMsG499Td7vdGsQVjU6oVb59ak5XkyBZeulvq9IMgV4I2mI70J0626YlZe09a5N1Sw gsyw== 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=a/O879fzSLfFh5eAZx7NFXunZe21Lim+UM6IJCf/EgU=; b=svTAww9tCIIqorUfNYGZWd43iSxYYUHbEGxzCpqrRv09EjsY6zlYmJpkzj/zGei54r Yr2gbuQ8tULKyFRj5BKgKCxD6W9PSohZoUKgjdtjDoPzfywsROyaUz7a3QXdB5e+n3kA LKygH1Jyo92U/MJ4QhvkCSiN5lnQMkxgdA7NuUyKjG+Bod2VNif7/4UP6A6J+Ev0croT wvaY3x+Zi1hUTm3Hz4S6KnYTuXzJ9sXcBG9RNaYd/UXGxwoIMc2sBEIitJ99CKLf2cXL Ck1VXxyqwcqCEaNSZ5VvXezRADHpq7caC/W/Z1Aou+0TOXRf6ck1epmWYE7vMH0HLzPh DHww== 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 dd21si2610993edb.514.2021.07.16.01.36.06; Fri, 16 Jul 2021 01:36:06 -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 S237055AbhGPIi7 (ORCPT + 4 others); Fri, 16 Jul 2021 04:38:59 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3426 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232016AbhGPIi7 (ORCPT ); Fri, 16 Jul 2021 04:38:59 -0400 Received: from fraeml704-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GR46T1Xzgz6H7NP; Fri, 16 Jul 2021 16:24:49 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml704-chm.china.huawei.com (10.206.15.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 16 Jul 2021 10:36:03 +0200 Received: from A2006125610.china.huawei.com (10.47.80.222) 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; Fri, 16 Jul 2021 09:35:56 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , Subject: [PATCH v6 9/9] iommu/dma: Reserve any RMR regions associated with a dev Date: Fri, 16 Jul 2021 09:34:42 +0100 Message-ID: <20210716083442.1708-10-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> References: <20210716083442.1708-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.80.222] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 1b6e27475279..c1ae0c3d4b33 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);