From patchwork Thu Aug 5 08:07:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 492240 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55082jap; Thu, 5 Aug 2021 01:08:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLybdGkepZne6Hktkv1tuzQCTlmEQTQR8CFiawmvcMsoLtQvR5/I+qt/n+/k+ZV8K9v1nv X-Received: by 2002:a17:906:ae91:: with SMTP id md17mr3618904ejb.105.1628150927487; Thu, 05 Aug 2021 01:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150927; cv=none; d=google.com; s=arc-20160816; b=UvywgrR8eQo2Bn0HiJhF6JxjWDR3zLEVensMfrhbIhvswVUw/wyeH8uCyzeJLZsVeK 9zYmv6SgoVIGb1ppXzT8dN65aPGlOGwbJ+b8YRgNngzJRMmbVLsp91r4pEHEGjzpGtmv gtXS5mGB3KT8Cp1yaHuS6Uj2YpHkXNdJBc6hUB2uxpVAho2wazx4FmbGycMOzSLQQxwq +rzudiWOUV1E0cxCeuGEUV1nDV8pEn/ep8+fvuTr43gMQUpbsCPN1cQYsbIPfSvE9CTl 8v+oFDjUk0VxVRRPEYbSWf7zuajyq7PWJQl9bwGBhnQ66+sUKTRRURkTlVhBpOUhEaS8 8Czw== 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=maPikDJ1KzpFJLdCtXTvNMglFekOeFdBhW+rIKttjfta9QoR8e5qp5tOi2PsHYviY3 /+GeohqBJeC+pRUv3wmWVoplWd+Ds/UUj61PTEZWPivRfqSiqLsY2Fzr26zzUc3Sx4f6 gk5G82RpU5i9QCin4cAejmoJzzusH3LxFcdyM/aNUF+UPtoKculeNxm4L2R/H7Tgvgql k7tfr15/5qSEDqoP0O0UH021v4KXBgXxO2z3zU6eVxNgLB1A4mr9i03yo5+Gdcu0vYhh 6wu++9bPQG8oJ5lVfnp1nnGJKaOf/TZhQSgjdJAm/Ru1i/zZf8Y5cNfh07VZtDYr91ff Bjlw== 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 g18si5224762ejp.458.2021.08.05.01.08.47; Thu, 05 Aug 2021 01:08: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 S232418AbhHEIJA (ORCPT + 4 others); Thu, 5 Aug 2021 04:09:00 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3585 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbhHEII7 (ORCPT ); Thu, 5 Aug 2021 04:08:59 -0400 Received: from fraeml743-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLpM29jYz6F8FR; Thu, 5 Aug 2021 16:08:27 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml743-chm.china.huawei.com (10.206.15.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:08:44 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:08:37 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 1/9] iommu: Introduce a union to struct iommu_resv_region Date: Thu, 5 Aug 2021 09:07:16 +0100 Message-ID: <20210805080724.480-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 Tested-by: Steven Price 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 Thu Aug 5 08:07:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 492242 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55171jap; Thu, 5 Aug 2021 01:08:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLVO5bo1ha+s36ViuTwIl4RLmsbhf5DKrT4h5xqItB1UWzEi5QHenmhcaadNpRxKV/EPqP X-Received: by 2002:a05:6402:498:: with SMTP id k24mr5076449edv.25.1628150936209; Thu, 05 Aug 2021 01:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150936; cv=none; d=google.com; s=arc-20160816; b=CeG0sQu8zgrXgOgo5cjyeXwkh8JgmOyM96vrJ0KWd4hc5Tw2dl26s3xnAYYJa/u2B6 O9uSO6cADXeuXgaeq0hbH4NLfoP/lEj1k2zHmKRwIZp1kjW5UQME49hglb0Qo/XqUpxN 2BigkzMk2BiLCfVy01EAchUYCHDZAzpt+PdyVjb+gIl5NCYd925llIk6GlOHnBIwASuk 17cx3yyUs8Oht5Crc1WhgG6Oh58JA9cBscihUTT9yg777RBSnEtZOjHs97V8XyztT9HU 2WstdshUGB68VYJlHKo2SOYmRQHsY5SHBO7fLfMXBAePhg50NSFWmQMySfdZAQ5/uIiT rfcg== 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=I+q36jsYtrYuYJeO1H47Gcb5WsMqD7IIGdJmu6bOe0p33a5QKqPuZP+Gpx+kSFtaSd tZXKjcIf0Ja6sfCUAv4lArMvAYUt3A58juPHf1pLDWt0e2LGRggaqhgXYOBZepFu5Qv7 CKiBMEMoso8PNKYpE2Oyy7yySYqzzmPmxBTjDjgUs9lExRgJuN3kAYI3ZiNET0JDOvpy 5tAA6hQpnA3z7ojGhKjfd+qlqBbRbsRhhCSuZP3nF7667RBejyLl6XVUwusDB8HyFyk6 jKxfMzhzYjkOpvnY8yZFdsTpXF75u1JWmFferhYmdQjlcz5t9JA9pCT/RKPACLDxkMHi J+MQ== 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 g18si5224762ejp.458.2021.08.05.01.08.55; Thu, 05 Aug 2021 01:08:56 -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 S229578AbhHEIJJ (ORCPT + 4 others); Thu, 5 Aug 2021 04:09:09 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3586 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232559AbhHEIJI (ORCPT ); Thu, 5 Aug 2021 04:09:08 -0400 Received: from fraeml741-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLpX39wzz6F8FG; Thu, 5 Aug 2021 16:08:36 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml741-chm.china.huawei.com (10.206.15.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:08:53 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:08:46 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 2/9] ACPI/IORT: Add support for RMR node parsing Date: Thu, 5 Aug 2021 09:07:17 +0100 Message-ID: <20210805080724.480-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 Tested-by: Laurentiu Tudor 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 Thu Aug 5 08:07:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 492243 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55259jap; Thu, 5 Aug 2021 01:09:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZwGJ1e8JNFBFqbKZXeE3jZmFjDPhiXE07oB7PbC/2SYbVuKaXhCzSDnWDJmELVEx7tXrY X-Received: by 2002:a17:906:4943:: with SMTP id f3mr3606612ejt.102.1628150945976; Thu, 05 Aug 2021 01:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150945; cv=none; d=google.com; s=arc-20160816; b=DCcpfSj9lmTFR6V/VKxRH8ziPIae1otBg7o5P+24tEUZ8x6agc69A63oJpnnkzYT+d pULKwzCvdIzbtqbLVafRifHyvWkNt/JVw0iU1Y3KcYyH1bAI95iWOBUITLGL0Y0bppCr 5FEeKi/aLMml3O2x295j2ZD3KwgoP3KH7CoWlkqel5EC7KB97oZy5xSpByJSEosTnI/m 6/DkjIe6geIcyFt17HhnZIDv0W5w73wWgy6ixeIKJEvBgbe8t2rN9fN07iWaHYf1Pd0i 8fmc1CaN63HPngKSgDllXHkHa0+80dQ7cXcyRJn5SQzGm6m2eAsMRXn428Pr76q6hrod fdPg== 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=bjpQNZSqoh5YEE/rdYSY8FF2xUBOhS1Hvs/8cL1Fb8BAGqpuHqsqU6bNigROwgZYmx WLjTs2Hf8X+phwUOLTaKZSUrragaSx1rLhYK5axn8gA5u23Ju4i5TAjvFd7oFxcXwZwV HdVFWaWH/nEJH3AfLlecyRSUOCqt3SZv6CgBZthYz4Lkyqi2zIvnxeS+v8tuUy/EInzi 1WYMvFlimu0Mzyg71DyM4dIROfmhHn9Dml9nsNoFgAW1fTAP6Hg8e2CCGOr8OGQbA1mE CP/lCamBQTTjmugfw/3cE7RM0VbBOagUbkIv1CASYj5RxX8BFIPiJox9tRzf+X9qhN6r iECA== 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 g18si5224762ejp.458.2021.08.05.01.09.05; Thu, 05 Aug 2021 01:09:05 -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 S232700AbhHEIJS (ORCPT + 4 others); Thu, 5 Aug 2021 04:09:18 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3587 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232559AbhHEIJR (ORCPT ); Thu, 5 Aug 2021 04:09:17 -0400 Received: from fraeml739-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLpk5g0Qz6GBjV; Thu, 5 Aug 2021 16:08:46 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml739-chm.china.huawei.com (10.206.15.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:02 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:08:55 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 3/9] iommu/dma: Introduce generic helper to retrieve RMR info Date: Thu, 5 Aug 2021 09:07:18 +0100 Message-ID: <20210805080724.480-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 Thu Aug 5 08:07:19 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: 492244 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55349jap; Thu, 5 Aug 2021 01:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf6eI97V8DdkBsEJ3InTlZcTITyZvRiDIiLXLcA+R1+fEAivgaENdYdFSaXHF6m1JxxN91 X-Received: by 2002:a05:6402:1603:: with SMTP id f3mr4913683edv.274.1628150954586; Thu, 05 Aug 2021 01:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150954; cv=none; d=google.com; s=arc-20160816; b=Aio4Brv1rzeE185nX6rEoCOinCHErn/RGSB0gWmJhe5fyI1m6rIyV/JDYv81136jN9 EIDsuXqbV++qemJtif2QawvF2tWLH7nl3WOrP+Gsu4YJcP1xSTucmp2dnCZs3AlkIPQj TbdfSofARXHrbRUwFGslMvvNWnszJpgRl9IaqDDDZYvWXoVIv9N/bXccSVXn3i5i7Qfi FRZhi+qka5N5X2X/zr7gAIiY2CYn2IfYY+oUu/d1sSAvf5gLDOWLY4RL+qaccj9t8MPf URpGCIAQhb7uKqx4FaWDPO8RX6wm2EZEX/W9SBD/jY7XGITesT2qw3TebODEEuMSbqMn d5dg== 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=ayXDMnJJGq/+/JUInBU3ZZxs2g1a4iCrAa/Jbee3v3rS94ZcBVNwcn/mjmuMErK0aW 6Gud434AAnDh5Ei8dXSWE209n46uf9giRAq8S07839swRcsRSGx0if0rnLPKj7XZ3OZ5 kiHM8w9spyzCN+3Rga4YTPujqtucwKtr2P6RVLbErNNYy+tmDqshHHl0yzXcxwyu6H+9 zRiUSvtyoa7zU5Ricyq5LtIL3e9MkzVVSpyqWhaVFv1Rr2474/0BcXujc5P7rmmr55vp YViDzgMgkC9gNHE9jxIMA/5P+FqTNM1+/0j9vDqPlcuxY9Py2Mi81+MaHBqQOkie9zVT ox8g== 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 g18si5224762ejp.458.2021.08.05.01.09.14; Thu, 05 Aug 2021 01:09:14 -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 S232559AbhHEIJ1 (ORCPT + 4 others); Thu, 5 Aug 2021 04:09:27 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3588 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbhHEIJ0 (ORCPT ); Thu, 5 Aug 2021 04:09:26 -0400 Received: from fraeml740-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLpt38RLz6F8FD; Thu, 5 Aug 2021 16:08:54 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml740-chm.china.huawei.com (10.206.15.221) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:11 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:09:04 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 4/9] ACPI/IORT: Add a helper to retrieve RMR memory regions Date: Thu, 5 Aug 2021 09:07:19 +0100 Message-ID: <20210805080724.480-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 Reviewed-by: Lorenzo Pieralisi 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 Thu Aug 5 08:07:20 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: 492245 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55466jap; Thu, 5 Aug 2021 01:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybLMarx3gWhpytH6YuMv7TuunPWOhiNKQJ0CdHSi2uqPxZ2BTQ/a8S7qa+QsQtAJ7s6ahq X-Received: by 2002:a17:907:2ce7:: with SMTP id hz7mr3550483ejc.35.1628150964980; Thu, 05 Aug 2021 01:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150964; cv=none; d=google.com; s=arc-20160816; b=E5rvUZxaPQOXROceXrTwFQZIaEoxqTLY/vLyIWW1k0Wbpc62MG4+dpebdAxKwQ4UMw Qct1IoeH3aaCFi68bNUq8D8FbLy1E6BYivcRzpdX9lFCbYZyrNt9dCliOH2Gb/TUqKNe BS06RuAs+GUhw/fqkK0dKf2lZ/itUeg1oEJfM8Z6XBQtlLK7iKz4m4fpalJU2hT2FJk3 +26r75Fd4a1fnXdbayDrc6uvdCr6re0GGg94AvIIBf7apI0968eykqaRNWo1aQoZzROM smEdGNYNgUL/liD28dQHCP+cILmUAGFQ1ELo+u9hqjAF7G6Z09L1+0DAp0Wgze1L/bRV EY5Q== 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=TFlIXxrvyAFR10DoLE/xbj0hMm2KyFYC0fKgJPN6dv0=; b=UZBUIbDzB8jEfxHlOPkdVQUDIFxW9JfPlFze2T4pEejdpvCCDd3eM/TmFkFaPaZx+S WhJGHLpOpAwo31RK9JTCqlDf0Voh8YEQNQNCoYwwQIBoXMDWBFkZS/wXPsGs/quaXmvP gkuuk+EEXHZJp1nTVI1gfXV4hzLsNEUGJebu2lVVo4uF8t9q6tGlX5bv7Cl7vok8IpfC s6aR3e1K6WlpFmYwvzh1SovCFSd8m7rGOm/zdbxFVG4lwHT2ckgQ0QKFEa3clqky/mWJ 7r9wqvVk+hdkT3lGzJlnT9EI5Emm2oPvuOHFejX6qAa9fP9Tlte6fYcV7OO8ZVdkss0I RT7g== 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 g18si5224762ejp.458.2021.08.05.01.09.24; Thu, 05 Aug 2021 01:09:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbhHEIJh (ORCPT + 4 others); Thu, 5 Aug 2021 04:09:37 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3589 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233484AbhHEIJh (ORCPT ); Thu, 5 Aug 2021 04:09:37 -0400 Received: from fraeml738-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLq63Lqgz6GBpG; Thu, 5 Aug 2021 16:09:06 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml738-chm.china.huawei.com (10.206.15.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:22 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:09:14 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 5/9] iommu/arm-smmu-v3: Introduce strtab init helper Date: Thu, 5 Aug 2021 09:07:20 +0100 Message-ID: <20210805080724.480-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 235f9bdaeaf2..31940e53c675 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2518,6 +2518,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) { @@ -2541,20 +2554,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 Aug 5 08:07:21 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: 492246 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55573jap; Thu, 5 Aug 2021 01:09:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlZCfw1fSx3khcnCq9qR02gzzwuWUHxareB3lOV4iODg681l9YMyDbxI9nB7BCjsFDs8x9 X-Received: by 2002:a17:906:a04f:: with SMTP id bg15mr3668920ejb.417.1628150974485; Thu, 05 Aug 2021 01:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150974; cv=none; d=google.com; s=arc-20160816; b=C7aRcduatTMzkQkUVgl7pr31C3GJF5aJOVcDvBcv1VjCyd8H5q7ghMcjgnQ0QbM85Q OSm7Eus+wqy52pTPEKe4OwbL481Vh4BwKALhldiEPDR+bAU9Az/nwtrA/NVtMMQ8+Mvw 05D4frXSO8IHzxsmeCCoeBt6TaCXdbQM21IlT82d9xRvo4jhLOSFIvN6UQVSuVwX+LCZ gUB+PXb9QJaPxZc/zDGeW2iWMXRFYZ7WDDz1cnGzA8TVQc3BQTIyOMVjYF9qi2bdSLhc xiOJoWQF/gDfzO19727hDH1bqoWH4+yurkFlwF3Art4HTI4AZSnJQJtkhr9YNVpEtmNu lAPw== 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=P6h8VURn8a2xqvzxeDK3AvXzvUWTuF93ZASR46rodpk=; b=zebox5tWHWymWKRUkhC87Bjvg02qXifLZ3vkuDEFG2jbm6jRGDtInd6tb1+n34atUI yy3O76fF94y+BWxeRIAmPm7uzI6o8XgdY53/ALte0dKbipV4Y0vKbeO9JqCpXIIyiDpw 0MH1OtLiFSKm8ZMZgki8XZ/IvBHNHN8B1AocqaPyWsBmIrHcwXnPO8jmQLor4jcgBGJk nC0kAmsEc6KwRvf5gnD+/IDYtmtWmFwg8ad+F0SNRcyJksEC3I49pFq49ohjRpv/uGfz xJ/q6QVInaoHg+4SB7Iw3fmdIdeL2mjFWZe3+wQSRmMjWEjdCUUeFgk5Nq9DAdbdbg/f Ewuw== 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 g18si5224762ejp.458.2021.08.05.01.09.34; Thu, 05 Aug 2021 01:09:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234289AbhHEIJr (ORCPT + 4 others); Thu, 5 Aug 2021 04:09:47 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3590 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233484AbhHEIJq (ORCPT ); Thu, 5 Aug 2021 04:09:46 -0400 Received: from fraeml736-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLqG2lZkz6F8Fl; Thu, 5 Aug 2021 16:09:14 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml736-chm.china.huawei.com (10.206.15.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:31 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:09:24 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 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: Thu, 5 Aug 2021 09:07:21 +0100 Message-ID: <20210805080724.480-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 31940e53c675..85f6f1925a36 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1357,12 +1357,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; } } @@ -1390,7 +1399,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; } @@ -3042,7 +3051,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 Thu Aug 5 08:07:22 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: 492247 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55698jap; Thu, 5 Aug 2021 01:09:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyz4jnuv/MJyNm3cCAT+QxYPeVT/PhGvbO+DOzepFsxz0cstDPWjD7r3Xj0Und/faFYsHAM X-Received: by 2002:a17:906:c08e:: with SMTP id f14mr3544967ejz.380.1628150984698; Thu, 05 Aug 2021 01:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150984; cv=none; d=google.com; s=arc-20160816; b=Fk1zKUsfYDUPooKrUUyWb85MnW6fBEC53WmKly88E0ymjdMr8VZYiLGF0JLOSm+J2t swjrmLXBCioranph4aM3KqHt+Z/S6HLSPIUy4h+hvbgCU/a56jgojZ4eU+KyPErEhPyx EjzSdMc7uH50XQ/A/5RTHTv5ny4+iS0kCQRgwGvO/TdQQ2XawREl4NlSNaQUkRY7OO7Q KEX//dndvXp1oZTv6T2dwdcABHdK7rhfdyR1IbZppckZdsngUpG3q44D9uKZyqFDOCMN l2IUImGg2VrLDGDVdRk8nkEDpz0v2s4REVoy9fIpKsxtwmsH3MG7KnTwnyn8jDCdZ0/8 Zp9Q== 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=vmPoOQGyrGk1Cc+ceG1F3nkBz/lBXzH0CrZHu6Cd2nk=; b=YwEMxhoMOCUezFikga+XR4aeLv49OVlOz1/bBcWpijG9KUR7gaKOljzCG1XEFIiRYG N6IlBqTGiyozVjg6hUiTjcdstjxLAKY+BI9x4nSsxiGJUHF4buWs6mtpXN2WtfzYeqG+ 6K4/pwGD+u/6/78BrwedUmdaBxKTogRZqW0x5aSu3FxF/ytZZzhXO2Lhh7tvM+tmLgfF Qs8Z8JtPp1rRZ0IjKPqIHOuw+EZQpRpxzpnaJsSmGtgph6p4rNF7iBUcNCdtUkOAeF21 PQiDKUK65udIawXboFCymv2QYju8cW6iSiW7C7gZMD+aDAQDCeGDUhEGga/25m+sZ020 vc4A== 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 g18si5224762ejp.458.2021.08.05.01.09.44; Thu, 05 Aug 2021 01:09: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 S233484AbhHEIJ5 (ORCPT + 4 others); Thu, 5 Aug 2021 04:09:57 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3591 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235821AbhHEIJz (ORCPT ); Thu, 5 Aug 2021 04:09:55 -0400 Received: from fraeml737-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLqT3T2rz6F8Fl; Thu, 5 Aug 2021 16:09:25 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml737-chm.china.huawei.com (10.206.15.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:40 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:09:33 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 7/9] iommu/arm-smmu-v3: Get associated RMR info and install bypass STE Date: Thu, 5 Aug 2021 09:07:22 +0100 Message-ID: <20210805080724.480-8-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 85f6f1925a36..1165605d6f7a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3760,6 +3760,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; @@ -3841,6 +3869,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 Aug 5 08:07:23 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: 492248 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55766jap; Thu, 5 Aug 2021 01:09:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3+K/CuayJnE6n9YFAZCbZ167NO1OZ37/6FQKLASnzubL1jyQiwDioDvOlTQzaSMxhzKYN X-Received: by 2002:a17:906:6cb:: with SMTP id v11mr3587194ejb.482.1628150991893; Thu, 05 Aug 2021 01:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628150991; cv=none; d=google.com; s=arc-20160816; b=dhOzamIIm9o25Pf6DaBfrM1fZt6B/20+Mra6Cbhsagikcbje9jWOseErT/A9P/0XgQ dJ6+AxhxQDSZkthY+6fBvl6H0X6DtHqXqvj+tDdDj4IjuXBOGYeT9xJJIEyKoOeilAff r9rBAn/sF9/bPSMaD0Ih7WDrc+Ovb8dYdWOmlOzQXbgR383zXEC5JposT33ZINY+bQFF BvL9Jh6EQ8uqdMPG7uXgjA6Lm2O/x48Oah2VzTMKkM0noNpIOOCwZbITm3bcntHaHe85 xzdY1KotaBCgu8dT1jTjuQGF/wvie4LGWOghZzHnbyr0LXoYz13iiGEVrjUWj+CWTohP 67tA== 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=vVT//bqXaoGRfIUkJDp5nc9oPbpfPEZIwFnwMjD93ic=; b=RBZtL1RUMGctwXlRcImFl0Fp6Y3faIRxdDTaGp4VJv2QqWaf/vV1XDRnwkIErFq5Xa /K7FmxqXLue4cCS6KH/gFEv1fORJ859HlN4Ou3eryiT5MFtrBRpHvtklDBdj1EiDONhP 1va89pkZhhUzoFGL2zF0WBO9FQBak4JGDbSL1n5S/RQQYF9tKIL64HesdrmpRL6MST/v qCSlQN3HDFGWZh0ewJZiNW/J9qQY8k9Jdd6jXq7rTnZ66iaKp1KXmY7NfSXf39jkp6O3 CNbBbZYNJPpmgrlxel9op2dyOxhlNdQ79uXuDqMtm3O65TEELcnEQfUDK0oYtMh6yQYt DLhA== 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 g18si5224762ejp.458.2021.08.05.01.09.51; Thu, 05 Aug 2021 01:09: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 S236885AbhHEIKE (ORCPT + 4 others); Thu, 5 Aug 2021 04:10:04 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3592 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236658AbhHEIKE (ORCPT ); Thu, 5 Aug 2021 04:10:04 -0400 Received: from fraeml735-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLqc12HHz6F8FP; Thu, 5 Aug 2021 16:09:32 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml735-chm.china.huawei.com (10.206.15.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:49 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:09:42 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 8/9] iommu/arm-smmu: Get associated RMR info and install bypass SMR Date: Thu, 5 Aug 2021 09:07:23 +0100 Message-ID: <20210805080724.480-9-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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..315feab9e85b 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 Thu Aug 5 08:07:24 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: 492249 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp55958jap; Thu, 5 Aug 2021 01:10:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9sRDWy9DT2QYxtUqxrNaGJVVQxYKgb4SFPBml659vp/GC6zb3ztMo+LsT3udSW6kwm0f8 X-Received: by 2002:a05:6402:42c7:: with SMTP id i7mr4854729edc.161.1628151007738; Thu, 05 Aug 2021 01:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628151007; cv=none; d=google.com; s=arc-20160816; b=S33/schxWb6OGEMNdc7k7rx/CEo8rlUvSqxUns3ZR12ml8PGCOp72prP3c0szm06yZ uDTttCbkROOa20N4A41FX9pIdwznHeRcMdlV8v1aV8t4z2onFfZqB7/WjKhOPVWcOzSi goP5qA4nwB5JqCreW7xSKNe8HcR2kl/ydd64JNGqYAIOty6JgsnwyAs3l532inAl5D/6 T8TB2+5XphBa2Ap+iOYQ7D2V9C2bNoIT4txvfZe1pwLeY/l8ulAuwHCAcbUM/1AWgXrs gIRJ4LvnpXhT/os4osiNJNaDI5RZoG05WhiZ5qsBvGZtKacdXF8LQYW1LJjiDKwhMfPJ j9uw== 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=STYy2sJ7XPGDdiF5r6X6Jndg7efPvRwWirKErTlukTLbWc9fwXNGF5YI2mG8H4eZzd MtsGwGN8oHo9Dh2+ElR3qq2jWQ9WCBmR2JWYqaC/fLUd8AjNv0hVrOTF4TRkGY2yh3Et i6b5dQFdcZjh3dulBVu/r7lDLVO5yOBEpeyzCGJfnJv+cSQozkLhzaNCknGATBV39Vot BsOGegYS/7EHmZzls603KHqOPeBmoIpjSXQCwN7oGkb/yG8bzn5Vpmm9gs2xsfPoOFtp pZOfWuVnji81O0OF9z2WWUKlNuEWHzT2rWTzIdnBYOHRu4/+KFRjhpKhtvj5tsTkLTX2 Glxg== 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 zo11si4796360ejb.23.2021.08.05.01.10.07; Thu, 05 Aug 2021 01:10:07 -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 S235821AbhHEIKO (ORCPT + 4 others); Thu, 5 Aug 2021 04:10:14 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3593 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239048AbhHEIKO (ORCPT ); Thu, 5 Aug 2021 04:10:14 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GgLqp4z5jz6G9VM; Thu, 5 Aug 2021 16:09:42 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 10:09:58 +0200 Received: from A2006125610.china.huawei.com (10.47.91.4) 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; Thu, 5 Aug 2021 09:09:51 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , , , Subject: [PATCH v7 9/9] iommu/dma: Reserve any RMR regions associated with a dev Date: Thu, 5 Aug 2021 09:07:24 +0100 Message-ID: <20210805080724.480-10-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> References: <20210805080724.480-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.91.4] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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);