From patchwork Thu Nov 19 12:11:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328399 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361460ils; Thu, 19 Nov 2020 04:13:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1clAS7XApZdbjVPJRHBGw2uxo0QG7zJG3tk545XPnq01MOv3MCXHu8t0gG7FoBVOEJ4xR X-Received: by 2002:a17:906:7f19:: with SMTP id d25mr10436685ejr.0.1605788030721; Thu, 19 Nov 2020 04:13:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788030; cv=none; d=google.com; s=arc-20160816; b=eOoRcnPdSM5hTyySwVY/6HAhDlEYDF590GBnonCZMM62Sxp+aNfY5MjJcx1DwxHiOG WtPb4ElvNWr37ARHCQ/nZac49c5pLyZAGjpxTrVnuJVqCdL87Yw/E/I7iivt4x4c8F10 7grqRkBTBhnYvY/HEs9FKs9/ep6j5ZLrefoIxcE5beK+A9DrR7rmryDp/T7HoqDtxZtU pziirQ5UvPHlvLuFcmyMdbK2x3FUckTcuNH3AxEKUZGGQZ2akF6gMCgdJ+iZCRy7J4zz vHQSLVc+0lch/uXl7Mb5HGHCXNe3DivPL+/g6p5lLB4OaYJXZwb/dIGfQCR7sLk4xT8b 7n7w== 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=aaf/G6l8tKSjeTfUqYOgNGT551bxUYkcwq7T/2D1kqU=; b=RIglt9U7FgniWAwF0ldaTt6S4VmcJhoXql7yg9tSsi9BjPHxU/qIKoAqwF5LS8e2AW AE4mC/vg4ttVrH28scl5y632hYH2G0bsLfmdTdqUv69HdLbFJNyfuESkplQM15jZxGSj cW303in/teQ9AIGka8LsHjbdXWripK1AalXkbXnRLQ7jd4/1r0fWfKbsu9kzRO2/n1fE tyc/wKtvvC6UIjBV2KoOrqrSU7oFxmPn+ybfqJ5yMAdBnhGkm3yz+ws3rfoTfrvx2xnS 640ZQXWyD9TIwfiEHUkCVDv5Gx7tUCfR95yNqOrtxJuet4sM3+hoEJilLOpijvgnyQzM YyzQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.50; Thu, 19 Nov 2020 04:13:50 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727118AbgKSMMh (ORCPT + 5 others); Thu, 19 Nov 2020 07:12:37 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:7563 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbgKSMMh (ORCPT ); Thu, 19 Nov 2020 07:12:37 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcJTJ31GlzhXkw; Thu, 19 Nov 2020 20:12:20 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:26 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 1/8] ACPICA: IORT: Update for revision E Date: Thu, 19 Nov 2020 12:11:43 +0000 Message-ID: <20201119121150.3316-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org IORT revision E contains a few additions like,     -Added an identifier field in the node descriptors to aid table      cross-referencing.     -Introduced the Reserved Memory Range(RMR) node. This is used     to describe memory ranges that are used by endpoints and requires     a unity mapping in SMMU. -Introduced a flag in the RC node to express support for PRI. Signed-off-by: Shameer Kolothum --- include/acpi/actbl2.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index ec66779cb193..274fce7b5c01 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -68,7 +68,7 @@ * IORT - IO Remapping Table * * Conforms to "IO Remapping Table System Software on ARM Platforms", - * Document number: ARM DEN 0049D, March 2018 + * Document number: ARM DEN 0049E, June 2020 * ******************************************************************************/ @@ -86,7 +86,8 @@ struct acpi_iort_node { u8 type; u16 length; u8 revision; - u32 reserved; + u16 reserved; + u16 identifier; u32 mapping_count; u32 mapping_offset; char node_data[1]; @@ -100,7 +101,8 @@ enum acpi_iort_node_type { ACPI_IORT_NODE_PCI_ROOT_COMPLEX = 0x02, ACPI_IORT_NODE_SMMU = 0x03, ACPI_IORT_NODE_SMMU_V3 = 0x04, - ACPI_IORT_NODE_PMCG = 0x05 + ACPI_IORT_NODE_PMCG = 0x05, + ACPI_IORT_NODE_RMR = 0x06, }; struct acpi_iort_id_mapping { @@ -167,10 +169,10 @@ struct acpi_iort_root_complex { u8 reserved[3]; /* Reserved, must be zero */ }; -/* Values for ats_attribute field above */ +/* Masks for ats_attribute field above */ -#define ACPI_IORT_ATS_SUPPORTED 0x00000001 /* The root complex supports ATS */ -#define ACPI_IORT_ATS_UNSUPPORTED 0x00000000 /* The root complex doesn't support ATS */ +#define ACPI_IORT_ATS_SUPPORTED (1) /* The root complex supports ATS */ +#define ACPI_IORT_PRI_SUPPORTED (1<<1) /* The root complex supports PRI */ struct acpi_iort_smmu { u64 base_address; /* SMMU base address */ @@ -241,6 +243,17 @@ struct acpi_iort_pmcg { u64 page1_base_address; }; +struct acpi_iort_rmr { + u32 rmr_count; + u32 rmr_offset; +}; + +struct acpi_iort_rmr_desc { + u64 base_address; + u64 length; + u32 reserved; +}; + /******************************************************************************* * * IVRS - I/O Virtualization Reporting Structure From patchwork Thu Nov 19 12:11:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328401 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361480ils; Thu, 19 Nov 2020 04:13:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPIXGzXc/pUHLB/Lu8dairRuF825+Moff/9LDgYDIAcb4kr2A13CtQCYoxxGZxk80wJgN5 X-Received: by 2002:a05:6402:14cf:: with SMTP id f15mr29803203edx.18.1605788031785; Thu, 19 Nov 2020 04:13:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788031; cv=none; d=google.com; s=arc-20160816; b=AzGKyEYywU33hxuze3+R5Ev5Weul8FAqBmkVJ0lzBaJ7SjomHg8hGqefh3+gr3VYCy DY7VU89nKB4uTt6ykhOMvssuvwZzpe7toa6jXHdXBbY5dJrF6eUe2DIT3sHsLxFYC1tE o49deVveWNFY3sIxeX7ljN0vmm3nJVm6PqW8nFPe0DTgZR7u03GcdXiNjWe1b0T3JRTa xk9uUYcSsQtiNtPF4bIPHPNUMnt3YcMRMZVXsklifif5zzRfG4P/3kWuKUWCvd5Tvqyk GVpF7WUvLEq4y5W34pEv875QEWKiTjL8oo9qNp7ZqFBbalhUYZaM+4iNjCbKzgB5lgir LGFQ== 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=qma9EmGJanhEMidTo22Oa2pciz5Y3GPxkmcWGw8wP2Y=; b=rg+iwYwxL3JgpsSb6yP0qVEw1AL37s0rrrhVmiw/3ngc8YNne1LKvGZXI06Crz8Se6 Dq2nT1hqnva7juARbrPxjm6RCYmEFVDoZMEp3Mt1fMJRTZKAE3QTuRbtumKwqtl9vRfU Nh7nmKAyONEm1m+NnEMB02ixlyKPxDBgPa+ASVdP8Ckx7S3lCa4AQngDdnXjC94ijHcv 2fu7EylQH3hDlVGVGVFWp5ygYxXgv8KXeBU8Q7N43VGCjFGm0qPi8ekQSiJ3KeS5LasB AxfU5zEgvXfs6saKIVJNtmGffgIrkKRrjdzBT5TasVriZz+QDg98oEdW1X4Zu8D6D5K7 BTrw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.51; Thu, 19 Nov 2020 04:13:51 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727252AbgKSMMm (ORCPT + 5 others); Thu, 19 Nov 2020 07:12:42 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8119 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbgKSMMm (ORCPT ); Thu, 19 Nov 2020 07:12:42 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcJTJ1kRJzLqQB; Thu, 19 Nov 2020 20:12:20 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:32 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 2/8] ACPI/IORT: Add support for RMR node parsing Date: Thu, 19 Nov 2020 12:11:44 +0000 Message-ID: <20201119121150.3316-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add support for parsing RMR node information from ACPI. Find associated stream ids 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 | 122 +++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 9929ff50c0c0..a9705aa35028 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -40,6 +40,25 @@ struct iort_fwnode { static LIST_HEAD(iort_fwnode_list); static DEFINE_SPINLOCK(iort_fwnode_lock); +struct iort_rmr_id { + u32 sid; + struct acpi_iort_node *smmu; +}; + +/* + * One entry for IORT RMR. + */ +struct iort_rmr_entry { + struct list_head list; + + unsigned int rmr_ids_num; + struct iort_rmr_id *rmr_ids; + + struct acpi_iort_rmr_desc *rmr_desc; +}; + +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 +412,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; } @@ -1647,6 +1667,103 @@ static void __init iort_enable_acs(struct acpi_iort_node *iort_node) #else static inline void iort_enable_acs(struct acpi_iort_node *iort_node) { } #endif +static int iort_rmr_desc_valid(struct acpi_iort_rmr_desc *desc) +{ + struct iort_rmr_entry *e; + u64 end, start = desc->base_address, length = desc->length; + + if (!IS_ALIGNED(start, SZ_64K) || !IS_ALIGNED(length, SZ_64K)) + return -EINVAL; + + end = start + length - 1; + + /* Check for address overlap */ + list_for_each_entry(e, &iort_rmr_list, list) { + u64 e_start = e->rmr_desc->base_address; + u64 e_end = e_start + e->rmr_desc->length - 1; + + if (start <= e_end && end >= e_start) + return -EINVAL; + } + + return 0; +} + +static int __init iort_parse_rmr(struct acpi_iort_node *iort_node) +{ + struct iort_rmr_id *rmr_ids, *ids; + struct iort_rmr_entry *e; + struct acpi_iort_rmr *rmr; + struct acpi_iort_rmr_desc *rmr_desc; + u32 map_count = iort_node->mapping_count; + int i, ret = 0, desc_count = 0; + + if (iort_node->type != ACPI_IORT_NODE_RMR) + return 0; + + if (!iort_node->mapping_offset || !map_count) { + pr_err(FW_BUG "Invalid ID mapping, skipping RMR node %p\n", + iort_node); + return -EINVAL; + } + + rmr_ids = kmalloc(sizeof(*rmr_ids) * map_count, GFP_KERNEL); + if (!rmr_ids) + return -ENOMEM; + + /* Retrieve associated smmu and stream id */ + ids = rmr_ids; + for (i = 0; i < map_count; i++, ids++) { + ids->smmu = iort_node_get_id(iort_node, &ids->sid, i); + if (!ids->smmu) { + pr_err(FW_BUG "Invalid SMMU reference, skipping RMR node %p\n", + iort_node); + ret = -EINVAL; + goto out; + } + } + + /* 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); + ret = -EINVAL; + goto out; + } + + rmr_desc = ACPI_ADD_PTR(struct acpi_iort_rmr_desc, iort_node, + rmr->rmr_offset); + + for (i = 0; i < rmr->rmr_count; i++, rmr_desc++) { + ret = iort_rmr_desc_valid(rmr_desc); + if (ret) { + pr_err(FW_BUG "Invalid RMR descriptor[%d] for node %p, skipping...\n", + i, iort_node); + goto out; + } + + e = kmalloc(sizeof(*e), GFP_KERNEL); + if (!e) { + ret = -ENOMEM; + goto out; + } + + e->rmr_ids_num = map_count; + e->rmr_ids = rmr_ids; + e->rmr_desc = rmr_desc; + + list_add_tail(&e->list, &iort_rmr_list); + desc_count++; + } + + return 0; + +out: + if (!desc_count) + kfree(rmr_ids); + return ret; +} static void __init iort_init_platform_devices(void) { @@ -1676,6 +1793,9 @@ static void __init iort_init_platform_devices(void) iort_enable_acs(iort_node); + if (iort_table->revision == 1) + iort_parse_rmr(iort_node); + ops = iort_get_dev_cfg(iort_node); if (ops) { fwnode = acpi_alloc_fwnode_static(); From patchwork Thu Nov 19 12:11:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328402 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361488ils; Thu, 19 Nov 2020 04:13:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0NdHER39om5EGbF2isVqB9LqBMlL9/PlbnBrwzolRNbL2+zYkldYiMZjBHn8l842hn1MC X-Received: by 2002:a05:6402:1019:: with SMTP id c25mr2636705edu.297.1605788032180; Thu, 19 Nov 2020 04:13:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788032; cv=none; d=google.com; s=arc-20160816; b=OTyr7i1gyQBk3P1JZ5CbXNITxitn75l/LD7GvKL+88ZMIdTZPXxaMLnjsQYZToI2zM n1pVB6M15YoT+77GJE5nG4XGMj4q/CQpj5nuK+M8nPwsE7xiFKLuwPJKaCKlh+jOa8as 6oCvfpRlbSleYje/BPW70LkAsqylGZitxKzg5I/DNco0QphdEZgUhdjb2GLR2WWLLzQJ 66xaCkvHvhGcG75vxIw6x2Gs0Pd53v/dj6iZC1ONygiIYfj+WCLFo7ctwz3aCj4zD+1l igLSqf3yEyYhD1PCwA+WYvY3tNyvIzovj8LRfjlvu7uKdlYeavmxxVXmDGreBjWM2y4c 3SRw== 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=eewYhq/zZjuaZlIaDY2gouIWEBzbezEuaMJqHKLi4QA=; b=bryj8r0Xyr6VEp3yrDJPrdzgIJaMv8Ef512vDKYzByGbXBn2DSNt31eZ9LelaiFuZp 10MEc0tOByEG7tm5iwoLUz+DFoH7s+wmmZKd/vpQdpvW0otEzBiI8lWuTxr7tE8/ply1 fXoTY+nCEmzyCKvLlYxVIL4ElZeXYymxjvnXSS/gqgZRB+YqZsmhSyx1PT0uYAfapIKD 5ESMmBlmY7C7vhP5aPmQCb8lLp4pbmRoaCo5ewGOTBWerPO4IZSQrIyri2j80tS8qwFX HPuP1x6FEfARIyk3/MtwCWLiMh5e9v97wRpq4j98qfdFRImZuZKWutcsfEocPG77upAB opcw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.52; Thu, 19 Nov 2020 04:13:52 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbgKSMMt (ORCPT + 5 others); Thu, 19 Nov 2020 07:12:49 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8120 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727058AbgKSMMs (ORCPT ); Thu, 19 Nov 2020 07:12:48 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcJTP2bGyzLr01; Thu, 19 Nov 2020 20:12:25 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:38 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 3/8] iommu/dma: Introduce generic helper to retrieve RMR info Date: Thu, 19 Nov 2020 12:11:45 +0000 Message-ID: <20201119121150.3316-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Reserved Memory Regions(RMR) associated with an IOMMU may be described either through ACPI tables or DT in systems with devices that require a unity mapping or bypass for those regions in IOMMU drivers. 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 | 36 ++++++++++++++++++++++++++++++++++++ include/linux/dma-iommu.h | 7 +++++++ include/linux/iommu.h | 16 ++++++++++++++++ 3 files changed, 59 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 0cbcd3fc3e7e..d73768ecdd1a 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -166,6 +166,42 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) } EXPORT_SYMBOL(iommu_dma_get_resv_regions); +/** + * iommu_dma_get_rmrs - Retrieve Reserved Memory Regions(RMRs) associated + * with a given IOMMU + * @iommu_fwnode: fwnode associated with IOMMU + * @list: RMR list to be populated + * + */ +int iommu_dma_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list) +{ + return 0; +} +EXPORT_SYMBOL(iommu_dma_get_rmrs); + +struct iommu_rmr *iommu_dma_alloc_rmr(u64 base, u64 length, + u32 *ids, int num_ids) +{ + struct iommu_rmr *rmr; + int i; + + rmr = kzalloc(struct_size(rmr, ids, num_ids), GFP_KERNEL); + if (!rmr) + return NULL; + + INIT_LIST_HEAD(&rmr->list); + rmr->base_address = base; + rmr->length = length; + rmr->num_ids = num_ids; + + for (i = 0; i < num_ids; i++) + rmr->ids[i] = ids[i]; + + return rmr; +} +EXPORT_SYMBOL(iommu_dma_alloc_rmr); + static int cookie_init_hw_msi_region(struct iommu_dma_cookie *cookie, phys_addr_t start, phys_addr_t end) { diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 2112f21f73d8..8900ccbc9e6a 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -37,6 +37,9 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc, void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); +int iommu_dma_get_rmrs(struct fwnode_handle *iommu, struct list_head *list); +struct iommu_rmr *iommu_dma_alloc_rmr(u64 base, u64 length, + u32 *ids, int num_ids); #else /* CONFIG_IOMMU_DMA */ struct iommu_domain; @@ -78,5 +81,9 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { } +int iommu_dma_get_rmrs(struct fwnode_handle *iommu, struct list_head *list); +{ + return 0; +} #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index b95a6f8db6ff..e43c4e8084e7 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -592,6 +592,22 @@ struct iommu_sva { struct device *dev; }; +/** + * struct iommu_rmr - Reserved Memory Region details per IOMMU + * @list: Linked list pointers to hold RMR region info + * @base_address: base address of Reserved Memory Region + * @length: length of memory region + * @num_ids: number of associated device IDs + * @ids: associated device IDs + */ +struct iommu_rmr { + struct list_head list; + phys_addr_t base_address; + u64 length; + unsigned int num_ids; + u32 ids[]; +}; + int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, const struct iommu_ops *ops); void iommu_fwspec_free(struct device *dev); From patchwork Thu Nov 19 12:11:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328403 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361498ils; Thu, 19 Nov 2020 04:13:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIS/Mb6hrNXob3/D/YlKlMtFoVK6uXXffgeOFFc5yI51XYqE0I11wS5+G1C7+aIl9UsviP X-Received: by 2002:aa7:c30e:: with SMTP id l14mr30658108edq.315.1605788032643; Thu, 19 Nov 2020 04:13:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788032; cv=none; d=google.com; s=arc-20160816; b=n+3Ygg4PIgB+81Mo+hSV/2ngjuNHsTvxOTWO5avXwmEK5ELFR5hQoGkajI1kFViI/W APlz5TviPLqEKqbQpF2Jj4ZADtm54shIBMqK7agWSFnyThy49W5m0KuPIVLd88pBwEPt 4O7PsQsUR3Iv9Q8m8q/Ik5QGRBvqPaB3zfCj/RifbKJ5pglskdaHDROKrkIjBKF1+Luj 8/pd2CKojDC70kGvf+9NLyEsDR7l32anu0GPtRSvWQBX+w14f/W0hXd0ebRLRood7z80 0ijjY3+hkoGC21BURyoK46EraA/apvD3WSVNpw8rrqZl5W+d7evB4r9Tb62rTOycRnF7 pQwA== 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=1RXyRJfu+HXCuhsiLAGwbZaeku3TAjDSAZTBtfIPhU4=; b=HxtDlFb0RGDNwfReqdggGmSHzOCMqkC4peQQJZh57k9++dq6CfFGRUcOT/Kjxi6MSx E5MOizhbaJNznplqTMR6BXCGI8iHtuo3NQQqtHS3R89/ThAZT9iyYbmxOFncB98AlYb+ 3l3XCoZ+nxGD9+r5CdFGahrIpvWsjsHE4dbvJH9whIq0Sudgg1YoThKTBhesRwJEzOpJ 9hVbfGpC24t+Z0Gq4/k4vWcUYltENNsWFqutwSw7yhWhukKOk5lnhCX4jBXmXxipxzSv tP6LQjUNxZNMsvYzZbQCAKWA9XHwqQySVhhW7T/aqHRUb3y8HpBwwnFDR+prmmHjbG/C 3S9g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.52; Thu, 19 Nov 2020 04:13:52 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727114AbgKSMMx (ORCPT + 5 others); Thu, 19 Nov 2020 07:12:53 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:7564 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727058AbgKSMMx (ORCPT ); Thu, 19 Nov 2020 07:12:53 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcJTb4ZwHzhd1R; Thu, 19 Nov 2020 20:12:35 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:44 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 4/8] ACPI/IORT: Add RMR memory regions reservation helper Date: Thu, 19 Nov 2020 12:11:46 +0000 Message-ID: <20201119121150.3316-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add a helper function that retrieves RMR memory descriptors associated with a given IOMMU. This will be used by IOMMU drivers to setup necessary mappings. Now that we have this, invoke this from the generic helper interface. Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 60 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/dma-iommu.c | 3 ++ include/linux/acpi_iort.h | 6 ++++ 3 files changed, 69 insertions(+) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index a9705aa35028..d1a2b09230ab 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -842,6 +843,63 @@ static inline int iort_add_device_replay(struct device *dev) return err; } +/** + * iort_iommu_get_rmrs - Helper to retrieve RMR info associated with IOMMU + * @iommu: fwnode for the IOMMU + * @head: RMR list head to be populated + * + * Returns: 0 on success, <0 failure + */ +int iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *head) +{ + struct iort_rmr_entry *e; + struct acpi_iort_node *iommu; + + iommu = iort_get_iort_node(iommu_fwnode); + if (!iommu) + return 0; + + list_for_each_entry(e, &iort_rmr_list, list) { + struct iort_rmr_id *rmr_ids = e->rmr_ids; + struct acpi_iort_rmr_desc *rmr_desc; + struct iommu_rmr *rmr; + u32 *ids, num_ids = 0; + int i, j = 0; + + for (i = 0; i < e->rmr_ids_num; i++) { + if (rmr_ids[i].smmu == iommu) + num_ids++; + } + + if (!num_ids) + continue; + + ids = kmalloc_array(num_ids, sizeof(*ids), GFP_KERNEL); + if (!ids) + return -ENOMEM; + + for (i = 0; i < e->rmr_ids_num; i++) { + if (rmr_ids[i].smmu == iommu) + ids[j++] = rmr_ids[i].sid; + } + + rmr_desc = e->rmr_desc; + rmr = iommu_dma_alloc_rmr(rmr_desc->base_address, + rmr_desc->length, + ids, num_ids); + if (!rmr) { + kfree(ids); + return -ENOMEM; + } + + list_add_tail(&rmr->list, head); + kfree(ids); + } + + return 0; +} + /** * iort_iommu_msi_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() @@ -1112,6 +1170,8 @@ int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) const struct iommu_ops *iort_iommu_configure_id(struct device *dev, const u32 *input_id) { return NULL; } +int iort_iommu_get_rmrs(struct fwnode_handle *fwnode, struct list_head *head) +{ return 0; } #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 d73768ecdd1a..aa8304e50786 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -176,6 +176,9 @@ EXPORT_SYMBOL(iommu_dma_get_resv_regions); int iommu_dma_get_rmrs(struct fwnode_handle *iommu_fwnode, struct list_head *list) { + if (!is_of_node(iommu_fwnode)) + return iort_iommu_get_rmrs(iommu_fwnode, list); + return 0; } EXPORT_SYMBOL(iommu_dma_get_rmrs); diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index 20a32120bb88..0b61b98a4941 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -38,6 +38,8 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *size); const struct iommu_ops *iort_iommu_configure_id(struct device *dev, const u32 *id_in); int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head); +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) @@ -55,6 +57,10 @@ static inline const struct iommu_ops *iort_iommu_configure_id( static inline int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) { return 0; } +static inline +int iort_iommu_get_rmrs(struct fwnode_handle *iommu_fwnode, + struct list_head *list) +{ return 0; } #endif #endif /* __ACPI_IORT_H__ */ From patchwork Thu Nov 19 12:11:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328404 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361507ils; Thu, 19 Nov 2020 04:13:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbMWOPoTw59lCyb6WR+QS2GRiOgWmAz2Q+KuFPyeOe/QEyVP6oCpulGxHxCmJoOreg6e4c X-Received: by 2002:a50:e087:: with SMTP id f7mr18510353edl.29.1605788033061; Thu, 19 Nov 2020 04:13:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788033; cv=none; d=google.com; s=arc-20160816; b=k7pFqDKIpQxTFxJ5J24olfF7Kz4zD7hA8QptoIvd99iLVCoSs4D/O7DxM8UFSRGB2Z JrHPI4RKnF31gCvDgiO5IGTEaTc2bqpALkb5cirsef7N0qr31+HBaiwuHZbrILqNO/yt 8RhqP5KKWGvyQfCZwB12PKQ1/83iU0fVvrLjgBQq3yc+aDV/M5Q2c6CUyyrGvxlbWv22 fmLS/YK/Zh/1Q4ZUeyoWkxfF8zRcRQiWFZibdEMJqcbBqmBNvshtXmcLrtn/PpqBQ2Ki XSxz/LdFr6FetpKTuViJSiePDzGDoR6fKQjG8UWwmTO0eDkF+fgGkHWXPre9wLqBhsT2 4M1w== 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=zl/vCtXOkCvt9VfU0xd8fDTnwPyF4m65kHlVlA/lnyA=; b=Q9CHwGaDYSqqMG0eRpBE8TD4kUUQcdxXEj3wvmGTAtWa6Ug0Vc2d8SxvL7egdPT3c2 oECC5kJLBb5irp+tkNK9a7FTJWDpvD5iFlV8EJpw2GuNAGTyCz03iHL27nwoLBEgjQlT RRgznVH0ys6qIq5L5IPbhJKwX/s1bN4zV7ii0GEGFgS7FIgA1Bkbsp7eAS1X9h3R09Lt /Zvk8z+wXIdspAi3GsfJlRGPVcLDTlg54YiCaf/FwbFhz2+sDDdQs033tsBFo/j7AQTM Mv2LlxV9wf1OKCfQLIB9F/5XitRa30Ew6hEWmt/auzP6+g63u5BKtjHiOXzJOfGVMBOr KKAg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.52; Thu, 19 Nov 2020 04:13:53 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727254AbgKSMM6 (ORCPT + 5 others); Thu, 19 Nov 2020 07:12:58 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8372 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727058AbgKSMM6 (ORCPT ); Thu, 19 Nov 2020 07:12:58 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CcJTj099Vz709F; Thu, 19 Nov 2020 20:12:41 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:49 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 5/8] iommu/arm-smmu-v3: Introduce strtab init helper Date: Thu, 19 Nov 2020 12:11:47 +0000 Message-ID: <20201119121150.3316-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] 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 for RMR SIDs. Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 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 e634bbe60573..1953b317d814 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2308,6 +2308,19 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) static struct iommu_ops arm_smmu_ops; +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 struct iommu_device *arm_smmu_probe_device(struct device *dev) { int i, ret; @@ -2336,21 +2349,12 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) INIT_LIST_HEAD(&master->bonds); dev_iommu_priv_set(dev, master); - /* Check the SIDs are in range of the SMMU and our stream table */ for (i = 0; i < master->num_sids; i++) { u32 sid = master->sids[i]; - if (!arm_smmu_sid_in_range(smmu, sid)) { - ret = -ERANGE; + ret = arm_smmu_init_sid_strtab(smmu, sid); + if (ret) goto err_free_master; - } - - /* Ensure l2 strtab is initialised */ - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { - ret = arm_smmu_init_l2_strtab(smmu, sid); - if (ret) - goto err_free_master; - } } master->ssid_bits = min(smmu->ssid_bits, fwspec->num_pasid_bits); From patchwork Thu Nov 19 12:11:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328406 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361532ils; Thu, 19 Nov 2020 04:13:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIQxjwkpjkMS6Dmpe1CcVJ7lo/tLbhxr2MyZwGCmnYFXuzgtDLPQCeSsLOQPLfqZmZL4I3 X-Received: by 2002:a17:906:cd0f:: with SMTP id oz15mr28611219ejb.200.1605788034450; Thu, 19 Nov 2020 04:13:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788034; cv=none; d=google.com; s=arc-20160816; b=ULFgffZ4ibZF8mLb8XUqFr/PXUD8lzaurzk9fjCt9Kl/8HepYiBmBzptBQ46VVFQP7 n/HORFOGvTvymVRNU1bWxiQCc4GURdNJSfFIZCVBJ6Chm4lRPtl7sWs6/1Z1apff1Pxw tkxPd3qeTu2wsbFhECN1xOauRl0Kebln7vdq1tIoEeVpcRw4vo4Q7ujuRUu2gh89ehxU bZFQXZDbX3nkcNM+T5B9zeTC2hxdA4HF1h0H/FoXSsP8CbqtUfH84MQUceb11OsBwHdL 1BFjRpHfYi0dpubcP4CsZPdI29RFlRE7vRGhGXCnk+t0+0XFP0fvjZwaNK8Om2vQzZ4O QttA== 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=MtsW3hwrSeBC+zOFPeyA8GURRuY80bNDOvM6SFgSL0g=; b=IuE+yLfr1jhGfaJfjhj77QlpaC1Z2NaLMDWE/53THDkrF+wChJINIWG++fGkOLVfxg BtVL1PgGSipSA7RNHKsaIsMHuLZGwc64W36X20hwF3KYXPbj1GrGZZRpWXklLwfsTjgC Aqv8Y19PwLCJiA9CEzVmhlc8px1+pqidRb31x8eq+1Ep1lc/hDCeJC8uPgCrGSs407nk AjEo5IqwGBVnBIi9q9qCH23Y5yzv7WKCd1+9zJsuw2YCtOBw1VW6WR9XsJs0lHEtOFvA jwln0ChvQhVOc0Vryb7SGzN2K7v5k0uppQ6JYQUUKeDDJtcbQNIXQQd3P6Nzo73Y7Ylk vw8g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.54; Thu, 19 Nov 2020 04:13:54 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727268AbgKSMNI (ORCPT + 5 others); Thu, 19 Nov 2020 07:13:08 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:7954 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgKSMNH (ORCPT ); Thu, 19 Nov 2020 07:13:07 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CcJTz013FzhdPH; Thu, 19 Nov 2020 20:12:55 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:56 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 6/8] =?utf-8?q?iommu/arm-smmu-v3=3A_Add_bypass_flag?= =?utf-8?b?IHRvwqBhcm1fc21tdV93cml0ZV9zdHJ0YWJfZW50KCk=?= Date: Thu, 19 Nov 2020 12:11:48 +0000 Message-ID: <20201119121150.3316-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org By default, disable_bypass is set and any dev without an iommu domain installs STE with CFG_ABORT during arm_smmu_init_bypass_stes(). Introduce a "bypass" flag to arm_smmu_write_strtab_ent() so that we can force it to install CFG_BYPASS STE for specific SIDs. This will be useful for RMR related SIDs. Signed-off-by: Shameer Kolothum --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 1953b317d814..5f366d5a9ebf 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1174,7 +1174,7 @@ static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid) } static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, - __le64 *dst) + __le64 *dst, bool bypass) { /* * This is hideously complicated, but we only really care about @@ -1245,7 +1245,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, /* Bypass/fault */ if (!smmu_domain || !(s1_cfg || s2_cfg)) { - if (!smmu_domain && disable_bypass) + if (!smmu_domain && disable_bypass && !bypass) val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); else val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); @@ -1317,7 +1317,7 @@ static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent) unsigned int i; for (i = 0; i < nent; ++i) { - arm_smmu_write_strtab_ent(NULL, -1, strtab); + arm_smmu_write_strtab_ent(NULL, -1, strtab, false); strtab += STRTAB_STE_DWORDS; } } @@ -2038,7 +2038,7 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) if (j < i) continue; - arm_smmu_write_strtab_ent(master, sid, step); + arm_smmu_write_strtab_ent(master, sid, step, false); } } From patchwork Thu Nov 19 12:11:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328407 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361548ils; Thu, 19 Nov 2020 04:13:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+/ztJ8lLepslsWbkIb3ZMXQ0RaU25ZBM2TanBnVQ1NmIQ+5cAT+GVJIj+E1OCRtM60KR+ X-Received: by 2002:a50:e087:: with SMTP id f7mr18510493edl.29.1605788035260; Thu, 19 Nov 2020 04:13:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788035; cv=none; d=google.com; s=arc-20160816; b=JjI7Eldekrv9qGLGnKzpQSyeiLi5ocLnfIEtquDYfr73ANtpPLzHgzSBZqjDpg1IKQ vdUA/ixbqCXRZBWTPRPdmuumlAdQ2R/0fwIlYe41e4aIjmhcuuMrBV3anCFUKXoRL61S 7q8noOjPcC3LmbhxbyU6+no+LQX+HIRwPLOvndyLppzeUxXQidGilC+LrjU6rXkiGSSi gFeP4EGexcHUJYxR/ce3yyQvWxnHs03sNYge12oxD8R6l6VLzCMaWiqXxxSFnkJifW2x CwxXT3cEuQ89ZYQVz6KVDcuY0ueENSmREnAJrPZVmrUV+LjMB8H7yn/363Kq2KJInBQq Bv3g== 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=fx+YdgHdGfXz3R2yYdhVUlHrZME/JEaeL0kHjwNjbvs=; b=R40Qiauzx6DIMiJD/464irLSwMBVoStDDR8sMozY6fq5l7tPCu05c1xBGe0MkkYWnm owgL+IzDq8z7UkqnxOk15qjRWB8dFofKfzocae4laJ3rqaU+SUbsbjw6aRjrz9DyfY7h KaRHegN08MBg/HOIBEIgn6E1ycaEP9ChNhvOP3zU0Nfwg0Rbkn61bY5GDmzK5yVcbChO 5vn9p1jG/w4Rav+D68r2e8X8DXi0r4LHlSykm6pE70OUb6FBHdJP5T5cpNhCQOI3QkhU 6vFfXgG3auuIbUK4QlG7N+M7oOdVeUujln5I19TCJDCnvxFIsIFSccphUPI+S5YTpVSZ vYPQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.55; Thu, 19 Nov 2020 04:13:55 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727270AbgKSMNN (ORCPT + 5 others); Thu, 19 Nov 2020 07:13:13 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:7565 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgKSMNM (ORCPT ); Thu, 19 Nov 2020 07:13:12 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcJV00Bwhzhd20; Thu, 19 Nov 2020 20:12:56 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:13:02 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 7/8] iommu/arm-smmu-v3: Get associated RMR info and install bypass STE Date: Thu, 19 Nov 2020 12:11:49 +0000 Message-ID: <20201119121150.3316-8-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] 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 | 40 +++++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ 2 files changed, 42 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 5f366d5a9ebf..97df1df001c9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3486,6 +3486,42 @@ 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 iommu_rmr *e; + int i, ret; + + /* + * Since, we don't have a mechanism to differentiate the RMR + * SIDs that has an ongoing live stream, install bypass STEs + * for all the reported ones.  + * FixMe: Avoid duplicate SIDs in the list as one sid may + * associate with multiple RMRs. + */ + list_for_each_entry(e, &smmu->rmr_list, list) { + for (i = 0; i < e->num_ids; i++) { + __le64 *step; + u32 sid = e->ids[i]; + + ret = arm_smmu_init_sid_strtab(smmu, sid); + if (ret) { + dev_err(smmu->dev, "RMR bypass(0x%x) failed\n", + sid); + continue; + } + + step = arm_smmu_get_step_for_sid(smmu, sid); + arm_smmu_write_strtab_ent(NULL, sid, step, true); + } + } +} + +static int arm_smmu_get_rmr(struct arm_smmu_device *smmu) +{ + INIT_LIST_HEAD(&smmu->rmr_list); + return iommu_dma_get_rmrs(dev_fwnode(smmu->dev), &smmu->rmr_list); +} + static int arm_smmu_device_probe(struct platform_device *pdev) { int irq, ret; @@ -3569,6 +3605,10 @@ 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 */ + if (!arm_smmu_get_rmr(smmu)) + arm_smmu_rmr_install_bypass_ste(smmu); + /* Reset the device */ ret = arm_smmu_device_reset(smmu, bypass); if (ret) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index d4b7f40ccb02..17b517ddecee 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -636,6 +636,8 @@ struct arm_smmu_device { /* IOMMU core code handle */ struct iommu_device iommu; + + struct list_head rmr_list; }; /* SMMU private data for each master */ From patchwork Thu Nov 19 12:11:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 328405 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361579ils; Thu, 19 Nov 2020 04:13:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKeFN7ojkrsbc5gpIGSqpDb1VjDwJ1jpgYDs85m1CWXHRMFd69HD3tKKzyVM/If6EDxW7W X-Received: by 2002:aa7:d443:: with SMTP id q3mr32093942edr.262.1605788037428; Thu, 19 Nov 2020 04:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788037; cv=none; d=google.com; s=arc-20160816; b=fHmYXgNF0dOfWcHC3APktHc12n0goMOb1DR0M5ANAy10JiUDd5+w5+Ac6RSumvEp6R m+AEHMTH5zcwBrsESX3phT7WrwF05ruIPZDSSH5NFM12yS0OJJKxpuej60t2tCTkSjKO ZvuZxSMaT7qEYP3WNt9sA0xlX1qVcCsCQ/aneME4fW5L1tlIKsHbwUh+/boA/ZdNJx5p 0qKEzg7vFAeWXFsCbnFUCw+6fd5WQtL15zYtbheLYG5d0YtrPgC6RpY0a/UsHjcbIQOk +3+kGEYK2Wrzg19RaqMr1JoTci10DY0E5QoFbnZDhWPuC5gNUatmLcYMy+C2+bwUrzlJ 4+IQ== 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=lGwC+kYTAIamTf87KCNQHqRe7Pcpk6ns/QMMUYyKs30=; b=1JsRkUh6vZLUJtzWOJ4vJ2HBwXbFFKQmlI9HLFtUuel7a9l8rTM2tx5T8tdyQ8/LTU x1IE9IO4bAzGn69OzTKlxFnNCny4P0kdsg48YMfgkboS6TmREb9q9iWqa+KkJ/xzBDg7 UhHdjds9Ahjk7YZRiF/dqYbWNmhjV7GOGHIN75HU14iJylzakXrRgTBERAc3ob1C9FNf H8nEI6K6g4rOji3cEADplZ8R5225kEqdy20FVaRThVtMc63JYOBlflVMpRoqYIiYoduy aoAMea51+tR4tx1xpq7wRQPAiV/fksr/qkwTHhHGwUVEmDwmQS+KAz6wc8VFMfeDnusG GXLw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.57; Thu, 19 Nov 2020 04:13:57 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727304AbgKSMNV (ORCPT + 5 others); Thu, 19 Nov 2020 07:13:21 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8373 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727269AbgKSMNV (ORCPT ); Thu, 19 Nov 2020 07:13:21 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CcJV528Nrz70BV; Thu, 19 Nov 2020 20:13:01 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:13:09 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 8/8] =?utf-8?q?iommu/arm-smmu-v3=3A_Reserve_any_RMR?= =?utf-8?q?_regions_associated_with_a=C2=A0dev?= Date: Thu, 19 Nov 2020 12:11:50 +0000 Message-ID: <20201119121150.3316-9-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Get 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/arm/arm-smmu-v3/arm-smmu-v3.c | 38 +++++++++++++++++++++ 1 file changed, 38 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 97df1df001c9..174a9bcfd627 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2492,6 +2492,43 @@ static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args) return iommu_fwspec_add_ids(dev, args->args, 1); } +static bool arm_smmu_dev_has_rmr(struct arm_smmu_master *master, + struct iommu_rmr *e) +{ + int i, j; + + for (i = 0; i < master->num_sids; i++) { + for (j = 0; j < e->num_ids; j++) { + if (e->ids[j] == master->sids[i]) + return true; + } + } + + return false; +} + +static void arm_smmu_rmr_get_resv_regions(struct device *dev, + struct list_head *head) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu = master->smmu; + struct iommu_rmr *rmr; + + list_for_each_entry(rmr, &smmu->rmr_list, list) { + struct iommu_resv_region *region; + int prot = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; + + if (!arm_smmu_dev_has_rmr(master, rmr)) + continue; + region = iommu_alloc_resv_region(rmr->base_address, + rmr->length, prot, + IOMMU_RESV_DIRECT); + if (!region) + return; + + list_add_tail(®ion->list, head); + } +} static void arm_smmu_get_resv_regions(struct device *dev, struct list_head *head) { @@ -2506,6 +2543,7 @@ static void arm_smmu_get_resv_regions(struct device *dev, list_add_tail(®ion->list, head); iommu_dma_get_resv_regions(dev, head); + arm_smmu_rmr_get_resv_regions(dev, head); } static bool arm_smmu_dev_has_feature(struct device *dev,